diff options
Diffstat (limited to 'sketches/01/script.js')
| -rw-r--r-- | sketches/01/script.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/sketches/01/script.js b/sketches/01/script.js new file mode 100644 index 0000000..9c1eaba --- /dev/null +++ b/sketches/01/script.js @@ -0,0 +1,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))) |
