|
//anime3
DrawObject d1, d2, d3;
float cx, cy, c;
float x1;
float y1;
int xsize=500, ysize=300, object_size;
void setup(){
size(xsize,ysize);
d1 = new DrawObject(30,30);
d2 = new DrawObject(250,250);
d3 = new DrawObject(490,170);
}
void loop(){
background(255,255,255);
ellipseMode(CENTER_DIAMETER);
//DrawObject();
d1.drawoval();
d1.ellipsedraw();
d2.drawoval();
d2.ellipsedraw();
d3.drawoval();
d3.ellipsedraw();
}
//class
class DrawObject{
// constructor
DrawObject(float aa, float bb){
x1 = aa;
y1 = bb;
}
void drawoval(){
//distance
cx = x1 - mouseX;
cy = y1 - mouseY;
c = sqrt(cx*cx+cy*cy);
//println(c);
if(mousePressed){
if(c > 0 && c < 50){
x1-=cx/20.9;
y1-=cy/20.9;
}
}
}
void ellipsedraw(){
object_size = 5;
fill(35,52,44);
ellipse(x1,y1, object_size, object_size);
}
}
|
|