Hi! I am doing a customizable fractal tree program. I have some issues; Why does this happen?
why this (“kinda”) works:
ArrayList<Float> x = new ArrayList<Float>();
ArrayList<Float> y = new ArrayList<Float>();
ArrayList<Float> a = new ArrayList<Float>();
ArrayList<Float> nx = new ArrayList<Float>();
ArrayList<Float> ny = new ArrayList<Float>();
ArrayList<Float> na = new ArrayList<Float>();
int n = 3, it = 0, mit = 5;
float spin = PI/6, br = -PI/2, bl = 100, bm = 0.9;
float spn[] = new float[n];
void setup() {
size(600,600);
for(int i = 0; i < n; i++) {
spn[i] = map(i,0,n-1,-spin/2,spin/2);
}
newBranch(300,500,br);
}
void draw() {
//x = nx;
//y = ny;
//a = na;
//nx.clear();
//ny.clear();
//na.clear();
background(0);
for(int i = 0; i < pow(n,it); i++) {
branch(x.get(i),y.get(i),a.get(i), bl * pow(bm,1));
}
println(frameCount);
delay(1000);
it++;
}
void branch(float x_, float y_, float r_, float l_) {
stroke(255);
for(int i = 0; i < n; i++) {
line(x_,y_, x_ + l_ * cos(r_ + spn[i]), y_ + l_ * sin(r_ + spn[i]));
newBranch(x_ + l_ * cos(r_ + spn[i]), y_ + l_ * sin(r_ + spn[i]), r_ + spn[i]);
}
}
void newBranch(float x_, float y_, float r_) {
x.add(x_);
y.add(y_);
a.add(r_);
}
while this doesn’t:
ArrayList<Float> x = new ArrayList<Float>();
ArrayList<Float> y = new ArrayList<Float>();
ArrayList<Float> a = new ArrayList<Float>();
ArrayList<Float> nx = new ArrayList<Float>();
ArrayList<Float> ny = new ArrayList<Float>();
ArrayList<Float> na = new ArrayList<Float>();
int n = 3, it = 0, mit = 5;
float spin = PI/6, br = -PI/2, bl = 100, bm = 0.9;
float spn[] = new float[n];
void setup() {
size(600,600);
for(int i = 0; i < n; i++) {
spn[i] = map(i,0,n-1,-spin/2,spin/2);
}
newBranch(300,500,br);
}
void draw() {
x = nx;
y = ny;
a = na;
nx.clear();
ny.clear();
na.clear();
background(0);
for(int i = 0; i < pow(n,it); i++) {
branch(x.get(i),y.get(i),a.get(i), bl * pow(bm,1));
}
println(frameCount);
delay(1000);
it++;
}
void branch(float x_, float y_, float r_, float l_) {
stroke(255);
for(int i = 0; i < n; i++) {
line(x_,y_, x_ + l_ * cos(r_ + spn[i]), y_ + l_ * sin(r_ + spn[i]));
newBranch(x_ + l_ * cos(r_ + spn[i]), y_ + l_ * sin(r_ + spn[i]), r_ + spn[i]);
}
}
void newBranch(float x_, float y_, float r_) {
nx.add(x_);
ny.add(y_);
na.add(r_);
}