Kyle Perik 9 months ago
parent
commit
ec386418ad
2 changed files with 17 additions and 8 deletions
  1. 1 0
      index.html
  2. 16 8
      index.js

+ 1 - 0
index.html

@@ -1,6 +1,7 @@
1 1
 <html>
2 2
     <head>
3 3
         <meta name="viewport" content="width=device-width, initial-scale=1">
4
+		<title>Skysim</title>
4 5
     </head>
5 6
     <body style="margin: 0; overflow: hidden;">
6 7
         <canvas id="pixelCanvas" width="800" height="800"></canvas>

+ 16 - 8
index.js

@@ -138,7 +138,7 @@ function getcolorat(x, y, percentday, width, height, isstar) {
138 138
     	    Math.pow(light, 1/100)
139 139
     	) : nightcolor,
140 140
         skyColor,
141
-        Math.min(1, Math.max(0, light - 0.002) * 20)
141
+        Math.min(1, Math.max(0, light - 0.05) * 20)
142 142
     );
143 143
     return sun || colorMix(sky, sunshineColor, sunshine);
144 144
 }
@@ -162,7 +162,7 @@ function drawRain(particles, wind, isSnow, amount) {
162 162
             p.x, p.y,
163 163
             p.x + (isSnow ? 1 : p.speed * wind * length),
164 164
             p.y + (isSnow ? 1 : p.speed * gravity * length),
165
-            isSnow ? 'rgba(230, 230, 230, .7)' : 'rgba(150, 150, 150, .2)', pixelCanvas
165
+            isSnow ? 'rgba(255, 255, 255, 1)' : 'rgba(150, 150, 150, .2)', pixelCanvas
166 166
         );
167 167
     });
168 168
     var size = getSize(pixelCanvas);
@@ -192,7 +192,7 @@ function drawClouds(clouds, wind, amount, cloud_color) {
192 192
         x => [...Array(canvasSize.y).keys()].map(y => {
193 193
             var meta = Math.pow(sum(clouds.map(c => c.size / (Math.pow(x - c.x, 2) + Math.pow(y - c.y, 2)))), 2);
194 194
             //if (meta < 0.8) return;
195
-            var color = cloud_color.slice().concat([Math.min(1, meta) * .75]);
195
+            var color = cloud_color.slice().concat([Math.min(1, meta * .1) * .75]);
196 196
             drawRect(
197 197
                 x, y,
198 198
                 1, 1,
@@ -204,7 +204,7 @@ function drawClouds(clouds, wind, amount, cloud_color) {
204 204
     var averagePoint = {x: mean(clouds.map(c => c.x)), y: mean(clouds.map(c => c.y))};
205 205
     return clouds.map(c => ({
206 206
         ...c,
207
-        x: c.x + wind / 8,// - (c.x - averagePoint.x) / 1000,
207
+        x: c.x + wind,// - (c.x - averagePoint.x) / 1000,
208 208
         y: c.y,// - (c.y - averagePoint.y) / 1000,
209 209
         size: c.size + (Math.random() - .5) / 10,
210 210
     })).concat(fillInClouds(
@@ -240,7 +240,7 @@ function draw(s) {
240 240
             [20, 20, 40], .5
241 241
         ),
242 242
         [240, 240, 240],
243
-        Math.max(0, Math.min(1, (light - 0.002) * 20))
243
+        Math.max(0, Math.min(1, (light - 0.05) * 20))
244 244
     );
245 245
     var overcast_color = raw_overcast_color.concat([Math.pow(s.weather.clouds.all / 100, 2)]);
246 246
     drawRect(0, 0, canvasSize.x, canvasSize.y, rgbatostr(overcast_color), pixelCanvas);
@@ -253,6 +253,12 @@ function draw(s) {
253 253
         canvas.width,
254 254
         canvas.height
255 255
     );
256
+    var dataURI = pixelCanvas.ctx.canvas.toDataURL();
257
+    var link = document.querySelector("link[rel*='icon']") || document.createElement('link');
258
+	    link.type = 'image/x-icon';
259
+	    link.rel = 'shortcut icon';
260
+	    link.href = dataURI;
261
+    document.getElementsByTagName('head')[0].appendChild(link);
256 262
 }
257 263
 
258 264
 
@@ -288,8 +294,8 @@ getLatLong().then(
288 294
             ))
289 295
             : []
290 296
         )
291
-        draw(state);
292 297
         pixelCanvas.ctx.save();
298
+        draw(state);
293 299
         setInterval(() => {
294 300
             getWeather(state.coords).then(w => state.weather = w);
295 301
             draw(state);
@@ -327,12 +333,14 @@ function onresize() {
327 333
             Math.random() * size.x * size.y
328 334
         )
329 335
     );
330
-    draw(state);
331 336
 }
332 337
 
333 338
 
334 339
 var resizeTimeout;
335 340
 window.addEventListener('resize', () => {
336 341
     clearTimeout(resizeTimeout);
337
-    resizeTimeout = setTimeout(onresize, 100);
342
+    resizeTimeout = setTimeout(() => {
343
+	    onresize();
344
+	    draw(state);
345
+	}, 100);
338 346
 });