blob: 9c1eaba00be20d556c6e32b7ab782a164fba5da8 (
plain) (
blame)
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
|
const program = (url) =>
fetch(url)
.then((f) => f.text())
.then(bqn)
const setupCanvas = (width, height) => {
const $canvas = Object.assign(document.createElement('canvas'), { width, height })
const ctx = $canvas.getContext('2d')
$canvas.parentNode || document.body.appendChild($canvas)
return ctx
}
const start = async () => {
console.dir(bqn)
sysvals.show = (x) => debug(x)
const getPoints = await program('./mandelbrot.bqn')
const ctx = setupCanvas(200, 200)
const points = getPoints(list([ctx.canvas.width, ctx.canvas.height]))
// console.log(points)
// debug(points)
const imageDataRaw = points.flatMap((x) => (x.length === 4 ? x : [...x, 255]))
const imageData = new ImageData(
new Uint8ClampedArray(imageDataRaw),
ctx.canvas.width,
ctx.canvas.height
)
ctx.putImageData(imageData, 0, 0)
console.log('DONE')
}
start().catch((e) => console.log(fmtErr(e)))
|