Barsnley fern
in
Programming Questions
•
1 year ago
Hi, Im trying to make a fractal drawing following this page instructions:
And it seems OK but I have some problems:
1. It seems too few points, but if I try to add more, there is a message that there are too much recursion.
2. Translate and rotate sentences doesnt seems to work with set.
3. random are not really random numbers. How can I have real random numbers?
This is the code:
void setup(){
background (255);
size(width, length, P3D);
}
background (255);
size(width, length, P3D);
}
int width = 800;
int length = 800;
float x = 0;
float y = 0;
color col = color (255, 0,0);
int iterations = 0;
int maxiterations =3000;
int length = 800;
float x = 0;
float y = 0;
color col = color (255, 0,0);
int iterations = 0;
int maxiterations =3000;
void draw(){
translate (2*width,length/2);
rotate (PI);
transform(x,y);
translate (2*width,length/2);
rotate (PI);
transform(x,y);
noLoop();
}
}
void transform(float x,float y){
float chance;
float a=0,b=0,c=0,d=0,e=0,f=0;
iterations++;
if (iterations < maxiterations){
set(int(50*x)+200, int(50*y), col);
//println(str(x)+" "+str(y));
chance = random(0,1);
if (chance <= 0.01){
a = 0;
b = 0;
c = 0;
d = 0.6;
e = 0;
f = 0;
}
if ((chance > 0.01)&& (chance<=0.86)){
a = 0.85;
b = 0.04;
c = -0.04;
d = 0.85;
e = 0;
f = 1.6;
}
if ((chance > 0.86)&& (chance<=0.93)){
a = 0.2;
b = -0.26;
c = 0.23;
d = 0.22;
e = 0;
f = 1.6;
}
if ((chance > 0.93)&& (chance<=1)){
a = -0.15;
b = 0.28;
c = 0.26;
d = 0.24;
e = 0;
f = 0.44;
}
x = a*x + b * y + e;
y = c*x + d * y + f;
transform(x,y);
}
}
1