Activate your free membership today | Log-in

Tuesday, June 16th, 2009

Doodle: Sprite library for Canvas

Category: Canvas

<>p>Billy Lamberta got tired having to get so low-level as you do with the raw Canvas API. So, he create a small abstraction layer:

Doodle.js attempts to create a fun and easy way to interact with the Canvas that is lightweight, flexible, and functional. While it contains a few shape primitives it is not meant to be a full-fledged drawing api, rather a framework that allows you to build sprites and interact with them in an expressive way.

He gives plenty examples, but here is one that animates the spiral that you see:

JAVASCRIPT:
  1.  
  2.  var r = 5;
  3.  var a = 0;
  4.  var frame = 0;
  5.  
  6.  dot.loop(function(obj) {
  7.               obj.modify({x:circle_x(a),
  8.                           y:circle_y(a),
  9.                           fill:random_color() });
  10.  
  11.               frame += 1; //update frame count
  12.               a += 10; //update angle rotation
  13.               r += 0.3; //update radius
  14.  
  15.               if(a % 15 == 0){ dot.fill = '#000000'; }
  16.               else{ dot.fill = random_color(); }
  17.  
  18.               //clear canvas every 800th frame, reset radius
  19.               if(frame % 800==0){oo.canvas().clear(); r = 5;}
  20.  
  21.           }, 0, '48fps'); //loop indefinitely at 48 frames/sec
  22.  

Best part of the framework? How he choose the "oo" convention for the main object:

The “oo” variable was picked because it’s easy to type, easy to remember (d-oo-dle), and easy for our eyes to parse when we look over the code (it only takes a very cursory knowledge of male psychology to understand that).

I was actually surprised that I hadn't already posted on this... or CAKE which I will mention next...

Related Content:

  • DOO
    Image...
  • SP3
    Quake2 pcx 32-bit sprite builder file (for use with...
  • sprite
    A sprite is a fairy or an...
  • DOO
    Atari Doodle ( Atari...
  • DirectX
    DirectX is an application program interface (API) for creating and managing graphic images and multimedia effects in applications such as games or...

Posted by Dion Almaer at 5:36 am
2 Comments

++++-
4.1 rating from 29 votes

2 Comments »

Comments feed TrackBack URI

Impressive :)

Comment by Darkimmortal — June 16, 2009

There is no mention of support for Safari. Why is that?

Comment by HG — June 18, 2009

Leave a comment

You must be logged in to post a comment.