-
Creative coding in sqlite
Been trying out creative coding in sqlite recently here. Turned out to be a lot more fun than what writing practical SQL had conditioned me to believe!
Generating images is pretty straight forward. The SQL uses recursive CTE to generate and store pixel rgb values in the db. Then a bash script reads the pixel values structures them in the ppm text format which is then converted to png using imagemagick. I was thinking of taking this a step further by converting to ppm from within sql but didn't feel like that added much except boilerplate.
Currently I've got 2 scripts image.sh and video.sh to generate images and videos respectively.
- image.sh: Generates a ppm from the pixels stored in the db. Uses imagemagick to convert that to a png (and also for displaying it)
- video.sh: Generates a ppm stream for each stored frame of the video. Uses ffmpeg to convert that to a gif (and uses ffplay for displaying it)
Here's a simplified example that generates 400x400 grid of pixels with a circle in the middle:
WITH RECURSIVE image(width, height, cx, cy, radius) AS (SELECT 400 AS width, 400 AS height, 200 AS cx, 200 AS cy, 160 AS radius), horizontal(x) AS (SELECT width FROM image UNION ALL SELECT x - 1 FROM horizontal WHERE x > 1), vertical(y) AS (SELECT height FROM image UNION ALL SELECT y - 1 FROM vertical WHERE y > 1) SELECT x, y, 255 * MAX(0, MIN(1, (x - cx)*(x - cx) + (y - cy)*(y - cy) - radius*radius)), 150, 150 FROM vertical, horizontal, image;Here,
horizontal/verticalgenerates x and y coordinates, the final select assigns the r,g,b values for each x,y coordinate which is what allows generating the visuals.In the repo, I'm storing the pixels instead of generating just generating them directly. I went with this approach for 2 reasons - debugging and reducing the pain of generating a video. Although, could've used materialized views but nah simpler is better.
Generating audio out of samples should also be simple with raw PCM data and then to ffmpeg to convert to wav but haven't tried that yet. Another more ambitious idea is to build a simple snake game. The way I'm thinking is with the ppm output streaming to ffplay and using terminal raw mode for input which will update relevant values either directly or via triggers. Leaving that for future me to fuck around with.
SQL can be fun.
2026-06-03 -
Desmos is beautiful
Desmos is a graphing calculator where you can input math equations and it'll plot it. The normal way to use it would be to throw in an equation like y = 2x2 + 2 and boom you have a parabola. Even though it might seem simple on the surface, it is hiding an incredible programming language and rendering engine that you can use to build pretty much anything you'd like.
Want to draw a box and a circle? {−5 < x < 5}{−5 < y < 5} > 0 x2 + y2 < 25
Here, the comparisons at the top level means region (or range in general) and conditional enclosed in curly braves like {−5 < x < 5 > 0} are expressions that can either return 1 if true or undefined if false. 2 of these expressions next to each other is the product of both.
Want to conditionally draw either a box or a circle and toggle between them on the click of a button? (on desmos) {Viscircle = 1 : −x2 − y2 + 25, {−5 < x < 5 > 0}{−5 < y < 5}} > 0 Viscircle = 0 Viscircle → {Viscircle = 0 : 1, 0}
Here, if you click the arrow button to the left of the last equation, it will update/toggle Viscircle. An expression like {x > 0 : 42, 7} is a conditional expression but instead of 1 or undefined, it will return 42 when true and 7 when false (i.e. if expression). Also, Viscircle → {Viscircle = 0 : 1, 0} means when the action is triggered (button is clicked or via timer), it will update the value which in this case would toggle between 0 and 1.
The action can also be connected to any object drawn on screen by clicking the cog in the sidebar, clicking on the icon to the left of the equation for the object and then enabling "Clickable".
You could also have that action be triggered every second (or whatever interval) using the ticker feature in desmos (+ button in the sidebar > Ticker).
This post doesn't even begin to cover the incredible features desmos provides but I think the fun is in exploring so if you find desmos interesting, it's better to discover those yourself.
Here's a snake game implemented in desmos. Press "Play/Pause" to start.
I maintain my collection of desmos experiments here.
2026-03-24 -
Uiua
Uiua is one of the most fun languages for creative coding. There are a bunch of really good primitives for generating audio files from samples, generating an image from an array of pixels, generating a gif from an array of array of pixels, etc. Messed around with it here some time ago and I've started to miss it. The only other APL-ish language I've tried is BQN which is also an amazing language but thinking tacit is hard and it takes time to get used to. There are smart people in the world. Being a member and representative of the other side of that spectrum, I need my escape hatches and they need to be pleasant. I've come to appreciate the stack-based escape hatches a lot more than the functional escape hatches with blocks using 𝕩 and the other spicy letters.
2026-03-22