We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I want to do a simple animation - cracks/frosts on mousePressed(), then the cracks increase in size and spread all over the screen, //to be done with line/ellipse cracks to look like this:
class Crack { float a, b, c, d; Crack(float ia, float ib, float ic, float id) { a=ia; b=ib; c=ic; d=id; } void draw() { line(a, b, c, d); } } ArrayList<Crack> cracks = new ArrayList(); void setup() { size(600, 600); } void draw() { background(0); noFill(); stroke(255); strokeWeight(2); rect(10, 10, 580, 580); for (Crack crack : cracks) crack.draw(); } void mousePressed() { for (int i = 0; i < 4; i++) { float r = random(TWO_PI); float d = random(20, 500); cracks.add( new Crack(mouseX, mouseY, mouseX+d*cos(r), mouseY+d*sin(r))); } }
I had to write this code from scratch because YOU POSTED NO CODE.
I am unable to help you more because YOU HAVEN'T TOLD US WHAT YOU ARE HAVING TROUBLE WITH.
New to the community; apologies.
Have achieved this much with a simpler code:
if (mousePressed){ line(mouseX, mouseY, random(100,300), random(300,500)); }
Want to increase the size of each line that is drawn.
What do you mean by a line's "size"? Its thickness? Its length?
class Crack { float a, b, c, d; Crack(float ia, float ib, float ic, float id) { a=ia; b=ib; c=ic; d=id; } void draw() { line(a, b, c, d); } } int sw = 1; ArrayList<Crack> cracks = new ArrayList(); void setup() { size(600, 600); } void draw() { background(0); noFill(); stroke(255); strokeWeight(2); rect(10, 10, 580, 580); strokeWeight(sw); for (Crack crack : cracks) crack.draw(); } void mousePressed() { for (int i = 0; i < 4; i++) { float r = random(TWO_PI); float d = random(20, 500); cracks.add( new Crack(mouseX, mouseY, mouseX+d*cos(r), mouseY+d*sin(r))); } sw++; }
Length.
Have achieved this much with a simpler code: Want to increase the size of each line that is drawn.
then you haven't achieved this with that code
if you use random the way you have then every frame will draw a different line. it won't grow, it'll just be random.
you have to generate some random lines in setup, and draw a bit more of them in every draw loop.
class Crack { float x, y, r, d; Crack(float ix, float iy, float ir, float id) { x=ix; y=iy; r=ir; d=id; } void draw() { line(x, y, x+d*cos(r), y+d*sin(r)); } void longer() { d+=random(2, 5); } } ArrayList<Crack> cracks = new ArrayList(); void setup() { size(600, 600); } void draw() { background(0); noFill(); stroke(255); strokeWeight(2); rect(10, 10, 580, 580); for (Crack crack : cracks) crack.draw(); } void mousePressed() { for (Crack crack : cracks) { crack.longer(); } for (int i = 0; i < 4; i++) { cracks.add(new Crack(mouseX, mouseY, random(TWO_PI), 5)); } }
Thank you so much!
here you can just hold the mouse in one place, mouse button down to let it grow automatically
or release button and press anew
or drag....
and you learned nothing from it but just got code from us.
Chrisir
boolean hold=false; ArrayList<Crack> cracks = new ArrayList(); int currentCracks=0; // how many of the last added cracks are growing void setup() { //size(1200, 800); fullScreen(); background(0); } void draw() { // background(0); // frame noFill(); stroke(255); strokeWeight(2); rect(10, 10, width-20, height-20); for (Crack crack : cracks) { crack.draw(); } if (hold) growLast(); } // ---------------------------------------------------------------------- void mousePressed() { hold=true; init(mouseX, mouseY); currentCracks=0; // reset } void mouseDragged() { if (hold) { init(mouseX, mouseY); println("here"); } } void mouseReleased() { hold=false; currentCracks=0; // reset } // ---------------------------------------------------------------------- void keyPressed() { background(0); cracks.clear(); } // ---------------------------------------------------------------------- void init(float x, float y) { // currentCracks+=4; currentCracks=6; for (int i = 0; i < 4; i++) { cracks.add(new Crack(x, y, random(TWO_PI), random(3, 5))); }//for } void growLast() { //for (Crack crack : cracks) { // crack.longer(); //} //Crack crack = cracks.get(cracks.size()-1); //crack.longer(); for (int i = cracks.size()-1; i > max(0, cracks.size() - currentCracks); i--) { /// cracks.add(new Crack(mouseX, mouseY, random(TWO_PI), 5)); Crack crack = cracks.get(i); crack.longer(); } } // ===================================================== class Crack { float x, y, angle, radius; color col; Crack(float ix, float iy, float i_angle, float i_radius) { x=ix; y=iy; angle = i_angle; radius = i_radius; if (random(100)>50) col=color(random(210, 256), random(55, 99)); // white-ish else col=color(random(22), random(33), random(210, 256), random(66, 99)); // blue-ish } void draw() { stroke(col); line(x, y, x+ radius*cos(angle), y+ radius*sin(angle)); } void longer() { radius+=random(2, 6); if (random(100)>90) init( x+ radius*cos(angle), y+ radius*sin(angle) ); } } //
Answers
I had to write this code from scratch because YOU POSTED NO CODE.
I am unable to help you more because YOU HAVEN'T TOLD US WHAT YOU ARE HAVING TROUBLE WITH.
New to the community; apologies.
Have achieved this much with a simpler code:
Want to increase the size of each line that is drawn.
What do you mean by a line's "size"? Its thickness? Its length?
Length.
then you haven't achieved this with that code
if you use random the way you have then every frame will draw a different line. it won't grow, it'll just be random.
you have to generate some random lines in setup, and draw a bit more of them in every draw loop.
Thank you so much!
here you can just hold the mouse in one place, mouse button down to let it grow automatically
or release button and press anew
or drag....
and you learned nothing from it but just got code from us.
Chrisir