Fix some diagnostic issues when skipping invalid statements, see #80; Make game-of-life example somewhat interactive; Update dist files

This commit is contained in:
dcodeIO
2018-04-22 23:13:02 +02:00
parent fac0fc59b5
commit 2ff1bb745a
17 changed files with 771 additions and 1770 deletions

View File

@ -1,8 +1,9 @@
// see: https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
const RGB_ALIVE = 0xE692D3; // LSB must be set
const RGB_DEAD = 0x851BA6; // LSB must not be set
const BIT_ROT = 10; // It's everywhere
// Configuration imported from JS.
declare const RGB_ALIVE: u32;
declare const RGB_DEAD: u32;
declare const BIT_ROT: u32;
var w: i32, h: i32, s: i32;
@ -76,3 +77,13 @@ export function step(): void {
}
}
}
/** Fills the row and column indicated by `x` and `y` with random live cells. */
export function fill(x: u32, y: u32, p: f64): void {
for (let ix = 0; ix < w; ++ix) {
if (Math.random() < p) set(ix, y, RGB_ALIVE | 0xff000000);
}
for (let iy = 0; iy < h; ++iy) {
if (Math.random() < p) set(x, iy, RGB_ALIVE | 0xff000000);
}
}