Amino: JavaScript Scenegraph

Overview

Amino is a scenegraph for drawing 2D graphics in JavaScript with the HTML 5 Canvas API. By creating a tree of nodes, you can draw shapes, text, images special effects; complete with transforms and animation. Amino takes care of all rendering, animation, and event handling so you can build rich interactive graphics with very little code. Using Amino is much more convenient than writing canvas code by hand. Here's a quick example:
<canvas id="can" width="200" height="200"></canvas>
<script>

//attach a runner to the canvas
var can = document.getElementById("can");
var runner = new Runner().setCanvas(can);

//create a rect and a circle
var r = new Rect().set(0,0,50,50).setFill("green");
var c = new Circle().set(100,100,30).setFill("blue");

//add the shapes to a group
var g = new Group().add(r).add(c);

//make the rectangle go left and right every 5 seconds
var anim = new Anim(g,"x",0,150,5);
runner.addAnim(anim);

//set the group as the root of the scenegraph, then start
runner.root = g;
runner.start();

</script>

A note on properties. Most objects have properties like x or width. Properties are accessed with getters. For example, to access the width property on a rectangle, call rect.getWidth(). Properties are set with setters. For example, to set the width property on a rectangle, call rect.setWidth(100). Most functions, especially property setters, are chainable. This means you can set a bunch of properties at once like this:
var c = new Rect()
    .setX(50)
    .setY(50)
    .setWidth(100)
    .setHeight(200)
    .setFill("green")
    .setStrokeWidth(5)
    .setStroke("black")
        ;

Classes by Category

Node

The base class for all nodes. All nodes have a parent and can potentially have children if they implement hasChildren.

Properties

Methods

Bounds

Represents the maximum bounds of something, usually the visible bounds of a node.

Properties

Buffer

An offscreen area that you can draw into. Used for special effects and caching.

Properties

Methods

BufferNode

A node which draws its child into a buffer. Use it to cache children which are expensive to draw.

Transform

Transforms the child inside of it with a translation and/or rotation.

Properties

Group

A parent node which holds an ordered list of child nodes. It does not draw anything by itself, but setting visible to false will hide the children.

Properties

Methods

ImageView

A node which draws an image. Takes a string URL in it's constructor. ex: new ImageView("blah.png")

Properties

MEvent

The base mouse event. Has a reference to the node that the event was on (if any), and the x and y coords. Will have more functionality in the future.

Methods

PropAnim

A PropAnim is a single property animation. It animates a property on an object over time, optionally looping and reversing direction at the end of each loop (making it oscillate).

Properties

Methods

PathAnim

Animates a shape along a path. The Path can be composed of lines or curves. PathAnim can optionally loop or reverse direction at the end. Create it with the node, path, and duration like this: new PathAnim(node,path,10);

Properties

Methods

Runner

The core of Amino. It redraws the screen, processes events, and executes animation. Create a new instance of it for your canvas, then call start() to start the event loop.

Properties

Methods

Util

A class with some static utility functions.

Methods