Triangle springs

Modification d’un code déjà existant : changement du rythme des figures et démultiplication.

 

 

float t=0.001;

void setup()
{
//fullScreen();
size(540, 540);
strokeWeight(2);
}
void draw()
{
background(255);
harom(300,600,40,460,50,(sin(0.0005*millis()%(2*PI))+1)/2);
harom2(500,460,40,460, 50,(sin(0.0005*millis()%(2*PI))+1)/2);
wesh(350,250,40,460,50,(sin(0.0005*millis()%(2*PI))+1)/2);
harom3(600,360,40,300, 50,(sin(0.0005*millis()%(2*PI))+1)/2);
harom4(600,700,40,400, 50,(sin(0.0005*millis()%(2*PI))+1)/2);
harom5(300,-50,40,400, 50,(sin(0.0005*millis()%(2*PI))+1)/2);
harom6(550,-10,40,400, 50,(sin(0.0005*millis()%(2*PI))+1)/2);
harom7(-10,550,40,400, 50,(sin(0.0005*millis()%(2*PI))+1)/2);

}

void harom(float ax, float ay,float bx, float by, int level,float ratio)
{
if(level!=0){
float vx,vy,nx,ny,cx,cy;
vx=bx-ax;
vy=by-ay;
nx=cos(PI/3)*vx-sin(PI/3)*vy;
ny=sin(PI/3)*vx+cos(PI/3)*vy;
cx=ax+nx;
cy=ay+ny;
line(ax,ay,bx,by);
line(ax,ay,cx,cy);
line(cx,cy,bx,by);
harom(ax*ratio+cx*(1-ratio),ay*ratio+cy*(1-ratio),ax*(1-ratio)+bx*ratio,ay*(1-ratio)+by*ratio,level-1,ratio);
}
}
void harom2(float ax, float ay,float bx, float by, int level,float ratio)
{
if(level!=0){
float vx,vy,nx,ny,cx,cy;
vx=bx-ax;
vy=by-ay;
nx=cos(PI/3)*vx-sin(PI/3)*vy;
ny=sin(PI/3)*vx+cos(PI/3)*vy;
cx=ax+nx;
cy=ay+ny;
line(ax,ay,bx,by);
line(ax,ay,cx,cy);
line(cx,cy,bx,by);
harom(ax*ratio+cx*(1-ratio),ay*ratio+cy*(1-ratio),ax*(1-ratio)+bx*ratio,ay*(1-ratio)+by*ratio,level-1,ratio);
}
}
void wesh(float ax, float ay,float bx, float by, int level,float ratio)
{
if(level!=0){
float vx,vy,nx,ny,cx,cy;
vx=bx-ax;
vy=by-ay;
nx=cos(PI/3)*vx-sin(PI/3)*vy;
ny=sin(PI/3)*vx+cos(PI/3)*vy;
cx=ax+nx;
cy=ay+ny;
line(ax,ay,bx,by);
line(ax,ay,cx,cy);
line(cx,cy,bx,by);
harom(ax*ratio*1+cx*(1-ratio),ay*ratio+cy*(1-ratio),ax*(1-ratio)+bx*ratio,ay*(1-ratio)+by*ratio,level-1,ratio);
}
}
void harom3(float ax, float ay,float bx, float by, int level,float ratio)
{
if(level!=0){
float vx,vy,nx,ny,cx,cy;
vx=bx-ax;
vy=by-ay;
nx=cos(PI/3)*vx-sin(PI/3)*vy;
ny=sin(PI/3)*vx+cos(PI/3)*vy;
cx=ax+nx;
cy=ay+ny;
line(ax,ay,bx,by);
line(ax,ay,cx,cy);
line(cx,cy,bx,by);
harom(ax*ratio+cx*(1-ratio),ay*ratio+cy*(1-ratio),ax*(1-ratio)+bx*ratio,ay*(1-ratio)+by*ratio,level-1,ratio);
}
}
void harom4(float ax, float ay,float bx, float by, int level,float ratio)
{
if(level!=0){
float vx,vy,nx,ny,cx,cy;
vx=bx-ax;
vy=by-ay;
nx=cos(PI/3)*vx-sin(PI/3)*vy;
ny=sin(PI/3)*vx+cos(PI/3)*vy;
cx=ax+nx;
cy=ay+ny;
line(ax,ay,bx,by);
line(ax,ay,cx,cy);
line(cx,cy,bx,by);
harom(ax*ratio+cx*(1-ratio),ay*ratio+cy*(1-ratio),ax*(1-ratio)+bx*ratio,ay*(1-ratio)+by*ratio,level-1,ratio);
}
}
void harom5(float ax, float ay,float bx, float by, int level,float ratio)
{
if(level!=0){
float vx,vy,nx,ny,cx,cy;
vx=bx-ax;
vy=by-ay;
nx=cos(PI/3)*vx-sin(PI/3)*vy;
ny=sin(PI/3)*vx+cos(PI/3)*vy;
cx=ax+nx;
cy=ay+ny;
line(ax,ay,bx,by);
line(ax,ay,cx,cy);
line(cx,cy,bx,by);
harom(ax*ratio+cx*(1-ratio),ay*ratio+cy*(1-ratio),ax*(1-ratio)+bx*ratio,ay*(1-ratio)+by*ratio,level-1,ratio);
}
}
void harom6(float ax, float ay,float bx, float by, int level,float ratio)
{
if(level!=0){
float vx,vy,nx,ny,cx,cy;
vx=bx-ax;
vy=by-ay;
nx=cos(PI/3)*vx-sin(PI/3)*vy;
ny=sin(PI/3)*vx+cos(PI/3)*vy;
cx=ax+nx;
cy=ay+ny;
line(ax,ay,bx,by);
line(ax,ay,cx,cy);
line(cx,cy,bx,by);
harom(ax*ratio+cx*(1-ratio),ay*ratio+cy*(1-ratio),ax*(1-ratio)+bx*ratio,ay*(1-ratio)+by*ratio,level-1,ratio);
}
}
void harom7(float ax, float ay,float bx, float by, int level,float ratio)
{
if(level!=0){
float vx,vy,nx,ny,cx,cy;
vx=bx-ax;
vy=by-ay;
nx=cos(PI/3)*vx-sin(PI/3)*vy;
ny=sin(PI/3)*vx+cos(PI/3)*vy;
cx=ax+nx;
cy=ay+ny;
line(ax,ay,bx,by);
line(ax,ay,cx,cy);
line(cx,cy,bx,by);
harom(ax*ratio+cx*(1-ratio),ay*ratio+cy*(1-ratio),ax*(1-ratio)+bx*ratio,ay*(1-ratio)+by*ratio,level-1,ratio);
}
}