-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.ts
42 lines (36 loc) · 1.18 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { getColumns, getLines } from "./components/process.ts";
import {
getEmptyScreen,
getDenoEmbeddedScreen,
getRainedDenoScreeen,
} from "./components/screen.ts";
import { generateDrops } from "./components/drop.ts";
const getScreenSizes = async () => {
const lines = await getLines();
const columns = await getColumns();
const characters = lines * columns;
return [lines, columns, characters];
};
async function* render(ratio: number): AsyncGenerator<string> {
let time = new Date().getTime();
let [lines, columns, characters] = await getScreenSizes();
const drops = generateDrops(lines, columns, Math.floor(characters * ratio));
while (true) {
const now = new Date().getTime();
if (now - time >= 1000) {
[lines, columns, characters] = await getScreenSizes();
time = now;
}
const screen = getEmptyScreen(lines, columns);
const denoEmbeddedScreen = getDenoEmbeddedScreen(lines, columns, screen);
const rainedDenoScreen = getRainedDenoScreeen(
lines,
columns,
denoEmbeddedScreen,
drops
);
for (const drop of drops) drop.move(lines, columns);
yield rainedDenoScreen.join("\n");
}
}
export { render };