Multiple skies

This commit is contained in:
zenoamaro committed 2019-06-30 02:56:18 +02:00
1 parent 7f2c532d37
commit abfb7a20bc
4 files changed
+23 -6

No files matched your search

+9 -5
View File
@@ -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<height; y++) {
const darken = 1 - (1/height*y);
const [dr, dg, db] = [r*darken, g*darken, b*darken];
drawRect(ctx, 0, y, width, 1, `rgb(${dr},${dg},${db})`);
const f = y / height;
const r = gradient(from[0], to[0], f);
const g = gradient(from[1], to[1], f);
const b = gradient(from[2], to[2], f);
drawRect(ctx, 0, y, width, 1, `rgb(${r},${g},${b})`);
}
}