This repository has been archived by the owner on May 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.pde
127 lines (108 loc) · 2.64 KB
/
background.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
int Y_AXIS = 1;
int X_AXIS = 2;
ArrayList<fracture> fractures = new ArrayList<fracture>();
int maxFractures=int(random(20,30));
int currentFracture;
int newScreenDimX,newScreenDimY;
int oldScreenDimX,oldScreenDimY;
color b1, b2;
void setup() {
size( $(window).width(),$(window).height());
b1=color(#4ec9c5);
b2=color(#215654);
}
void draw() {
size( $(window).width(),$(window).height());
setGradient(0, 0, width, height, b1, b2, Y_AXIS);
setGradient(width, 0, width, height, b2, b1, Y_AXIS);
fill(#0e131a);
stroke(#0e131a);
strokeWeight(10);
rect(0,0,width/30,height);
rect(0,0,width,width/30);
rect(width-width/30,0,width,height);
rect(0,height-width/30,width,height);
if(maxFractures>fractures.size()) {
fractures.add(new fracture());
}
for(int i=0;i < fractures.size(); i++) {
fracture x = fractures.get(i);
currentFracture=i;
x.update();
}
}
class fracture {
int start, end;
int x1,x2,y1,y2;
int timer;
fracture() {
start=int(random(0,width+height));
for(int i=0; i<fractures.size(); i++) {
fracture k = fractures.get(i);
if(abs(start-k.fStart())<60) {
start=int(random(2,width+height));
}
}
end=int(random(0,width+height));
for(int i=0; i<fractures.size(); i++) {
fracture k = fractures.get(i);
if(abs(end-k.fEnd())<60) {
end=int(random(2,width+height));
}
}
if(start<=width) {
x1=start;
y1=0;
} else {
x1=0;
y1=start-width;
}
if(end<=width) {
x2=end;
y2=height;
} else {
x2=width;
y2=end-width;
}
println(x1 + ", " + y1 + "; " + x2 + ", " + y2);
}
void update() {
if(timer<10) {
timer++;
} else {
fractures.remove(currentFracture);
}
if(x1==x2) {
fractures.remove(currentFracture);
}
if(y1==y2) {
fractures.remove(currentFracture);
}
line(x1,y1,x2,y2);
}
int fStart() {
return start;
}
int fEnd() {
return end;
}
}
void setGradient(int x, int y, float w, float h, color c1, color c2, int axis ) {
noFill();
if (axis == Y_AXIS) { // Top to bottom gradient
for (int i = y; i <= y+h; i++) {
float inter = map(i, y, y+h, 0, 1);
color c = lerpColor(c1, c2, inter);
stroke(c);
line(x, i, x+w, i);
}
}
else if (axis == X_AXIS) { // Left to right gradient
for (int i = x; i <= x+w; i++) {
float inter = map(i, x, x+w, 0, 1);
color c = lerpColor(c1, c2, inter);
stroke(c);
line(i, y, i, y+h);
}
}
}