Skip to content
This repository was archived by the owner on Dec 6, 2022. It is now read-only.

Graphics API

Ian Glen edited this page Aug 16, 2013 · 33 revisions

scripts/graphics/core.js

Dominion includes a graphics API used for drawing isometric graphics on the HTML5 canvas. It is used in everything from drawing the grid to converting between orthographic and isometric coordinate systems.

What does orthographic/isometric mean?

An orthographic projection refers to a 2d coordinate system where x is the horizontal coordinate and y is the vertical coordinate. Pixels on a screen are located on an orthographic coordinate system, and it is used for drawing graphics on the canvas. Orthographic coordinates will sometimes be referred to as real-world or screen coordinates.

An isometric projection is used to represent 3d objects on a 2d grid. Objects appear tipped towards the viewer at 30º. Isometric coordinates (x, y, z) are used to represent a point in 3d space, therefore it is necessary to convert them to orthographic before drawing them on the screen.

Color object

Defines an RGB color.

var color = new Color(255, 255, 255);

Methods

Color.formatRGB()

Returns: (string) color formatted as an RGB string

Color.formatRGBA(float opacity)

Returns: (string) color formatted as an RGBA string with given opacity

Color.fromRGB(string rgbString)

Sets the values of red, green, and blue based on the values given in an RGB string.

Properties

Color.red (integer)

The red value for the color.

Color.green (integer)

The green value for the color.

Color.blue (integer)

The blue value for the color.

OrthographicPoint object

Defines a point in an orthographic coordinate system.

var point = new OrthographicPoint(x, y);

Methods

OrthographicPoint.toIsometricPoint(Grid grid)

Converts orthographic coordinates to isometric coordinates on given Grid object.

Returns: (IsometricPoint) converted coordinates

OrthographicPoint.toIsometricPointAsInteger(Grid grid)

Converts orthographic coordinates to integer isometric coordinates on given Grid object.

Returns: (IsometricPoint) converted coordinates as integers

Properties

OrthographicPoint.x (float)

Horizontal coordinate for the point.

OrthographicPoint.y (float)

Vertical coordinate for the point.

IsometricPoint object

Defines a point in an isometric coordinate system.

var point = new IsometricPoint(x, y);

Methods

IsometricPoint.toOrthographicPoint(Grid grid)

Converts isometric coordinates to orthographic coordinates on given Grid object.

Returns: (OrthographicPoint) converted coordinates

Properties

IsometricPoint.x (float)

Horizontal coordinate for the point.

IsometricPoint.y (float)

Vertical coordinate for the point.

Canvas object

Defines the canvas where graphics are drawn.

var canvasElement = $('canvas').get(0);
var context = canvasElement.getContext('2d');
var canvas = new Canvas(canvasElement, context);

Methods

Canvas.clear()

Clears the entire canvas.

Properties

Canvas.element (Element DOM Object)

Represents the <canvas> HTML element.

Canvas.context (CanvasRenderingContext2D HTML5 Object)

Represents the HTML5 canvas context on which graphics are drawn.

Clone this wiki locally