[Processing] Lines Demo
Voila ma petite contribution à notre projet cooperatif en Processing.
/*
* Lines Demo
* by Xavier Gouchet
* versions : change the v variable below
* 1 - random
* 2 - square
* 2 - circle
* fading : change the fade variable below
*/
int v = 2;
boolean fade = true;
//
int oldX = 0, oldY = 0;
float angle = 0;
int t = 0;
int w = 256;
int h = 256;
void setup(){
size(w,h);
frameRate(12);
background(0);
smooth();
}
void draw(){
// Fade the old image
if (fade){
fill (0,0,0,8);
stroke(0,0,0,8);
rect(0,0,w,h);
}
// increment timer
t+=3;
t = t%256;
// set stroke color
colorMode(HSB, 256);
strokeWeight(4); // Thicker
stroke(t,256,256);
// create random position
int x = (int) random(w);
int y = (int) random(h);
if (v==3){
angle += random(PI/6,PI/3);
float radius = random(min(w,h))/2;
x = (int) ((w/2) + (cos(angle)*radius));
y = (int) ((h/2) + (sin(angle)*radius));
}
//*
if (v==2){
if (t%2 == 0){
// move horizontally
y = oldY;
} else {
// move vertically
x = oldX;
} // */
}
// draw lines
line(oldX,oldY,x,y);
// position become old position
oldX = x;
oldY = y;
}
Xavier