-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcreate-images.ts
49 lines (38 loc) · 1.14 KB
/
create-images.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
import { createCanvas } from "canvas"
import sketches from "./src/examples/sketches"
import { SCanvas } from "./src/lib"
import fs from "fs"
const width = 900
const height = 600
Object.entries(sketches).forEach(([category, { sketches }]) => {
sketches.forEach(({ sketch, name }) => {
const canvas = createCanvas(width, height)
const ctx = canvas.getContext("2d")
const sC = new SCanvas(
// supports all the basics but not fully as per modern HTML canvas
ctx as unknown as CanvasRenderingContext2D,
{
width,
height,
},
42,
0
)
sketch(sC)
const stream = canvas.createPNGStream()
const out = fs.createWriteStream(
`./samples/${name.replaceAll(/[^A-z0-9]/g, "-")}.png`
)
stream.pipe(out)
out.on("finish", () => console.log(`Done: ${name}`))
})
})
let md = "# Sketches\n\n"
Object.entries(sketches).forEach(([category, { sketches }]) => {
md += `## ${category}\n\n`
sketches.forEach(({ name }) => {
md += `### ${name}\n\n`
md += `![${name}](./${name.replaceAll(/[^A-z0-9]/g, "-")}.png)\n\n`
})
})
fs.writeFileSync("./samples/samples.md", md)