-
Notifications
You must be signed in to change notification settings - Fork 0
/
dvd_screensaver.pde
executable file
·73 lines (60 loc) · 1.73 KB
/
dvd_screensaver.pde
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
public int seed = int(random(-400,400));
public int posX = 1920/2 + seed; // position of the image, hereafter updated every frame
public int posY = 1080/2; // ^
public int speedX = 1; // constant speed of image, flipped when edge is encountered
public int speedY = 1; // ^
public PImage img;
public int r = 255;
public int g = 100;
public int b = 0;
public int n = 5; // the number of images in folder (if up to image3.png, this would be '4')
void setup() {
fullScreen();
background(0,0,0);
img = loadImage("image1.png"); // load image1 as the starting image
}
void draw() {
background(0,0,0); // remove image left by previous frame
// update image position by adding Δposition
posX = posX + speedX;
posY = posY + speedY;
// show the image
image(img,posX,posY);
checkBorders(); // call function that flips direction if necessary
}
public void checkBorders() {
// HORIZONTAL SPEED FLIPPER
if (speedX > 0) {
if ((posX+img.width) >= 1920) {
speedX = speedX * -1;
replaceImage();
}
}
if (speedX < 0) {
if (posX <= 0) {
speedX = speedX * -1;
replaceImage();
}
}
// VERTICAL SPEED FLIPPER
if (speedY > 0) {
if (posY+img.height >= 1080) {
speedY = speedY * -1;
replaceImage();
}
}
if (speedY < 0) {
if (posY <= 0) {
speedY = speedY * -1;
replaceImage();
}
}
}
public void replaceImage() {
img = loadImage("image" + int(random(1,n)) + ".png");
// generate suitable colour and apply to image
r = 200 + int(random(55));
g = 200 + int(random(55));
b = 200 + int(random(55));
tint(r,g,b);
}