Skip to content

ara pehlivanian

Web Standards, Web Culture, Web Everything.™

Playing with Canvas: Starfields in Firefox

I’ve been itching to play with Canvas for a while now and tonight I finally had the time and energy to actually do something with it*.

Granted it’s very basic in terms of what Canvas can do, but I’ve been in love with starfields ever since I coded my first one years ago in Quick Basic and I’ve been dying to do one in JavaScript for a long time now. Canvas gave me the opportunity to generate and move real pixels around–instead of DOM elements!

For those of you who want to pick the code apart, note the easy instantiation of the Starfield class. With literally 3 lines of code you can add another starfield to the page. :-)

* In case you didn’t catch it in the post title, this only works in Safari and recent Gecko based browsers like Firefox and Opera.

Sphere: Related Content

  • Comments closed

Buy my book

The Art & Science of JavaScript / SitePoint
The Art & Science of JavaScript

Advertisement

Firebug - Web Development Evolved

Advertisement

5 Comments

  1. Gravatar for LukeLuke says:

    Pretty cool. It’s amazing what you can really do with Canvas. Did you see this yet:

    http://www.abrahamjoffe.com.au/ben/canvascape/

  2. Gravatar for Ara PehlivanianAra Pehlivanian says:

    Luke: Yeah, I’d seen it before. That’s what got me interested in Canvas in the first place, though I hadn’t caught his use of the “Google workaround for IE”. I’ll have to look into that. :-)

  3. Gravatar for Nathan SmithNathan Smith says:

    Very cool. One minor typo though: You have Safari listed as a Gecko-based browser, which it isn’t.

  4. Gravatar for Ara PehlivanianAra Pehlivanian says:

    Nathan: You’re right, I thought it sounded odd. It seems I misread the line in the Canvas tutorial. I mixed it up because it talks about how Apple first introduced it for the OSX dashboard then put it in Safari, and it was also adopted by Gecko 1.8 browsers. My bad. I’ll go fix it now. :-)

  5. Gravatar for LukeLuke says:

    Actually, I don’t think Opera is gecko based either.

    Opera can pass the ACID2 test, while FF and Moz fail it miserably. So they must have different rendering engines under the hood.

Sorry, the comment form is closed at this time.

Skip to navigation

More stuff by Ara elsewhere on the web

    Snook Approved!

    © 2005-2008, Ara Pehlivanian.

    Stock photography courtesy stock.xchng. This site uses Akismet to catch spam (54,754 caught since May 2006) is hosted by DreamHost and powered by WordPress.