aboutsummaryrefslogtreecommitdiff
path: root/sketches/week-1/script.js
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2023-10-29 16:09:56 +0530
committerAkshay Nair <phenax5@gmail.com>2023-10-29 16:09:56 +0530
commitb6ebba87606d180735994d62e2d71c3fbf0b8763 (patch)
tree3aa0ff77d8d3c569be285e911e9ed44f10777b50 /sketches/week-1/script.js
parent95eae658a4845f86e1b6b2c16387a41dd36f9d42 (diff)
downloadcreative-coding-playground-b6ebba87606d180735994d62e2d71c3fbf0b8763.tar.gz
creative-coding-playground-b6ebba87606d180735994d62e2d71c3fbf0b8763.zip
feat: week 1 sort-of done? but not really
Diffstat (limited to 'sketches/week-1/script.js')
-rw-r--r--sketches/week-1/script.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/sketches/week-1/script.js b/sketches/week-1/script.js
new file mode 100644
index 0000000..9c1eaba
--- /dev/null
+++ b/sketches/week-1/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)))