February 19, 2017
About 1 minute
Visualization Hacks STEM

Confinity

An ode to the display hack

Contents

Over the years I’ve written a number of small apps to help people understand how different algorithms work. I’ve gotten a lot of positive feedback about them from students and teachers, and a few have been featured in magazines or books. So I thought it would be worthwhile to port at least some of these to the Web. To kick the project off, though, I’ve decided to do something more fun than functional.

Part of the magic that draws people into programming is the incredible complexity and beauty that can result from taking a few simple instructions and letting them run wild. The most immediate and tangible form of this magic is the “display hack,” a small program that makes pretty pictures. Display hacks are so vital to computing culture that even A.K. Dewdney’s classic tour of computing science, The Turing Omnibus,1 starts with one. I’m going to recreate it here, with one small modification: while the original produced two-colour images, this version allows a variable number. Here’s the pseudocode:

for i := 1 to imageWidth
for j := 1 to imageHeight
x := originX + i × sideLength / imageWidth
y := originY + j × sideLength / imageHeight
c := floor(+) mod numberOfColours
plot(i, j, colour[c])
end for
end for

The hack

And now, here’s the live version. Changing the values for the side length, origin, or number of colours will produce different pictures. To reproduce Dewdney’s original black-and-white version, set the number of colours to 2.

Bibliography

  1. A.K. Dewdney, The New Turing Omnibus: 66 Excursions in Computer Science. W H Freeman & Co; Revised edition (1993). ↩︎

Have a comment or correction? Let me know! I don’t use an automated comment system on this site, but I do appreciate feedback and I update pages accordingly.