xxxxxxxxxx
69
let x, y;
let pos_x, pos_y;
let target_x, target_y;
let angolo = 0;
function setup() {
createCanvas(400, 300);
x = width / 2;
y = height / 2;
pos_x = width / 2;
pos_y = height / 2;
target_x = random(0, width);
target_y = random(0, height);
}
function draw() {
background(200);
// Draw a circle
stroke(255);
fill(sin(angolo));
ellipse(pos_x, pos_y, 24, 24);
angolo++;
if (x < target_x) {
x++;
}
if (x > target_x) {
x--;
}
if (x == target_x) {
target_x = random(0, width);
}
if (y < target_y) {
y++;
}
if (y > target_y) {
y--;
}
if (y == target_y) {
target_y = random(0, height);
}
if (y <= 0) {
y = height;
}
if (y >= height) {
y = 0;
}
if (x <= 0) {
x = width;
}
if (x >= width) {
x = 0;
}
pos_x = x;
pos_y = y;
if (angolo > 359) {
angolo = 0;
}
}