You might be interested in some of the reference Example sketches online: things like clicking to create multiple falling objects, particle systems, etc.
Currently in my setup(), I have set the size, background, stroke and a for loop to get the final state of the object after substituting the rule into the turtle.
for(int k = 0; k < L; k++){
state = substitute(state, ruleF);
}
the final state of the object after substituting the rule into the turtle.
It is not clear what you are asking. Please remember we don't know anything about your code unless you explicitly show it to us so to be able to understand what you are trying to do. This is a good opportunity to check what a MCVE is: https://stackoverflow.com/help/mcve
Currently I have create a snowflakes class file, but unable to make it into an array to redraw it randomly.
tes[] flakes = new tes[100];
void setup() {
size(600, 400);
background(255);
stroke(0);
flakes[i] = new tes();
}
void draw() {
background(255);
//tes flakes = new tes();
y = y + speed;
if (y>height+100) {
y = -10;
L = 3; //Set value of L back to 3 when it redraw.
}
//flakes.animate();
//flakes.display();
for (int i =0; i<100; i++) {
flakes[i].draw();
flakes[i].mouseClicked();
}
}
----------------------------------------------------
tes class file
int SD = 5, sd = SD/2;
float d = sd;
float angle = PI/3;
String state = "[F+F+F+F+F]";
String ruleF = "F-F++F-F";
float L = 3;
float fade = 1;
float speed = random(1, 5);
float x = random(0, 600);
float y = 100;
public class tes {
void draw() {
pushMatrix();
fade++;
stroke(fade, 255);
for (int k = 0; k < L; k++) {
state = substitute(state, ruleF);
}
}
single();
popMatrix();
}
void mouseClicked() {
L=L-1;
}
void single() {
translate(x, y);
for (int i =0; i < state.length(); i++)
turtle(state.charAt(i));
}
}
Currently my number of iteration is set to 3, also know as the value "L". I tried to add on a mouseClicked() function to decrease the number of iteration. However when I clicked on my mouse, the value of L decrease to 2 but it doesn't update the value of L in the display() of the class file. May i know where have i gone wrong?
you haven't moved the variables inside the class as I told you
also better post the entire code a the bottom of the discussion as new post and not edit old posts, because then my remarks about the code don't make sense anymore...
Answers
Make a snowflake class and create an array of snowflake objects. Why not?
Check prev relevant posts: https://forum.processing.org/two/search?Search=raining
Kf
You might be interested in some of the reference Example sketches online: things like clicking to create multiple falling objects, particle systems, etc.
Currently in my setup(), I have set the size, background, stroke and a for loop to get the final state of the object after substituting the rule into the turtle.
for(int k = 0; k < L; k++){ state = substitute(state, ruleF); }
How can I make it into an array?
It is not clear what you are asking. Please remember we don't know anything about your code unless you explicitly show it to us so to be able to understand what you are trying to do. This is a good opportunity to check what a MCVE is: https://stackoverflow.com/help/mcve
Kf
@JamesKoo -- yes, this is unclear. What is
state
? What issubstitute()
? What isruleF
? What is "the turtle"?Share your code here -- you can format it for a forum post following these instructions: https://forum.processing.org/two/discussion/15473/how-to-format-code-and-text
here is a example to place two snowflakes
Currently I have create a snowflakes class file, but unable to make it into an array to redraw it randomly.
How can i change it to an array of snowflakes?
I demonstrated that above with LSystem class
Move this line
before setup
And change it to
Now in setup() use a for loop similar to my setup
Inside the for loop
flakes[i] = new tes(......
in draw also use a for loop and then similar to my draw () above
flakes[i].render();
I have just did some adjustment on my codes on top, is that what you mean?
Does it work?
Does it do what you want?
You are almost there
You need this in setup() too :
for(int i =0; i<100;i++)
Before flakes[....
Do you know why?
;-)
I edited the codes on my phone, have yet to try it out yet. I don't have my computer with my currently.
If not, it will generate only one flakes right?
It will crash
You need to make additional changes too:
Since all the snowflakes should have different positions you need to move x,y inside the class
So each snowflake is individual
In fact move all or as much as you can of the global variables inside the class
Remark
It would be cool to have different types of flakes, maybe you can vary the rule for each but that’s for later
Currently my number of iteration is set to 3, also know as the value "L". I tried to add on a mouseClicked() function to decrease the number of iteration. However when I clicked on my mouse, the value of L decrease to 2 but it doesn't update the value of L in the display() of the class file. May i know where have i gone wrong?
post your entire code to check
Is L a variable inside the class or a global one?
Currently it is global. I update it on 9th post on top.
in setup() use a for loop similar to my setup
Inside the for loop
flakes[i] = new tes(......
in draw also use a for loop and then similar to my draw () above
flakes[i].render();
you haven't moved the variables inside the class as I told you
also better post the entire code a the bottom of the discussion as new post and not edit old posts, because then my remarks about the code don't make sense anymore...
and the whole discussion is just confusing
I got a running version with 100 flakes.
Do you have that too?
(no mouseClicked() function or L change)
I have shift it to a new discussion to avoid further confusion. Sorry about that.
Could you pm me on that? I would like to see the different.
Why did you start a new discussion? Pointless. Even more so since in the new discussion your code is not runnable. Bad.
Question:
I got a running version with 100 flakes.
Do you have that too?
So what do i do currently? Update this post?
100 snowflakes running with the lsystem?
start by answer my question
post your entire sketch here.
a runnable version
when you want to change L what do you want to achieve in the graphic?