//variables to store the position and size of circle
float x,y;
int diameter;
//amount of wobble
float wobble=1.5;
//speed of circle
float speed;
void setup (){
//set up environment
size (300,300);
background (#000000);
stroke (#FFFC00);
smooth();
framerate (30);
//circle is at (150,150), with diameter 15, speed 0.1
x=150;
y=150;
diameter=15;
speed=0.1;
}
void draw(){
//clear background
background (#000000);
//calculate distance
float distX=x - mouseX;
float distY=y - mouseY;
//update position so that circle follows mouse
//added some wobble
x=x-distX*speed+random(2*wobble)-wobble;
y=y-distY*speed+random(2*wobble)-wobble;
//draw the ellipse
ellipse (x,y,diameter,diameter);
fill(#3CFF00);
//mouse pressed
if(mousePressed) {
fill (#FF0006);
} else {
stroke(#FFFC00);
fill (#3CFF00);
}
}

0 Comments:
Post a Comment
<< Home