top of page

Bouncing circle

  • Kelly Kiernan
  • Apr 4, 2019
  • 1 min read

Here is the code for a green square that follows the mouse, and a color changing circle once it hits top and bottom. I followed almost exactly what was going on in class. The canvas size is increased from 600 x 600 to 1000 x 600.





bouncing circle and square following mouse

var x =500;

var y =300;

var sqwl =50;

xSpeed = 5;

ySpeed = 3;

function setup() {

// put setup code here

createCanvas(1000, 600);

r = 255;

g = 0;

b = 0;

}

function draw() {

background (150);

fill('green');

rect(mouseX, mouseY,sqwl, sqwl);

//this is my bouncing circle

fill(r, g, b)

ellipse(x, y, 50, 50);

x = x + xSpeed;

y = y + ySpeed;

//in order to get the circle to stay on the screen we need a conditional.

//if my circle touches the right side of the screen, change the direction.

if (x > 1000 - sqwl/2){

xSpeed = -xSpeed;

}

else if (x <0){

xSpeed = -xSpeed;

}

//bounce my circle if we touch top or bottom

if (y >  (600 -sqwl/2)){

ySpeed = -ySpeed;

b = 0;

}

else if (y < sqwl/2){

ySpeed = -ySpeed;

b=255;

}

}

 
 
 

Recent Posts

See All
Coding for final

let font, fontsize = 40; let fortune = [15]; //this is the ballspeed for every variable var xSpeed = 5; var xE = 1000; var yE = 800; var...

 
 
 
Final coding

Examples of questions to ask a magic 8 ball Questions from an Aspiring Artist going through Tutorials 1.  Will my Tutorials grade reflect...

 
 
 
Final project

I didnt want to fully copy the jackson pollack splatter idea, but I really like it and want to maybe do a painting idea. I have a second...

 
 
 

コメント


bottom of page