0.1.1 • Published 2 months ago

@raducal/isomer v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

isomer

An isometric graphics library for HTML5 canvas.

View the official project page or try it out.

About

Isomer is an easy-to-use graphics library for drawing isometric scenes.

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))
})

output

Getting Started

Isomer is available as a package on NPM.

# 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.

<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.

#art {
  width: 400px;
  height: 300px;
}

At this point we can finally instantiate an Isomer object. Pass it a reference to your canvas like so:

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, meaning you can generate isometric graphics on the command line.

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.

MIT Licensed

0.1.1

2 months ago

0.1.0

2 months ago

0.0.2

2 months ago

0.0.1

3 months ago