PImage g;
traceur[] traceurs;
void setup(){
size(640,640);
g = loadImage("lehavre.jpg");
traceurs = new traceur[0];
background(255);
stroke(0,0,0,15);
for(int a=0;a<120;a++){
traceurs = (traceur[]) append (traceurs, new traceur());
}
}
void draw(){
for(int a=0;a<traceurs.length;a++){
traceurs[a].dessine();
}
}
class traceur{
float x,y,an,v;
float[] rang={-0.05,0.05};
traceur(){
x= random(width);y=random(height);
an=random(TWO_PI);v=random(1.2,1.5);
rang[0]=random(-0.1,-0.05);
rang[1]=random(0.05, 0.1);
}
void dessine(){
an+=random(rang[0],rang[1]);
float newx=x+cos(an)*v;
float newy=y+sin(an)*v;
if(newx<0||newx>width||newy<0||newy>height){
newx=constrain(newx,0,width);
newy=constrain(newy,0,height);
an+=random(-PI,PI);
rang[0]=random(-0.1,-0.05);
rang[1]=random(0.05, 0.1);
}
if(random(100)<1){
rang[0]=random(-0.1,-0.05);
rang[1]=random(0.05, 0.1);
}
float angleChoisi=an;
float couleur=brightness(g.get(int(newx),int(newy)));
for(float a=an-PI*0.3;a<an+PI*0.3;a+=PI*0.15){
int ixe=int(newx+cos(a)*v);
int igr=int(newy+sin(a)*v);
float col=brightness(g.get(ixe,igr));
if(col<couleur){
couleur=col;
angleChoisi=a;
}
}
an=angleChoisi;
if(random(100)<1){an=an+random(-1,1);}
line(x,y,newx,newy);
x=newx;y=newy;
}
}
void keyReleased(){
saveFrame("img#####.png");
}
Wow….what nice code this person is sharing. Thank you. Very instructive.
GCN Goes Bikepacking In The Atlas Mountains, Morocco
SpaceEngine 0.990: Serenity





