int x1 = 0; int y1 = 0; int x2 = 0; int y2 = 0; int xspeed1 = 3; int yspeed1 = 4; int xspeed2 = 4; int yspeed2 = 3; int size = 50; float distance = 0.0; void setup() { size(640, 480); x1 = int(random(width)); x2 = int(random(width)); y1 = int(random(height)); y2 = int(random(height)); xspeed1 = int(random(10)+1); yspeed1 = int(random(10)+1); xspeed2 = int(random(10)+1); yspeed2 = int(random(10)+1); }
void draw() {
background(0); stroke(0); fill(255, 255, 0); distance = dist(x1, y1, x2, y2); println(distance); if(distance < size){ fill(random(255), random(255), random(255)); } if(frameCount % 20 < 10) { arc(x1, y1, size, size, 0.52, 5.76); } else { arc(x1, y1, size, size, 0.1, 6.18); } if(frameCount % 20 < 10) { arc(x2, y2, size, size, 0.52, 5.76); } else { arc(x2, y2, size, size, 0.1, 6.18); }
x1 = x1 + xspeed1; y1 = y1 + yspeed1; x2 = x2 + xspeed2; y2 = y2 + yspeed2; if(x1 < 0 || x1 > 640) { xspeed1 = -xspeed1; } if(y1 < 0 || y1 > 480) { yspeed1 = -yspeed1; } if(x2 < 0 || x2 > 640) { xspeed2 = -xspeed2; } if(y2 < 0 || y2 > 480) { yspeed2 = -yspeed2; } } void mousePressed(){ x1 = int(random(width)); x2 = int(random(width)); y1 = int(random(height)); y2 = int(random(height)); xspeed1 = int(random(10)+1); yspeed1 = int(random(10)+1); xspeed2 = int(random(10)+1); yspeed2 = int(random(10)+1); }
|