int s; // size
int u; // unit
PVector p; // line position
PVector d; // direction
void setup() {
s = 300;
u = 2;
p = new PVector(0, 0);
d = new PVector(u, 0); // left to right
size(s, s);
background(#FFFFFF);
colorMode(HSB, s / u);
}
void draw() {
// direction
if (p.x > s) {
p.x = s;
d.x = 0;
d.y = u;
}
else if (p.y > s) {
p.y = s;
d.x = -u;
d.y = 0;
}
else if (p.x < 0) {
p.x = 0;
d.x = 0;
d.y = -u;
}
else if (p.y < 0) {
p.y = 0;
d.x = u;
d.y = 0;
}
// draw
stroke(frameCount % (s / u), 127, 127);
line(p.x, p.y, s - p.y, p.x);
// update
p.add(d);
}
Home | Archives | Categories | Tags | About |
|