Multiple skies
This commit is contained in:
1 parent
7f2c532d37
commit
abfb7a20bc
4 files changed
+23
-6
No files matched your search
@@ -13,6 +13,15 @@ export const PLAYER_COLORS = [
|
|||||||
'darkorchid',
|
'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 MAX_WIND = 25;
|
||||||
|
|
||||||
export const PLAYER_MAX_ENERGY = 100;
|
export const PLAYER_MAX_ENERGY = 100;
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ export function coords2index(width, x, y) {
|
|||||||
return y * width + x;
|
return y * width + x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function gradient(from, to, i) {
|
||||||
|
return from + (to-from) * i;
|
||||||
|
}
|
||||||
|
|
||||||
export function random(min, max) {
|
export function random(min, max) {
|
||||||
return min + Math.random() * (max-min);
|
return min + Math.random() * (max-min);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import {createCanvas, drawRect, clipCanvas, plot} from './gfx.js';
|
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) {
|
export function createSky(width, height) {
|
||||||
const ctx = createCanvas(width, height);
|
const ctx = createCanvas(width, height);
|
||||||
@@ -9,11 +11,13 @@ export function createSky(width, height) {
|
|||||||
|
|
||||||
export function generateSky(ctx) {
|
export function generateSky(ctx) {
|
||||||
const {width, height} = ctx.canvas;
|
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++) {
|
for (let y=0; y<height; y++) {
|
||||||
const darken = 1 - (1/height*y);
|
const f = y / height;
|
||||||
const [dr, dg, db] = [r*darken, g*darken, b*darken];
|
const r = gradient(from[0], to[0], f);
|
||||||
drawRect(ctx, 0, y, width, 1, `rgb(${dr},${dg},${db})`);
|
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})`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -39,7 +39,7 @@ const TERRAIN_TYPES = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
sand(ctx) {
|
sand(ctx) {
|
||||||
ctx.color = 'burlywood'; // FIXME
|
ctx.color = 'wheat';
|
||||||
const {width, height} = ctx.canvas;
|
const {width, height} = ctx.canvas;
|
||||||
const stepCount = 16;
|
const stepCount = 16;
|
||||||
const stepSize = width / stepCount;
|
const stepSize = width / stepCount;
|
||||||
|
|||||||
Reference in new issue
Block a user