xxxxxxxxxx
58
var dot;
function setup() {
createCanvas(600, 600);
dot1 = new Circle1();
dot2 = new Circle1();
dot3 = new Circle1();
background(0);
}
function draw() {
dot1.display();
dot1.interact();
dot2.display();
dot2.interact();
dot3.display();
dot3.interact();
}
function Circle1() {
this.x = random(100,500);
this.y = random(200,500);
this.speed = 5;
this.radius = 10;
this.display = function() {
var x2 = map(mouseX, 0, width, this.radius, width+this.radius);
//ellipse(x2, 75, 50, 50);
fill(0);
stroke(255);
ellipse(this.x, this.y, this.radius * 2, this.radius * 2);
ellipse(this.x-2, this.y-2, this.radius * 2, this.radius * 2);
ellipse(this.x-4, this.y-4, this.radius * 2, this.radius * 2);
ellipse(this.x-6, this.y-6, this.radius * 2, this.radius * 2);
ellipse(this.x-8, this.y-8, this.radius * 2, this.radius * 2);
ellipse(this.x-10, this.y-10, this.radius * 2, this.radius * 2);
ellipse(this.x-12, this.y-12, this.radius * 2, this.radius * 2);
}
this.interact = function() {
if (overCircle(this.x, this.y, this.radius)) {
this.x = this.x
this.y = this.y
} else {
this.x = this.x + random(-this.speed, this.speed);
this.y = this.y + random(-this.speed, this.speed);
}
}
}
function overCircle(x, y, radius) {
if (dist(x, y, mouseX, mouseY) < radius) {
return true;
} else {
return false;
}
}