Skip to content

Instantly share code, notes, and snippets.

@yptheangel
Created August 24, 2022 16:46
Show Gist options
  • Save yptheangel/1d8cda1f8fca55b6c1f42194ceb523c6 to your computer and use it in GitHub Desktop.
Save yptheangel/1d8cda1f8fca55b6c1f42194ceb523c6 to your computer and use it in GitHub Desktop.
bouncing logo p5js script
let x;
let y;
let xspeed;
let yspeed;
let r,g,b ;
function preload() {
logo = loadImage("logo.png")
}
function setup() {
createCanvas(800, 600);
x = random(width);
y = random(height);
xspeed = 2;
yspeed = 2;
pickColor();
}
function pickColor(){
r = random(100,256);
g = random(100,256);
b= random(100,256);
}
function draw() {
background(0);
// rect(x,y, 80,60);
tint(r,g,b);
image(logo,x,y);
x=x+xspeed;
y=y+yspeed;
if (x+logo.width >= width){
xspeed = -xspeed;
x = width-logo.width;
pickColor();
}
else if (x <=0){
xspeed = -xspeed;
x = 0;
pickColor();
}
if (y+logo.height >= height){
yspeed = -yspeed;
y=height-logo.height;
pickColor();
}
else if (y <=0){
yspeed = -yspeed;
y=0;
pickColor();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment