xxxxxxxxxx
60
var speed = true;
var position = true;
var x=10;
var y=10;
var r=125;
var g=200;
var b=200;
function setup() {
createCanvas(400, 400);
background (0);
}
function draw() {
//background (r,g,b,100);
//background (0,255,255,100);
ball ();
move (2,5);
bounce ();
}
function ball () {
noStroke();
fill(r,g,b);
//fill(random(0,255),random(0,255),random(0,255),250);
ellipse (x,y,20,20);
}
function move(xspeed,yspeed) {
if (speed == true) {
x=x+xspeed;
} else {
x=x-xspeed;
}
if (position == true) {
y=y+yspeed;
} else {
y=y-yspeed;
}
}
function bounce () {
if (x+10>width || x-10<0) {
speed=!speed;
//colchange();
}
if (y+10>height || y-10<0) {
position=!position;
//colchange();
}
}
// function colchange () {
// r = random(0,255);
// g = random(0,255);
// b = random(0,255);
// }