Mixin: ABM.util.shapes

Defined in: src/util_shapes.coffee
Included in: ABM.Util.Shapes

Overview

Each shape is a named object with two members: a boolean rotate and a draw procedure and two optional properties: image for images, and shortcut for a transform-less version of draw. The shape is used in the following context with a color set and a transform such that the shape should be drawn in a -.5 to .5 square

context.save()
context.fillStyle = color.rgbString()
context.translate x, y; context.scale size, size;
context.rotate heading if shape.rotate
context.beginPath(); shape.draw(context); context.closePath()
context.fill()
context.restore()

The list of current shapes, via u.shapes.names() below, is:

["default", "triangle", "arrow", "bug", "pyramid",
  "circle", "square", "pentagon", "ring", "cup", "person"]

Method Summary

Method Details

~ (void) polygon(context, array)

A simple polygon utility: c is the 2D context, and a is an array of 2D points; c.closePath() and c.fill() will be called by the calling agent, see initial discription of drawing context. It is used in adding a new shape above.

~ (void) centered_circle(context, x, y, size)

Centered drawing primitives: centered on x, y with a given width/height size. Useful for shortcuts.

~ (void) counter_centered_circle(context, x, y, size)

Centered counter clockwise circle.

~ (void) centered_image(context, x, y, size, image)

Centered image.

~ (void) centered_square(context, x, y, size)

Centered square.

~ (void) fillSlot(slot, image)

An async util for delayed drawing of images into sprite slots.

~ (void) names()

Return a list of the available shapes, see above.

~ (void) add(name, rotate, draw, shortcut)

Add your own shape. Will be included in names list.

Usage:

u.shapes.add "test", true, (c) -> # bowtie/hourglass
  u.shapes.polygon c, [[-.5, -.5], [.5, .5], [-.5, .5], [.5, -.5]]

Note: an image that is not rotated automatically gets a shortcut.

~ (void) draw(context, shape, x, y, size, rad, color, strokeColor)

Two draw procedures, one for shapes, the other for sprites made from shapes.

~ (void) drawSprite(context, slot, x, y, size, radians)

~ (void) shapeToSprite(name, color, size, strokeColor)

Convert a shape to a sprite by allocating a sprite sheet "slot" and drawing the shape to fit it. Return existing sprite if duplicate.

    Quickly fuzzy find classes, mixins, methods, file:

    Control the navigation frame:

    You can focus and blur the search input: