All posts by MattK
Making Context Free Art
If you are reading this post in your feed reader, you’ll want to click through to my actual website. Trust me on this one.
I was really impressed with Aza Raskin’s ContextFree.js experiment. I like how the simple rules of a context free art piece generate complex forms. See below, that text will turn into something I can’t exactly predict.
I’ve added a few comments to help you understand what’s going on there.
//all context free art starts with a single rule. Ours will start with a rule named face.
startshape FACE
//and here is the rule FACE
rule FACE{
//a FACE rule means that we should draw the rules EYE MOUTH and HEAD.
EYE{}
// flip an eye over to the other side of the face.
EYE{flip 90}
MOUTH{}
HEAD{}
}
//OH NO! We have two rules named HEAD. Context free will randomly pick one
rule HEAD{ CIRCLE{}}
rule HEAD{ SQUARE{}}
rule EYE{CIRCLE { s .1 b .5 y .12 x .3}}
rule EYE {SQUARE { s .1 b .5 y .12 x .3}}
rule EYE {SQUARE { s .1 b .5 y .12 x .3 r 45}}
rule EYE {TRIANGLE { s .1 b .5 y .12 x .3}}
rule EYE {TRIANGLE { s .1 b .5 y .12 x .3 r 60}}
rule MOUTH {SQUARE{ s .8 .1 y -.12 b .5}}
And here is a randomly generated face, all made up of squares, circles, and triangles:
Want more faces? Go mess about with my face generator on Aza’s demo site.
update: in the comments Chris came up with a bunch of great mouths for an even better face generator!
The art is context free because any rule can be executed without knowing the context of the other rules – they are side-effect free. (these are the kind of problems that work well on lots of processors)
It gets much better. If you are using a modern browser, you’ll see that the heading of my website now is using this to generate random art up there in that previously wasted space.
Reload the website, you’ll see different art generated according to a handful of tiny algorithms.
Recent Nerdery
- I drew my whole apartment on google sketchup in order to settle a discussion with my partner Sam over where we should move some chairs and tables. Sadly, it did not help.
- Due to a nasty twitter post, I had to write up rot13 in ruby – which is of course hot.
#ruby on rot13 class String def rot13 self.tr("A-Ma-mN-Zn-z", "N-Zn-zA-Ma-m") end end "Damn you @genmon !".rot13Â # => Qnza lbh @trazba !
Two stories about light and information
When I was younger I saw small haloish ripples around some shadows. I thought I had magic powers, that I could see auras. I believed I had this secret power for quite some time. While reading a moving presentation by Matt Web about ancient Patagonian communication (it’s sort of heartbreaking), I learned what it was. I was seeing the resolution problems of my eye. In shadows, you can see the very resolution limits of light information itself. How fascinating that you can see these physical limits of the universe in action.
One footnote of his led me to go read and eventually write about the story of the first telegraph network, which was completely human powered. I’ve put up a little something for you about Claude Chappe’s Optical Telegraph, and I’d appreciate any feedback you’ve got on it.
Books: Anathem by Neal Stephenson
I finished the book and put up a longer review of Anathem
When I got home from going San Francisco and the Caymans this Sunday I had a pleasant surprise. I had a nice advanced reader’s copy of “Anathem”, the upcoming novel by Neal Stephenson*. I’d heard reports that it was either post-apocalyptic or a space opera, but neither seems an apt description 100 pages in. So far it seems to be another new genre: Long Now Fiction. You’ve got a monastic (“mathic”) order where different sects sequester themselves away from the ever changing world outside for periods of a year, a decade, a century or a millennium.
There’s an awful lot of worldbuilding words to keep track of, which is a bit annoying, and it is starting off slow. That’s fine, though. Stephenson’s books generally don’t move like other books that have a slow rising action to a climax. Stephenson’s books tend to be first immersion in a world for a few 100 pages, then a radical spiraling climax that is vertically asymptotic against the presence of the end of the book. It’ll get exciting soon enough.
The book isn’t due out till September 30th, and assuming that I’ll finish the massive thing by then, do let me know if you’d like it next.
*Apparently I’m quite the lucky duck. I got this through the LibraryThing Early Reviewers program and was one of the 25 recipients out of the 1375 requesters.Â
It’s all details
They say the devil is in the details. Sometimes subtle details are a place to shine.
I was reading notes on a lecture by the great Joshua Schachter, developer of Del.icio.us, when I was thunderstruck by a detail.
You have to speak the user’s language. “Bookmarks” are what you call them if
you use Netscape of Firefox – most users these days know the term “favourite”
instead. Half of his population (? users) didn’t know what a bookmark was.
The beauty of Ruby’s array subtraction operator
Today I had to a set of email addresses, one per line, from which I had to remove the addresses of folks that said “Don’t email me.” Those emails were in a separate file, one address per line.
I figured I’d have to do this again, so I wrote a ruby script to automate it. Below, stripper.rb
#put each address in an array, remove whitespace and make it all lowercase potential_emails = IO.readlines("potentials.txt").map! {|email| email.strip.downcase} delete_emails = IO.readlines("donotemail.txt").map! {|email| email.strip.downcase} #use the beauty of ruby's array subtraction operator puts potential_emails - delete_emails
Simple, terse and readable. Lovely!
links for 2008-05-30
-
The Only BookMarklet You’ll Ever Need!
Efficient – Fast – Easy – Secure – Free
sends to a crapload of other services… -
two secret drawers, one of which includes a give-up red herrring drawer.
How to install Add-Art
Steve Lambert put up a nice helpful walkthrough video on Add-Art, the project I’ve been working on recently. Take a mo’ and check out the project and the video.
Introduction to Add-Art from Steve Lambert on Vimeo.
links for 2008-05-27
-
German article on add-art!

