|
int screensize = 300;
int x1, y1, x2, y2;
float p_left, p_right, p_up, p_down;
float direction_x, direction_y;
int stride;
int counter;
void setup() {
size(screensize, screensize);
background(255, 255, 255);
colorMode(HSB, screensize);
x1 = y1 = x2 = y2 = 150;
stride = 3;
counter = 0;
}
void loop() {
counter++;
// To regulate of probability x, y
if (mousePressed) {
// probability of x
if (x1mouseX) {
p_right = 2;
p_left = -2;
}
// pobability of y
if (y1mouseY) {
p_down = 2.8;
p_up = -2;
}
// To regulate of probability x, y to default
} else {
p_left = -1;
p_right = 2;
p_up = -1;
p_down = 2.8; // To regulate imcomplate random. Why?
}
// to get the new x-coordinate
direction_x = random(p_left, p_right);
if (direction_x < 0) {
x2 = x1 - stride;
} else if (direction_x > 1) {
x2 = x1 + stride;
}
if (x2 < 0 || x2 > screensize) {
x2 = x1;
}
// to get the new y-coordinate
direction_y = random(p_up, p_down);
if (direction_y < 0) {
y2 = y1 - stride;
} else if (direction_x > 1) {
y2 = y1 + stride;
}
if (y2 < 0 || y2 > screensize) {
y2 = y1;
}
// to draw
fill(x2, y2, counter%300);
ellipse(x2, y2, 8, 8);
x1 = x2;
y1 = y2;
}
|