Week 4:Dynamic generative patterns
//THE CONSTRUCTION OF THE SNOWFLAKE WAS INSPIRED BY THE PAPER-CUT PATTERN IN A FOLDED SHEET OF PAPER
//THE PRINCIPLE: a triangle with three fixed vertex.
//Between these vertex, insert new vertex per groups of three: two of them are sliping randomly on the borderline
//The third one is framed by the two previous ones moving randomly inside the borders of the rectangle
void setup() {
size(1200,700);
framerate(3);
background(50);
}
void draw() {
//RENEW THE BACKGROUND ANDPREVIOUS SNOWFLAKES DISAPPEAR BY MELTING IN THE BACKGROUND
fill(40,40,40,80);
rect(0,0,1200,700);
translate(random(1500),random(900));
fill(20,230,208,90);
noStroke();
float rayon = random(10,80);//rayon = diameter/2
float x = random(10,50)/2;
float y = random(25,75)/2;
float a = random(rayon)/2;//randomize the end of the branch
while(x>y) {
x = random(rayon/8,5*rayon/8)/2;
y = random(3*rayon/8,7*rayon/8)/2;
}
float y2 = random(rayon/4,rayon/2);
float y3 = random(0,rayon/4);
float y4 = random(3*rayon/4+rayon/8,rayon-rayon/8);
float y5 = random(rayon/2+rayon/8,3*rayon/4-rayon/8);
float x4 = random(rayon/2,3*rayon/4);
float x5 =random (rayon/4,rayon/2);
for(int i=0;i<4;i++) {
rotate(PI/4);//DEFOLD THE PAPER
beginShape();
vertex(0,0);//first fixed point
vertex(rayon-a,rayon-a);//END OF THE BRANCH:detail which makes all the difference ;-)
vertex(rayon-a,rayon+5-a);//END OF THE BRANCH
vertex(rayon-5-a,rayon+5-a);//END OF THE BRANCH
vertex(rayon-20-a,rayon-10-a);//END OF THE BRANCH
vertex(x4,rayon);//first group of three points
vertex(y,rayon/2+x);
vertex(x5,rayon);
vertex(0,rayon);//second fixed point
vertex(0,y4);//second group of three points
vertex(x,rayon/2+y);
vertex(0,y5);
vertex(0,y2);//third group of three points
vertex(x,y);
vertex(0,y3);//third (fixed) point, center of the snowflake
endShape();
//MAKING THE SYMETRICAL TRIANGLE
beginShape();
vertex(0,0);
vertex(-rayon+a,-rayon+a);
vertex(-rayon+a,-rayon+a);
vertex(-rayon+5+a,-rayon-5+a);
vertex(-rayon+20+a,-rayon+10+a);
vertex(-x4,-rayon);
vertex(-y,-(rayon/2+x));
vertex(-x5,-rayon);
vertex(0,-rayon);
vertex(0,-y4);
vertex(-x,-(rayon/2+y));
vertex(0,-y5);
vertex(0,-y2);
vertex(-x,-y);
vertex(0,-y3);
endShape();
}
}
//THE CONSTRUCTION OF THE SNOWFLAKE WAS INSPIRED BY THE PAPER-CUT PATTERN IN A FOLDED SHEET OF PAPER
//THE PRINCIPLE: a triangle with three fixed vertex.
//Between these vertex, insert new vertex per groups of three: two of them are sliping randomly on the borderline
//The third one is framed by the two previous ones moving randomly inside the borders of the rectangle
void setup() {
size(1200,700);
framerate(3);
background(50);
}
void draw() {
//RENEW THE BACKGROUND ANDPREVIOUS SNOWFLAKES DISAPPEAR BY MELTING IN THE BACKGROUND
fill(40,40,40,80);
rect(0,0,1200,700);
translate(random(1500),random(900));
fill(20,230,208,90);
noStroke();
float rayon = random(10,80);//rayon = diameter/2
float x = random(10,50)/2;
float y = random(25,75)/2;
float a = random(rayon)/2;//randomize the end of the branch
while(x>y) {
x = random(rayon/8,5*rayon/8)/2;
y = random(3*rayon/8,7*rayon/8)/2;
}
float y2 = random(rayon/4,rayon/2);
float y3 = random(0,rayon/4);
float y4 = random(3*rayon/4+rayon/8,rayon-rayon/8);
float y5 = random(rayon/2+rayon/8,3*rayon/4-rayon/8);
float x4 = random(rayon/2,3*rayon/4);
float x5 =random (rayon/4,rayon/2);
for(int i=0;i<4;i++) {
rotate(PI/4);//DEFOLD THE PAPER
beginShape();
vertex(0,0);//first fixed point
vertex(rayon-a,rayon-a);//END OF THE BRANCH:detail which makes all the difference ;-)
vertex(rayon-a,rayon+5-a);//END OF THE BRANCH
vertex(rayon-5-a,rayon+5-a);//END OF THE BRANCH
vertex(rayon-20-a,rayon-10-a);//END OF THE BRANCH
vertex(x4,rayon);//first group of three points
vertex(y,rayon/2+x);
vertex(x5,rayon);
vertex(0,rayon);//second fixed point
vertex(0,y4);//second group of three points
vertex(x,rayon/2+y);
vertex(0,y5);
vertex(0,y2);//third group of three points
vertex(x,y);
vertex(0,y3);//third (fixed) point, center of the snowflake
endShape();
//MAKING THE SYMETRICAL TRIANGLE
beginShape();
vertex(0,0);
vertex(-rayon+a,-rayon+a);
vertex(-rayon+a,-rayon+a);
vertex(-rayon+5+a,-rayon-5+a);
vertex(-rayon+20+a,-rayon+10+a);
vertex(-x4,-rayon);
vertex(-y,-(rayon/2+x));
vertex(-x5,-rayon);
vertex(0,-rayon);
vertex(0,-y4);
vertex(-x,-(rayon/2+y));
vertex(0,-y5);
vertex(0,-y2);
vertex(-x,-y);
vertex(0,-y3);
endShape();
}
}
0 Comments:
Post a Comment
<< Home