top of page
Search
  • Writer's picturejunfeng shao

Assignment 10: p5 interactivity

var x, y, d;

var r, g, b;


function setup() {

createCanvas(600, 600);

x = 300;

y = 50;

d = 50;

r = 0;

g = 255;

b = 0;

}


function draw() {

noStroke();

fill(r, g, b);

ellipse(mouseX, mouseY, d, d);

}


function keyPressed(){

if(keyCode === UP_ARROW){

d += 25;

}

else if (keyCode === DOWN_ARROW){

if (d >= 50){

d -= 25;

}

}

else if (key === 'q'){

r = 255;

g = 165;

b = 0;

}

else if (key === 'w'){

r = 0;

g = 255;

b = 0;

}

else if (key === 'e'){

r = 255;

g = 0;

b = 0;

}

}


function mousePressed(){

background(255);

}


4 views0 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