forked from APCSLowell/Lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lightning.pde
176 lines (143 loc) · 4.17 KB
/
Lightning.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
boolean drawingside = false;
boolean drawingvert = false;
boolean drawingrandom = false;
boolean drawingdiag = false;
void setup() {
size(1000, 1000);
}
void draw() {
strokeWeight(1);
//fill(0, 60, 100, (int)(Math.random()*61));
fill(0, (int)(Math.random()*31));
rect(0, 0, 1000, 1000);
stroke(255);
rect(0, 250, 250, 500);
rect(750, 250, 250, 500);
rect(250, 0, 500, 250);
rect(250, 750, 500, 250);
if (mousePressed){
fill(100, 150, 200);
ellipse(mouseX, mouseY, 50, 50);
}
stroke(255);
if (drawingside){
lightning();
drawingside = false;
} else if (drawingvert) {
lightningvert();
drawingvert = false;
} else if (drawingrandom) {
int picker = (int)(Math.random()*3);
if (picker == 0)
lightning();
else if (picker == 1)
lightningvert();
//else
//lightningdiag();
drawingrandom = false;
} else if (drawingdiag) {
lightningdiag();
drawingdiag = false;
}
}
void lightning() {
int x_coord = 0;
int y_coord = (int)(Math.random()*(height)+1);
int x_prev;
int y_prev;
stroke((int)(Math.random()*256), (int)(Math.random()*256), (int)(Math.random()*256), 200);
while (x_coord < width) {
x_prev = x_coord;
y_prev = y_coord;
x_coord += (int)(Math.random()*(1+width/75));
if (Math.random() <= 0.5)
y_coord -= (int)(Math.random()*(1+width/75));
else
y_coord += (int)(Math.random()*(1+width/75));
strokeWeight((int)(Math.random()*5)+1);
line(x_prev, y_prev, x_coord, y_coord);
}
}
void lightningvert() {
int x_coord = (int)(Math.random()*(width)+1);
int y_coord = 0;
int x_prev;
int y_prev;
stroke((int)(Math.random()*256), (int)(Math.random()*256), (int)(Math.random()*256), 200);
while (y_coord < height) {
x_prev = x_coord;
y_prev = y_coord;
y_coord += (int)(Math.random()*(1+width/75));
if (Math.random() <= 0.5)
x_coord -= (int)(Math.random()*(1+width/75));
else
x_coord += (int)(Math.random()*(1+width/75));
strokeWeight((int)(Math.random()*5)+1);
line(x_prev, y_prev, x_coord, y_coord);
}
}
//split into 4
void lightningdiag() {
int x_coord;
int y_coord;
int x_prev;
int y_prev;
int picker = (int)(Math.random()*4);
stroke((int)(Math.random()*256), (int)(Math.random()*256), (int)(Math.random()*256), 200);
if (picker == 0) {
x_coord = 0;
y_coord = 0;
while (x_coord < width && y_coord < height){
x_prev = x_coord;
y_prev = y_coord;
x_coord += (int)(Math.random()*(1+width/75));
y_coord += (int)(Math.random()*(1+height/75));
strokeWeight((int)(Math.random()*5)+1);
line(x_prev, y_prev, x_coord, y_coord);
}
} else if (picker == 1) {
x_coord = width;
y_coord = 0;
while (x_coord > 0 && y_coord < height){
x_prev = x_coord;
y_prev = y_coord;
x_coord -= (int)(Math.random()*(1+width/75));
y_coord += (int)(Math.random()*(1+height/75));
strokeWeight((int)(Math.random()*5)+1);
line(x_prev, y_prev, x_coord, y_coord);
}
} else if (picker == 2) {
x_coord = 0;
y_coord = height;
while (x_coord < width && y_coord > 0){
x_prev = x_coord;
y_prev = y_coord;
x_coord += (int)(Math.random()*(1+width/75));
y_coord -= (int)(Math.random()*(1+height/75));
strokeWeight((int)(Math.random()*5)+1);
line(x_prev, y_prev, x_coord, y_coord);
}
} else {
x_coord = width;
y_coord = height;
while (x_coord > 0 && y_coord > 0){
x_prev = x_coord;
y_prev = y_coord;
x_coord -= (int)(Math.random()*(1+width/75));
y_coord -= (int)(Math.random()*(1+height/75));
strokeWeight((int)(Math.random()*5)+1);
line(x_prev, y_prev, x_coord, y_coord);
}
}
}
void mouseDragged() {
if ((mouseX <= 250 || mouseX >= 750) && (mouseY >= 250 && mouseY <= 750))
drawingside = true;
else if ((mouseY <= 250 || mouseY >= 750) && (mouseX >= 250 && mouseX <= 750))
drawingvert = true;
else if ((mouseX >= 250 && mouseX <= 750) && (mouseY >= 250 && mouseY <= 750))
drawingrandom = true;
else
drawingdiag = true;
redraw();
}