-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.ts
52 lines (45 loc) · 1.7 KB
/
lib.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
43
44
45
46
47
48
49
50
51
52
import { SketchConstructor } from "library/core/sketch"
import { ICanvas, RenderParams } from "library/core/types"
export type { SketchRenderer } from "library/core/renderer"
export { SketchRunner } from "library/core/runner"
export type { ISketch as Sketch } from "library/core/sketch"
export * from "library/core/types"
/** Sketch module definition */
export type SketchModule = {
/** Artwork title */
name: string
/** Artwork year (specifies folder to load sketch from) */
year: number
}
type SketchModuleImpl = {
default: SketchConstructor | Promise<SketchConstructor>
}
// Only finished artworks here
export const sketches = [
{ name: "fireworks", year: 2023 },
{ name: "kiss", year: 2023 },
{ name: "shade", year: 2023 },
{ name: "whirlwind", year: 2022 },
{ name: "waves", year: 2022 },
{ name: "trees", year: 2022 },
{ name: "stars", year: 2022 },
{ name: "squares", year: 2022 },
{ name: "shards", year: 2022 },
{ name: "radiance", year: 2022 },
{ name: "pillars", year: 2022 },
{ name: "curves", year: 2022 },
{ name: "colonize", year: 2022 },
]
/**
* Dynamically load sketch module
* @param module {@link SketchModule} definition
* @returns promise with loaded sketch factory function
*/
export async function loadModule(module: SketchModule): Promise<SketchConstructor> {
const { default: sketch } = (await import(`./sketches/${module.year}/${module.name}.ts`)) as SketchModuleImpl
return sketch
}
export const screensaver = async (canvas: HTMLCanvasElement) =>
(await import("./sketches/2024/screensaver")).default(canvas)
export const initRenderer = async <C extends ICanvas>(params?: Partial<RenderParams<C>>) =>
(await import("./library/core/renderer")).init(params)