-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLightning.js
More file actions
130 lines (103 loc) · 2.63 KB
/
Lightning.js
File metadata and controls
130 lines (103 loc) · 2.63 KB
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
var width = 900;
var height = 500;
var maxDTheta = PI/10;
var minDTheta = PI/20;
var maxTheta = PI/2;
var childGenOdds = .01;
var minBoltWidth = 3;
var maxBoltWidth = 10;
var minJumpLength = 1;
var maxJumpLength = 10;
var stormMode = true;
var clearStrikes = true;
var randomColors = false;
var maxTimeBetweenStrikes = 3000;
var minFadeIntervalMillis = 500;
var maxFadeIntervalMillis = 1000;
//var yellow = var(59,99,99);
//var red = var(0,99,99);
var boltColor;
var skyColor;
var bolt;
var lastStrike = 0;
var nextStrikeInNms = 0;
//var playThunder = false;
//var useDing = false;
//import ddf.minim.*;
//AudioSample thunderSound;
//Minim minim;
//distance, in milliseconds, of the storm.
var meanDistance = 0;
//if the current time matches the time in this arraylist, it should fire!
var thunderTimes = [];
var currentBolts = [];
var maxConcurrentStrikes = 5
function setup(){
colorMode(RGB,100);
createCanvas(windowWidth, windowHeight);
//minim = new Minim(this);
//thunderSound = minim.loadSample("thunder.mp3");
noFill();
meanDistance = 1000*.5;
// yellow = var(60/3.6,99,99);
// red = var(0,99,99);
boltColor = color(255,255,255);
skyColor = color(0,0,0);
fill(0, 100);
rect(0, 0, width, height);
smooth();
}
function draw(){
//check if any of the stored times need to make a 'ding'
//if(playThunder && thunderTimes.size() > 0)
// if(millis() > (Float)thunderTimes.get(0)){
// thunderTimes.remove(0);
// thunderSound.trigger();
// prvarln("boom!");
// }
if(stormMode && millis()-lastStrike>nextStrikeInNms){//time for a new bolt?
lastStrike = millis();
nextStrikeInNms = random(0,maxTimeBetweenStrikes);
for (i=0;i<random(0,maxConcurrentStrikes ); i++){
currentBolts.push(new lightningBolt(random(0,width),0,random(minBoltWidth,maxBoltWidth),0,minJumpLength,maxJumpLength,boltColor))
};
for (i=0;i<currentBolts.length; i++){
currentBolts[i].draw();
};
//if(playThunder)
// thunderTimes.add(bolt.getThunderTime());
smooth();
}
else{
if(clearStrikes){
noStroke();
fill(skyColor);
rect(0,0,width,height);
noFill();
}
}
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
function stop(){
//thunderSound.close();
//minim.stop();
// super().stop();
}
function randomSign() //returns +1 or -1
{
var num = random(-1,1);
if(num==0)
return -1;
else
return (float)(num/abs(num));
}
function randomColor(){
return color(random(0,255),random(0,255),random(0,255));
}
function slightlyRandomColor( inputCol, length){
var h = hue(inputCol);
h = (h+random(-length,length))%100;
return color(h,99,99);
}