-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathweather.em
167 lines (134 loc) · 3.58 KB
/
weather.em
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
system.require('work/motion.em');
system.require('work/units.em');
// General weather box settings
var width = 100 * u.m;
var ground = -20 * u.m;
var sky = 50 * u.m;
var center = system.self.position;
center.y = ground;
// Cloud settings
var cloudScale = sky / 0.0675;
var cloudOffset = cloudScale * 0.025;
var cloudMesh = 'meerkat:///wmonroe4/clouds.dae/optimized/0/clouds.dae';
var cloudDome;
// Lightning settings
var duration = 0.25 * u.s;
var spacing = 5 * u.s;
var lightningMesh = 'meerkat:///wmonroe4/lt2.dae/optimized/0/lt2.dae';
var lightningBolt;
// Snow settings
var snowSpeed = 1.5 * u.m / u.s;
var snowMesh = 'meerkat:///wmonroe4/snow_large_em.dae/optimized/0/snow_large_em.dae';
// Rain settings
var rainSpeed = 20 * u.m / u.s;
var rainMesh = 'meerkat:///wmonroe4/rain_large.dae/optimized/0/rain_large.dae';
// Precipitation (rain/snow) settings
var precipScale = 20 * u.m;
var precipBlocks = [];
var precipSpeed = rainSpeed;
var precipMesh = rainMesh;
system.createPresence(lightningMesh, function(p) {
lightningBolt = p;
p.scale = (sky - ground) * Math.sqrt(5) / 4;
p.mesh = '';
});
var stop = {lightning: false};
function startLightning() {
flashOn();
}
function flashOn() {
if(stop.lightning) {
stop.lightning = false;
return;
}
var x = center.x + width * (Math.random() - 0.5);
var z = center.z + width * (Math.random() - 0.5);
var y = (ground + sky) / 2;
var theta = 2 * Math.PI * Math.random();
system.print('<' + x + ', ' + z + '>\n');
lightningBolt.position = <x, y, z>;
lightningBolt.orientation = new util.Quaternion(<0, 1, 0>,
theta);
lightningBolt.mesh = lightningMesh;
system.timeout(duration, flashOff);
}
function randomExponential(lambda) {
var u = 1 - Math.random();
return -Math.log(u) / lambda;
}
function flashOff() {
lightningBolt.mesh = '';
system.timeout(randomExponential(1 / spacing), flashOn);
}
function stopLightning() {
stop.lightning = true;
}
function createBlock(pos) {
if(pos.x > center.x + width) {
pos.x = center.x - width;
pos.z += 2 * precipScale;
}
if(pos.z > center.z + width) {
pos.z = center.z - width;
pos.y -= 2 * precipScale;
}
if(pos.y < ground)
return;
system.createPresence(precipMesh, function(newBlock) {
newBlock.position = pos;
newBlock.scale = precipScale * Math.sqrt(3);
newBlock.controller = new motion.Position(newBlock, function(p) {
if(p.position.y + precipScale < ground) {
var newPos = p.position;
newPos.y += Math.ceil((sky - ground) /
(2 * precipScale)) * 2 * precipScale;
p.position = newPos;
}
}, 0.125 + 0.25 * Math.random());
precipBlocks.push(newBlock);
system.timeout(.001, function() {
createBlock(pos + <2 * precipScale, 0, 0>);
});
});
}
function makePrecip() {
var pos = <center.x - width, sky, center.z - width>;
createBlock(pos);
}
function stopPrecip() {
pausePrecip();
for(var i in precipBlocks)
precipBlocks[i].mesh = '';
}
function pausePrecip() {
for(var i in precipBlocks)
precipBlocks[i].velocity = <0, 0, 0>;
}
function startPrecip() {
for(var i in precipBlocks) {
precipBlocks[i].mesh = precipMesh;
precipBlocks[i].velocity = <0, -precipSpeed, 0>;
}
}
function rain() {
precipMesh = rainMesh;
precipSpeed = rainSpeed;
startPrecip();
}
function snow() {
precipMesh = snowMesh;
precipSpeed = snowSpeed;
startPrecip();
}
function makeClouds() {
var resetDome = function (dome) {
cloudDome = dome;
cloudDome.position = center + <0, cloudOffset, 0>;
cloudDome.scale = cloudScale;
}
if(typeof(cloudDome) === 'undefined') {
system.createPresence(cloudMesh, resetDome);
} else {
resetDome(cloudDome);
}
}