@raducal/isomer
Version:
A simple isometric graphics library for HTML5 canvas
100 lines (68 loc) • 2.71 kB
Markdown

An isometric graphics library for HTML5 canvas.
View the [official project page](http://jdan.github.io/isomer/) or [try it out](http://jdan.github.io/isomer/playground).
## About
[Isomer](http://jdan.github.io/isomer/) is an easy-to-use graphics library for drawing isometric scenes.
```javascript
var Shape = Isomer.Shape;
var Point = Isomer.Point;
var Color = Isomer.Color;
var Textured = Isomer.Textured;
var red = new Color(160, 60, 50);
var blue = new Color(50, 60, 160);
iso.add(Shape.Prism(Point.ORIGIN, 3, 3, 1));
iso.add(Shape.Pyramid(Point(0, 2, 1)), red);
iso.add(Shape.Prism(Point(2, 0, 1)), blue);
const texture = new Image()
textre.src = "https://i.cloudup.com/kQrnH2x5XE-3000x3000.png"
texture.onload = () => {
iso.add(new Textured(Shape.Prism(point), texture))
// define an image for each path in the shape
iso.add(new Textured(Shape.Prism(point), [texture, texture, texture, texture, texture, texture]))
}
const blob = new Blob([...your image])
createImageBitmap(blob).then((bitmap) => {
iso.add(new Textured(Shape.Prism(point), bitmap))
})
```

## Getting Started
Isomer is available as a package on NPM.
```html
# NPM
npm install @raducal/isomer
# Yarn
yarn add @raducal/isomer
```
After which you'll need to place a canvas in your document that we can later refer to. Be sure to give it a width and height.
```html
<canvas width="800" height="600" id="art"></canvas>
```
**Note (Optional):** To improve the look of your canvas on retina displays, declare the width and height of your canvas element as double how you want it to appear. Then style your canvas with CSS to include the original dimensions.
```css
#art {
width: 400px;
height: 300px;
}
```
At this point we can finally instantiate an Isomer object. Pass it a reference to your canvas like so:
```javascript
var iso = new Isomer(document.getElementById("art"));
```
Now you're ready to start drawing!
## With node-canvas
Isomer also accepts the canvas provided by [node-canvas](https://github.com/learnboost/node-canvas),
meaning you can generate isometric graphics on the command line.
```javascript
var Canvas = require('canvas');
var canvas = new Canvas(400, 400);
var Isomer = require('isomer'); // npm install isomer
var fs = require('fs');
var out = fs.createWriteStream('output.png');
var iso = new Isomer(canvas);
iso.add(Isomer.Shape.Prism(Isomer.Point.ORIGIN));
canvas.pngStream().pipe(out);
```
## More Info
For more info, check out the [official project page](http://jdan.github.io/isomer).
[MIT Licensed](https://github.com/jdan/isomer/blob/master/LICENSE)