-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
59 lines (49 loc) · 1.1 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
let x;
let y;
let xspeed;
let yspeed;
let logo;
let r, g, b;
function preload() {
logo = loadImage('logo.jpg'); //Change this with your logo filename
}
function setup() {
createCanvas(windowWidth, windowHeight);
x = random(width);
y = random(height);
xspeed = 5; //Change this with your preffered speed, value must be the same as yspeed. It is advised to keep it 5
yspeed = 5; //Change this with your preffered speed, value must be the same as yspeed. It is advised to keep it 5
pickColor();
}
function pickColor() {
r = random(100, 256);
g = random(100, 256);
b = random(100, 256);
}
function draw() {
background(0);
// rect(x, y, 80, 60);
// Draw the logo
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();
}
}