Help with fractal-program!

Hi!

This is my first topic on this forum.

I'm trying to write a algorithm that shall generate a fractal that is called cantor sets (cantormängd on swedish ;)).

http://en.wikipedia.org/wiki/Cantor_set

To do this I have a function drawLine(p1,p2); that draws a line between two points.

I've really tried to comment the program, but the xStart and xStop variables are really hard to desribe without a paper and pen. Hope you get how I'm thinking.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  #include "algorithm.h"
#include <math.h>

int xStart;				// the variable that represent the starting x-position
int xStop;				// the variable that represents the finishing x-position
float xLength = 900;	// the length of the "mother-line"
int a = 6;				// the "input-variale" that tells the program how many rows shall be built
int yPos;				// the y variable, that is a multiplier of the "mother-loop-variable"
int denominator;		// the denominator that will be used to divide the x-coordinate in the inner-loop

void algorithm()
{
	
	

	for (int y = 1; y <= a ; y++)
		{
			denominator = pow((float)(3),(y-1));							//for y = 1, denominator is 1, next time 3, 9, 27...

			for (int i = 0; i < 2 * (pow ((double)(2),(y - 1))) ; i++)		// i mindre än antal punkter på linjen
				{
					if (i == 0)
					{
						xStart = 0; 
						xStop = xLength/denominator;
						yPos = y * 10;										//this is just to make the y-distance 10 times bigger 
					
						point p1 = {xStart,yPos};							//the yPos is constant in both points
						point p2 = {xStop,yPos};
					
						drawLine(p1,p2);									//Draws a line between p1 and p2
					}
					
					else
					{
						xStart = i / denominator;							
						xStop = xStart + (xLength / denominator);
						yPos = y * 10;										 
					
						point p1 = {xStart,yPos};							
						point p2 = {xStop,yPos};
					
						drawLine(p1,p2);									
					}
					
			 
				}
			

			 
		}

	
}


When I run the program it looks like this.

int xLength = 27;
int a = 4;
________________________
________
___
_

Any Ideas how i should move forward? I am really stuck...

Feel free to ask if I'm unclear somewhere, Thanks!
Forgot to say that I'm 100% sure that drawLine(p1,p2); is NOT the problem!
Topic archived. No new replies allowed.