From abfb7a20bcba3594e0c4fd722332383cf8ac17f4 Mon Sep 17 00:00:00 2001 From: zenoamaro Date: Sun, 30 Jun 2019 02:56:18 +0200 Subject: [PATCH] Multiple skies --- constants.js | 9 +++++++++ math.js | 4 ++++ sky.js | 14 +++++++++----- terrain.js | 2 +- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/constants.js b/constants.js index 990c284..9398b1c 100644 --- a/constants.js +++ b/constants.js @@ -13,6 +13,15 @@ export const PLAYER_COLORS = [ 'darkorchid', ]; +export const SKY_COLORS = [ + {from:[42, 78, 108], to:[0, 0, 0]}, + {from:[82, 120, 187], to:[201, 218, 236]}, + {from:[94, 171, 184], to:[225, 172, 139]}, + {from:[49, 76, 148], to:[242, 171, 85]}, + {from:[51, 89, 135], to:[163, 198, 220]}, + {from:[105, 95, 108], to:[223, 183, 110]}, +]; + export const MAX_WIND = 25; export const PLAYER_MAX_ENERGY = 100; diff --git a/math.js b/math.js index 5c91d7d..1737db2 100644 --- a/math.js +++ b/math.js @@ -11,6 +11,10 @@ export function coords2index(width, x, y) { return y * width + x; } +export function gradient(from, to, i) { + return from + (to-from) * i; +} + export function random(min, max) { return min + Math.random() * (max-min); } diff --git a/sky.js b/sky.js index fc61024..c9a259f 100644 --- a/sky.js +++ b/sky.js @@ -1,5 +1,7 @@ import {createCanvas, drawRect, clipCanvas, plot} from './gfx.js'; -import {randomInt} from './math.js'; +import {randomInt, gradient} from './math.js'; +import {SKY_COLORS} from './constants.js'; +import {sample} from './utils.js'; export function createSky(width, height) { const ctx = createCanvas(width, height); @@ -9,11 +11,13 @@ export function createSky(width, height) { export function generateSky(ctx) { const {width, height} = ctx.canvas; - const [r, g, b] = [70*0.6, 130*0.6, 180*0.6]; + const {from, to} = sample(SKY_COLORS); for (let y=0; y