Canto.js: An Improved Canvas API

In: web resources

29 Jul 2010

Javascript author extraordinaire David Flanagan released Canto.js recently, a lightweight wrapper API for canvas, introduced here and documented at the top of the source code. Example:

JAVASCRIPT:

canto(“canvas_id”).moveTo(100,100).lineTo(200,200,100,200).closePath().stroke();
 

Notice three things:

  • canto() returns an abstraction of the canvas – a “Canto” object.
  • As with jQuery and similar libraries, there’s method chaining; each method called on a Canto also returns the Canto.
  • lineTo() has been extended to support multiple lines being drawn in a single call.

Instead of setting the ink properties and then painting it, you can do it all in one step:

JAVASCRIPT:

canto(“canvas_id”).moveTo(100,100).lineTo(200,200,100,200).closePath().stroke({lineWidth: 15, strokeStyle: “red”});
 

And plenty more syntactic sugar – check out the API in the source code comments. Sweet!

Thanks @pkeane.

Go to Source

2 Responses to Canto.js: An Improved Canvas API

Avatar

Daniel K

July 30th, 2010 at 7:01 am

Yes I agree with Daniel K, Linkvana works well but you need to post unique and worthwhile articles to get backlinks.

Avatar

superpotatoes

August 12th, 2010 at 7:51 am

The Mortal Instruments Saga by Cassandra Clare. Great Books….

Comment Form

About this blog

This blog delivers stylish and dynamic news for designers and web-developers on all subjects of design, ranging from: CSS, Ajax, Javascript, web design, graphics, typography, advertising & much more. Our goal is to help you communicate effectively on the web with an engaging website or functional interface.