From the great book, Maintainable JavaScript.
Category: Programming
JavaScript perversities
Just looking at Douglas Crockford’s “JavaScript: The Good Parts” once again. One of the definitely Not Good parts is the NaN
value, supposedly standing for “Not a Number”.
Given that, what would you expect from typeof NaN
? Probably not 'number'
.
Even better:
NaN === NaN
gives false
NaN !== NaN
gives true
NaN
is not equal to itself!
And best of all, for some reason NaN
isn’t a constant, but a global variable. So if you want to change it to something else (e.g. NaN = 'fishcake'
) you can. Anyone who does should probably be shot, but the fact that it can be done at all is baffling.
Now the fireworks in me are all gone
I’ve been playing with Flash some more, and have made the leap to pure AS3. I’m using FlashDevelop, which is a really great IDE – far better than Flash CS3 itself for writing code. It’s amazing what a difference a good editor can make.
Anyway this is what I came up with, a bit of a rehash of some old Blitz Basic demos I did long ago. Click to launch fireworks
Fireworks.swf
Now I’m trying to learn flixel, a free AS3 framework designed for games. I’ve already made one basic platform game following a tutorial, and am now working on my own.
A Rorschach Test on fire
After much battling with ActionScript, this is the latest version of my Mandelbrot generator. Yes, it has skipped a few version numbers. New features:
- Rough rendering first, followed by a better quality one
- Various optimisations
- Information panel
- Actually being able to get back out again, without reloading the flash
- Doesn’t resize stupidly
- Just generally cleaner code
Hooray!
mandelbrot 5.swf
A day-glo pterodactyl
My Mandelbrot flash, now with (one-way) zooming. Click on a region to zoom in.
And while checking the lyrics to Mandelbrot Set for the title of this post, I found there is a Jonathan Coulton wiki! Sweet! Their article also confirmed my suspicion that the algorithm described in the song isn’t actually correct, it instead describes the production of a Julia set. Those are great though, and will probably be my next fractal project.
A heart-shaped box of springs and wire
I’ve used Flash a fair bit before, but never made the jump from ActionScript 2 to AS3. It’s quite a big change, and since I’m so used to programming in the very forgiving Python, it seems really fussy. But my god it’s fast! Anyway I’ve always wanted to make a Mandelbrot generator, even back when I was programming in BASIC and really didn’t have the skill. So here we go:
mandelbrot.swf (Ignore the pixelation, it’s just being displayed at the wrong size.)
I’m really quite pleased with this as I had to learn quite a few new techniques. Obviously it’s rather static, I still need to add moving/zooming but that shouldn’t be too hard now. The colouring could use some variation too.
Also, using song lyrics for post titles seems to have unintentionally become a theme, so I’m going to run with it. :)