top of page
Search

Assignment 3: A Bouncing Ball

  • jficco2
  • Sep 15, 2020
  • 1 min read



//These will keep track of positions

var xPos;

var yPos;


var xSpeed;

var ySpeed;


var ballsize;


var g;

var r;

var b;


function setup() {

createCanvas(400, 400);


//Setting my initial position

xPos=200;

yPos=200;

xSpeed=5;

ySpeed=5;

g=0;

r=1;

b=2;

}


function draw() {

background(220);

//Conditional

//If the ball touches right hand side of window

if(xPos>400-25){

//Then move ball to the left

//console.log("WE DID IT")

xSpeed=-xSpeed;

g= random(0,255);

r= random(255,0)

}

if(xPos<0 + 25){

xSpeed=-xSpeed

g= random(0,255);

r= random (1,255);

b= random (2,255);

}


//Conditional

if(yPos>400-25){

ySpeed=-ySpeed

g=random(0,255);

r=random(255,0)

}


if(yPos<0 + 25){

g=random(0,255);

r=random(1,255);

b=random(2,255);

}

/*if((xPos > 400) || (xPos < 0)){

xSpeed = -xSpeed;

}*/


/*if (xPos > 400){

xSpeed=-xSpeed

}

else if (xPos < 0){

xSpeed=-xSpeed

}*/


//move the ball

xPos=xPos+xSpeed;

//Drawing my ball

fill (r, g, b)

ellipse(xPos, yPos, 50, 50)

}


 
 
 

Recent Posts

See All
Final Project

Completely scratched the Pacman idea and went back to the drawing board since I got so many errors. I decided to go with Doodle Jump....

 
 
 
Midterm

https://editor.p5js.org/jon_ficco/sketches/tf19icH2_ I wanted to add a score board but every time I tried the whole thing wouldn't work...

 
 
 

Comments


Post: Blog2_Post
  • Facebook
  • Twitter
  • LinkedIn

©2020 by Jonathan's Blog. Proudly created with Wix.com

bottom of page