99
1010//seeded RNG to generate stars, snow, etc
1111function sfc32 ( a , b , c , d ) {
12- return function ( ) {
13- a >>>= 0 ; b >>>= 0 ; c >>>= 0 ; d >>>= 0 ;
14- var t = ( a + b ) | 0 ;
15- a = b ^ b >>> 9 ;
16- b = c + ( c << 3 ) | 0 ;
17- c = ( c << 21 | c >>> 11 ) ;
18- d = d + 1 | 0 ;
19- t = t + d | 0 ;
20- c = c + t | 0 ;
21- return ( t >>> 0 ) / 4294967296 ;
22- } ;
12+ return function ( ) {
13+ a >>>= 0 ; b >>>= 0 ; c >>>= 0 ; d >>>= 0 ;
14+ var t = ( a + b ) | 0 ;
15+ a = b ^ b >>> 9 ;
16+ b = c + ( c << 3 ) | 0 ;
17+ c = ( c << 21 | c >>> 11 ) ;
18+ d = d + 1 | 0 ;
19+ t = t + d | 0 ;
20+ c = c + t | 0 ;
21+ return ( t >>> 0 ) / 4294967296 ;
22+ } ;
2323}
2424
2525//scale x, y coords to screen
@@ -79,12 +79,11 @@ function drawSnow(color, coord, size) {
7979}
8080
8181function draw ( color ) {
82+ var seed ;
83+ var rand ;
8284
83- var seed ;
84- var rand ;
85-
86- g . clear ( ) ;
87- //background
85+ g . clear ( ) ;
86+ //background
8887 g . setColor ( color . bg1 ) . fillRect (
8988 px ( 0 ) , py ( 0 ) ,
9089 px ( 100 ) , py ( 45 )
@@ -96,28 +95,28 @@ g.clear();
9695 //lightning
9796 if ( color . ltn ) {
9897 g . setColor ( color . ltn ) . fillPoly ( [
99- px ( 70 ) , py ( 20 ) ,
100- px ( 60 ) , py ( 28 ) ,
101- px ( 71 ) , py ( 29 ) ,
102- px ( 63 ) , py ( 40 ) ,
103- px ( 75 ) , py ( 28 ) ,
104- px ( 64 ) , py ( 27 )
98+ px ( 70 ) , py ( 20 ) ,
99+ px ( 60 ) , py ( 28 ) ,
100+ px ( 71 ) , py ( 29 ) ,
101+ px ( 63 ) , py ( 40 ) ,
102+ px ( 75 ) , py ( 28 ) ,
103+ px ( 64 ) , py ( 27 )
105104 ] ) ;
106105 g . fillPoly ( [
107- px ( 40 ) , py ( 20 ) ,
108- px ( 30 ) , py ( 28 ) ,
109- px ( 41 ) , py ( 29 ) ,
110- px ( 33 ) , py ( 40 ) ,
111- px ( 45 ) , py ( 28 ) ,
112- px ( 34 ) , py ( 27 )
106+ px ( 40 ) , py ( 20 ) ,
107+ px ( 30 ) , py ( 28 ) ,
108+ px ( 41 ) , py ( 29 ) ,
109+ px ( 33 ) , py ( 40 ) ,
110+ px ( 45 ) , py ( 28 ) ,
111+ px ( 34 ) , py ( 27 )
113112 ] ) ;
114113 }
115114 //stars
116115 if ( color . star ) {
117116 seed = 4 ;
118117 rand = sfc32 ( 0x9E3779B9 , 0x243F6A88 , 0xB7E15162 , seed ) ;
119118 for ( let i = 0 ; i < 40 ; i ++ ) {
120- g . setColor ( color . star ) . drawCircle ( Math . floor ( rand ( ) * px ( 100 ) ) , Math . floor ( rand ( ) * py ( 33 ) ) , Math . floor ( rand ( ) * 2 ) ) ;
119+ g . setColor ( color . star ) . drawCircle ( Math . floor ( rand ( ) * px ( 100 ) ) , Math . floor ( rand ( ) * py ( 33 ) ) , Math . floor ( rand ( ) * 2 ) ) ;
121120 }
122121 }
123122 //birds
@@ -216,27 +215,27 @@ function setWeather() {
216215 if ( new Date ( ) . getHours ( ) >= 7 && new Date ( ) . getHours ( ) <= 19 ) {
217216 //day-clear
218217 a = {
219- bg1 :0x4FFF , bg2 :0x03E0 ,
220- sun :0xFD20 ,
221- path :0x8200 ,
222- mtn1 :0x045f , mtn2 :0x000F ,
223- lake :0x000F ,
224- tree1 :0x07E0 , tree2 :0 , tree3 :0x7BE0 ,
225- bird :0xFFFF
218+ bg1 :0x4FFF , bg2 :0x03E0 ,
219+ sun :0xFD20 ,
220+ path :0x8200 ,
221+ mtn1 :0x045f , mtn2 :0x000F ,
222+ lake :0x000F ,
223+ tree1 :0x07E0 , tree2 :0 , tree3 :0x7BE0 ,
224+ bird :0xFFFF
226225 } ;
227226 //day-cloudy
228227 if ( data . code == 801 || data . code == 802 ) a . cloud1 = 0xFFFF ;
229228 }
230229 else {
231230 //night-clear
232231 a = {
233- bg1 :0 , bg2 :0x0005 ,
234- sun :0xC618 ,
235- path :0 ,
236- mtn1 :0x0210 , mtn2 :0x0010 ,
237- lake :0x000F ,
238- tree1 :0x0200 , tree2 :0 , tree3 :0x59E0 ,
239- star :0xFFFF
232+ bg1 :0 , bg2 :0x0005 ,
233+ sun :0xC618 ,
234+ path :0 ,
235+ mtn1 :0x0210 , mtn2 :0x0010 ,
236+ lake :0x000F ,
237+ tree1 :0x0200 , tree2 :0 , tree3 :0x59E0 ,
238+ star :0xFFFF
240239 } ;
241240 //night-cloudy
242241 if ( data . code == 801 || data . code == 802 ) a . cloud1 = 0x4208 ;
@@ -246,12 +245,12 @@ function setWeather() {
246245 if ( new Date ( ) . getHours ( ) >= 7 && new Date ( ) . getHours ( ) <= 19 ) {
247246 //day-overcast
248247 a = {
249- bg1 :0xC618 , bg2 :0x0200 ,
250- path :0x3000 ,
251- mtn1 :0x3B38 , mtn2 :0x0005 ,
252- lake :0x000F ,
253- tree1 :0x03E0 , tree2 :0 , tree3 :0x59E0 ,
254- cloud1 :0x7BEF , cloud2 :1
248+ bg1 :0xC618 , bg2 :0x0200 ,
249+ path :0x3000 ,
250+ mtn1 :0x3B38 , mtn2 :0x0005 ,
251+ lake :0x000F ,
252+ tree1 :0x03E0 , tree2 :0 , tree3 :0x59E0 ,
253+ cloud1 :0x7BEF , cloud2 :1
255254 } ;
256255 //day-lightning
257256 if ( data . code >= 200 && data . code < 300 ) a . ltn = 0xFFFF ;
@@ -263,12 +262,12 @@ function setWeather() {
263262 else {
264263 //night-overcast
265264 a = {
266- bg1 :0 , bg2 :0x0005 ,
267- path :0 ,
268- mtn1 :0x0010 , mtn2 :0x000F ,
269- lake :0x000F ,
270- tree1 :0x0200 , tree2 :0 , tree3 :0x59E0 ,
271- cloud1 :0x4208 , cloud2 :1
265+ bg1 :0 , bg2 :0x0005 ,
266+ path :0 ,
267+ mtn1 :0x0010 , mtn2 :0x000F ,
268+ lake :0x000F ,
269+ tree1 :0x0200 , tree2 :0 , tree3 :0x59E0 ,
270+ cloud1 :0x4208 , cloud2 :1
272271 } ;
273272 //night-lightning
274273 if ( data . code >= 200 && data . code < 300 ) a . ltn = 0xFFFF ;
@@ -282,50 +281,50 @@ function setWeather() {
282281 if ( new Date ( ) . getHours ( ) >= 7 && new Date ( ) . getHours ( ) <= 19 ) {
283282 //day-fog
284283 a = {
285- bg1 :0xC618 , bg2 :0x0200 ,
286- path :0x3000 ,
287- mtn1 :0x3B38 , mtn2 :0x0005 ,
288- lake :0x000F ,
289- tree1 :0x03E0 , tree2 :0 , tree3 :0x59E0 ,
290- fog :0xFFFF
284+ bg1 :0xC618 , bg2 :0x0200 ,
285+ path :0x3000 ,
286+ mtn1 :0x3B38 , mtn2 :0x0005 ,
287+ lake :0x000F ,
288+ tree1 :0x03E0 , tree2 :0 , tree3 :0x59E0 ,
289+ fog :0xFFFF
291290 } ;
292291 }
293292 else {
294293 //night-fog
295294 a = {
296- bg1 :0 , bg2 :0x0005 ,
297- path :0 ,
298- mtn1 :0x0010 , mtn2 :0x000F ,
299- lake :0x000F ,
300- tree1 :0x0200 , tree2 :0 , tree3 :0x59E0 ,
301- fog :0x7BEF
295+ bg1 :0 , bg2 :0x0005 ,
296+ path :0 ,
297+ mtn1 :0x0010 , mtn2 :0x000F ,
298+ lake :0x000F ,
299+ tree1 :0x0200 , tree2 :0 , tree3 :0x59E0 ,
300+ fog :0x7BEF
302301 } ;
303302 }
304303 }
305304 else if ( ( data . code >= 600 ) && ( data . code < 700 ) ) {
306305 if ( new Date ( ) . getHours ( ) >= 7 && new Date ( ) . getHours ( ) <= 19 ) {
307306 //day-snow
308307 a = {
309- bg1 :0 , bg2 :0x7BEF ,
310- path :0xC618 ,
311- mtn1 :0xFFFF , mtn2 :0x7BEF ,
312- lake :0x07FF ,
313- tree1 :0xC618 , tree2 :0xC618 , tree3 :0x59E0 ,
314- cloud1 :0x7BEF , cloud2 :1 ,
315- snow :0xFFFF ,
316- clock : 0
308+ bg1 :0 , bg2 :0x7BEF ,
309+ path :0xC618 ,
310+ mtn1 :0xFFFF , mtn2 :0x7BEF ,
311+ lake :0x07FF ,
312+ tree1 :0xC618 , tree2 :0xC618 , tree3 :0x59E0 ,
313+ cloud1 :0x7BEF , cloud2 :1 ,
314+ snow :0xFFFF ,
315+ clock : 0
317316 } ;
318317 }
319318 else {
320319 //night-snow
321320 a = {
322- bg1 :0 , bg2 :0x0005 ,
323- path :0 ,
324- mtn1 :0x0010 , mtn2 :0x000F ,
325- lake :0x000F ,
326- tree1 :0x39E7 , tree2 :0x39E7 , tree3 :0x59E0 ,
327- cloud1 :0x4208 , cloud2 :1 ,
328- snow :0xFFFF
321+ bg1 :0 , bg2 :0x0005 ,
322+ path :0 ,
323+ mtn1 :0x0010 , mtn2 :0x000F ,
324+ lake :0x000F ,
325+ tree1 :0x39E7 , tree2 :0x39E7 , tree3 :0x59E0 ,
326+ cloud1 :0x4208 , cloud2 :1 ,
327+ snow :0xFFFF
329328 } ;
330329 }
331330 }
0 commit comments