-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoon-sketch.js
73 lines (69 loc) · 1.46 KB
/
moon-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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
let moonPic;
function preload() {
moonPic = loadImage("bitcoinMoon.png");
}
// let angle = 0
let x;
let y;
let snelheidX;
let snelheidY;
let breed;
let hoog;
// function chooseRandomXDirection() {
// // if moon gets out of screen, we reset it to the middle and this function
// //picks a new direction
// dx = random(0, 1)
// if (dx > 0.5) {
// dx = 1
// } else {
// dx = -1
// }
// }
function setup() {
let cnv = createCanvas(windowWidth, windowHeight);
cnv.position(0, 0);
cnv.style("z-index", "-1");
// angleMode(DEGREES)
x = windowWidth / 2;
y = windowHeight / 2;
breed = 1;
hoog = breed;
snelheidX = -2;
snelheidY = 1;
}
function draw() {
background(0);
// translate(windowWidth/2, windowHeight/2)
// rotate(angle)
// image(moonPic,(breed/2)*-1,(hoog/2)*-1,breed,hoog)
image(moonPic, x, y, breed, hoog);
// angle = angle+0.5
x = x + snelheidX;
y = y + snelheidY;
breed = breed + 0.5;
hoog = breed;
if (
x >= windowWidth + 200 ||
x <= -200 ||
y >= windowHeight + 200 ||
y <= -200
) {
breed = 1;
x = windowWidth / 2;
y = windowHeight / 2;
snelheidX = random(0, 1);
if (snelheidX < 0.5) {
snelheidX = -2;
} else {
snelheidX = 2;
}
snelheidY = random(0, 1);
if (snelheidY < 0.5) {
snelheidY = -1;
} else {
snelheidY = 1;
}
}
}
// click "go live" below in the task-bar to start up a canvas at
// http://127.0.0.1:5500/