forked from ohboyd/bouncing_dvd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sketch.js
40 lines (32 loc) · 783 Bytes
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// control + option + l starts live server
let coord = {
x: 40,
y: 40
};
let velocity = {
x: 2,
y: 2
};
let dvd;
function preload() {
logo = loadImage("assets/logo.png");
}
function setup() {
// this creates the initial window and loads the image
createCanvas(window.innerWidth, window.innerHeight);
logo.resize(194, 125);
}
function draw() {
background(0);
image(logo, coord.x, coord.y);
// changes x velocity and color when an edge is impacted
if(coord.x + logo.width > width || coord.x < 0) {
velocity.x = (-velocity.x);
}
coord.x = coord.x + velocity.x;
// changes y velocity and color when an edge is impacted
if (coord.y + logo.height > height || coord.y < 0) {
velocity.y = (-velocity.y);
}
coord.y = coord.y + velocity.y
}