The Ashes

Technology, Science and other news
June 16, 2009

Doodle: Sprite library for Canvas

Posted by : admin
Filed under : General

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:

PLAIN TEXT
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…

Tags :

No Comments

(required)
(will not be published) (required)
(opitional)

cciash.com EN ES IT DE PT CZ FR RU
October 2018
M T W T F S S
« Sep    
1234567
891011121314
15161718192021
22232425262728
293031  

Pages

Categories

Resources

There are many online poker site where you can play but at poker.hk you can play the poker games with all the knowledge you need related to the game with the poker school available in both the English and Chinese language.

Super Casino

Now you can bet on any sports and any sporting events from all the comfort from your home. Bet770 allows you to bet on any events and match with in just 3 clicks. They also offers great odds on football betting for every premier and champions league match. Get £50 free in bets when you register.

Bingo770, offering best online bingo games with £7.70 free no deposit Bonus!