top of page
Search
  • Writer's picturejunfeng shao

Assignment 9: p5 animation

var x = 500;

var y = 300;

var sqwl = 100;

var xSpeed = 10;

var ySpeed = 5;

var r, g, b;

var triX = 500;

var triY = 50;


function setup() {

createCanvas(1000, 600);

r = 255;

g = 0;

b = 0;

}


function draw() {

background(127);

noStroke();

fill(r, g, b);

ellipse(x, y, sqwl, sqwl);

a

x = x + xSpeed;

y = y + ySpeed;

if (x > (1000 - sqwl/2)){

xSpeed = -xSpeed;

b = 0;

}

else if (x < 0 + sqwl/2){

xSpeed = -xSpeed;

b = 255;

}

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

ySpeed = -ySpeed;

g = 0;

}

else if (y < sqwl/2){

ySpeed = -ySpeed;

g = 255;

}

}


1 view0 comments

Recent Posts

See All

Final Project

My final project is a ball game. In the game, there are two ball on the screen. One ball is stationary, the other ball is moving. You can use the keyboard to control the stationary ball to make it mov

bottom of page