top of page
Search

Assignment 3: Bouncing Ball

  • Writer: Ryan  Ramcharan
    Ryan Ramcharan
  • Sep 14, 2020
  • 1 min read

For this assignment I added a ySpeed and made it different from the xSpeed, I added r,g,and b as it's own variables and I randomly just chose numbers to pick colors. My code is down below with the link to my creation.



var xPos;

var yPos;


var xSpeed;

var ySpeed;

//var ballSize;


//Here are the colors red, green,and blue

var r;

var g;

var b;


function setup() {

createCanvas(400, 400);

//setting my intial position

xPos = 10;

yPos = 400;

xSpeed = 3;

ySpeed = 5;

r = 0

g = 0

b = 0

}


function draw() {

background(0, 20);

if(xPos > 400){

xSpeed = -xSpeed ;

r = random(0, 300);

g = random(0, 255);

b = random(0, 500);

}

else if (xPos < 0){

xSpeed = -xSpeed ;

r = random(0, 300);

g = random(0, 255);

b = random(0, 500);

}

if(yPos > 400){

ySpeed = -ySpeed ;

r = random(0, 300);

g = random(0, 255);

b = random(0, 500);

}

else if (yPos < 0){

ySpeed = -ySpeed ;

r = random(0, 300);

g = random(0, 255);

b = random(0, 500);

}

//move the ball horizontally

xPos = xPos + xSpeed;

//move the ball vertically

yPos = yPos + ySpeed;

//Drawing my ball

fill( r, g, b);

ellipse(xPos, yPos, 50, 50);

}

 
 
 

Recent Posts

See All
Final project

https://editor.p5js.org/yoyoganesh32/sketches/tBvFFZ4P_ It is a robot that say's certain things when you press the button, 1-9, to make...

 
 
 
Assignment#8

https://www.tinkercad.com/things/fLtKmdw1xkI-assignment-8/editel I tried making one LEDs light up while the other LED is off and when you...

 
 
 
Midterm Project

In my code, the car would have to move around the screen and avoid the balls that are on the screen. My intentions were to have a run...

 
 
 

Comments


Post: Blog2_Post
  • Facebook
  • Twitter
  • LinkedIn

©2020 by Ganesh Ryan Ramcharan Blog👨‍💻👨‍🎨. Proudly created with Wix.com

bottom of page