Categories

M Train-Code Interactive Sketch

int x=mouseX;
int y=mouseY;
int speedX=6;
int speedY=8;

void setup(){
size(800, 600);

}

void draw(){
background(255);
 if (keyPressed==false){
 x=x+speedX;
 y=y+speedY;
 
 if ((x>width)||(x<0)){
 speedX=speedX*(-1);
 }
 if ((y>height)||(y<0)){
 speedY=speedY*(-1);
 }
 noStroke();
 fill(0);
 ellipse(x, y, 20, 20);
 
}else{
 noStroke();
 fill(200);
 ellipse(mouseX, mouseY, 20, 20);
 x=mouseX;
 y=mouseY;
}
}
No Comments

Leave a Comment: