forked from APCSLowell/Lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lightning.pde
79 lines (79 loc) · 1.13 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
int col;
int rot;
void setup()
{
size(800,800);
colorMode(HSB,360);
background(0);
}
void draw()
{
fill(0,0,0,36);
stroke(0,0,0,36);
rect(0,0,800,800);
}
void mousePressed()
{
Bolt bob = new Bolt(mouseX,mouseY,col,rot);
bob.show();
}
void keyPressed()
{
if (key == CODED) {
switch (keyCode)
{
case UP :
{rot--;
break;
}
case DOWN :
{rot++;
break;
}
case LEFT :
{col--;
col%=120;
while(col<0)
{col+=120;}
break;
}
case RIGHT :
{col++;
col%=120;
while(col<0)
{col+=120;}
break;
}
}
}
}
class Bolt {
int x;
int y;
int c;
int r;
Bolt (int x, int y, int c, int r) {
this.x = x;
this.y = y;
this.c = c;
this.r = r;
}
void show()
{
stroke(3*c,360,180);
translate(x, y);
rotate(r*PI/60);
int startX = 0;
int startY = 0;
int endX;
int endY;
while(startX<800 && startY<400 && startY>-400)
{
endX = startX + (int)(Math.random()*10+1);
endY = startY + (int)(Math.random()*11-5);
line(startX, startY, endX, endY);
startX = endX;
startY = endY;
}
}
}