A lightweight wrapper for RaphaelJS.
Michaelangelo enables you to easily build out cross-browser vector graphics via Raphael that was inspired by the Python module matplotlib.
Currently, Michaelangelo provides abstractions some of the elements you can create in Raphael. The abstraction isn't much currently, but it provides namespacing and the ability to easily scale your graphics.
For the following code samples, I will demonstrate how you might fulfill the same task in Raphael vs. Michaelangelo.
// Vanilla Raphael var Raphael; Raphael = require'raphael'; // Create a 400x400 canvas with a 10x10 rectangle in the top left Raphael'canvas' 400 400 type: 'rect' x: 0 y: 0 width: 10 height: 10 stroke: '#000';
// Raphael with Michaelangelo var Michaelangelo Raphael rectangle; Michaelangelo = require'michaelangelo';Raphael = require'raphael'; rectangle = MichaelangeloRectangle x: 0 y: 0 width: 10 height: 10 stroke: '#000' ; Raphael'canvas' 400 400 rectangletoRaphaelObject;
Ok... I know what you're thinking. More lines of code... Wat?
You're right, but what if we want to scale our rectangle?
// Raphael with Michaelangelo var Michaelangelo Raphael rectangle; Michaelangelo = require'michaelangelo';Raphael = require'raphael'; // Creates a 20x20 rectangle rectangle = x: 0 y: 0 width: 10 height: 10 scale: 2 stroke: '#000' ; Raphael'canvas' 400 400 rectangletoRaphaelObject;
The problem I had is that I wanted to use real measurements, then scale as needed.
Raphael provides means to scale, but you must do so after placing it on the canvas. Prior
to placing it on the canvas, I didn't want to have to deal with the mental load of keeping
track of the scale or litter '... * 2' everywhere.
While these may be syntactic improvements at best, I think some of the real powers of Michaelangelo reside in path building.
var Raphael; Raphael = require'raphael'; Raphael'canvas' 400 400 type: 'path' path: 'M0,0L10,10Z';;
While this is a simple example, it's not entirely intuitive.
var Michaelangelo Raphael path; Michaelangelo = require'michaelangelo';Raphael = require'raphael'; path = x1: 0 y1: 0 x2: 10 y2: 10; Raphael'canvas' 400 400 pathtoRaphaelObject;
To me, this example is much more clear of what we're doing. We have a line with two points, Michaelangelo handles the rest.
Another handy service that Michaelangelo provides is building arcs.
var Michaelangelo Raphael circle ellipse arc; Michaelangelo = require'michaelangelo';Raphael = require'raphael'; // Essentially draws a circle centered at (200, 200) with // a radius of 25 circle = cx: 200 cy: 200 height: 50 width: 50; // Similar to above, but this will be an ellipse ellipse = cx: 200 cy: 200 height: 100 width: 50; // Ok, now we're actually drawing an arc. This one will draw // the right half of the ellipse above. arc = cx: 200 cy: 200 height: 100 width: 50 theta1: 90 theta2: 270;
git clone git@github.com:austburn/michaelangelo.git
cd michaelangelo
npm install
npm test
Feel free to fork and submit pull requests!