obelisk.js-browserify-test
v1.0.4
Published
JavaScript Engine for Building Pixel Isometric Element with HTML5 Canvas
Downloads
5
Maintainers
Readme
Obelisk.js
Obelisk.js is a JavaScript Engine for building isometric pixel objects.
With the simple and flexible API provided by it, you can easily add isometric pixel element like brick, cube, pyramid onto HTML5 canvas. Obelisk.js strictly follows the pixel neat pattern: lines with 1:2 pixel dot arrangement, leading to an angle of 22.6 degrees.
You should know this is not for vector isometric graphics drawing. In fact it is not using any canvas graphic drawing API at all, instead, it manipulates all the things in pixel level to obtain typical pixel arrangement. Just try it out to pixelate something. Have fun.
Showcase
Origin:
- GIF Animation Rendering: http://codepen.io/nosir/details/mdiHe (WebKit browser only - Chrome, Safari)
- Input Text Rendering: http://codepen.io/nosir/details/IxBJn
- Pixel Isometirc Flappy Bird: http://codepen.io/nosir/details/rzaLA
- Cube Generator: http://codepen.io/nosir/details/ganrh
User Contributed:
- Github Contribution Chart Isometric View Chrome Extension: Github Project URL by @jasonlong
- Online Voxel Builder: http://ngryman.sh/obelisk-buildr by @ngryman
- Snake Game: http://codepen.io/sfaedo/full/AwGjg (Use ← → Key) by @Sebastian Faedo
- Mario 3D voxel: http://jsdo.it/cx20/bQtQ by @cx20
- Conway's Game of Life: http://codepen.io/safx/full/Ewcym by @safxdev
- Node Server-side Image Rendering with node-canvas: Github Project URL by @pose
- Animations with Angular.js: Github Project URL by @Wildhoney
Getting started
Simply include obelisk.js in your project
<script src="//path/to/obelisk.min.js"></script>
In JavaScript
// create a canvas 2D point for pixel view world
var point = new obelisk.Point(200, 200);
// create view instance to nest everything
// canvas could be either DOM or jQuery element
var pixelView = new obelisk.PixelView(canvas, point);
// create cube dimension and color instance
var dimension = new obelisk.CubeDimension(80, 100, 120);
var gray = obelisk.ColorPattern.GRAY;
var color = new obelisk.CubeColor().getByHorizontalColor(gray);
// build cube with dimension and color instance
var cube = new obelisk.Cube(dimension, color, true);
// render cube primitive into view
pixelView.renderObject(cube);
For more details, check the tutorial part 1: To build the first cube or try the code yourself
Node.js
Also you can use it in your Node.js canvas project
As node.js
canvas
dependency can be tricky to install (binary dependency on Cairo) we are not adding it as a project dependency. You will need to add thecanvas
dependency explicitly on your project:
$ npm install canvas
$ npm install obelisk.js
In your JavaScript
// load Node Canvas dependency
var Canvas = require('canvas');
// load obelisk.js module
// here we need the Canvas as a module parameter
var obelisk = require('obelisk.js')(Canvas);
// create a Node Canvas instance
var canvas = new Canvas(600,450);
// Use obelisk the same way you will use it in the browser ...
// Save canvas to a file
canvas.createPNGStream().pipe(fs.createWriteStream('./figure.png'));
For more details, check the Node.js Canvas example.
Tutorials
Step by step:
- Part 1: To build the first cube
- Part 2: Coordinate system
- Part 3: Primitives
- Part 4: Color
- Part 5: Dimension
Sample code for building all primitives:
- Cube: http://jsfiddle.net/nosir/ygWEW/
- Pyramid : http://jsfiddle.net/nosir/ZVURu/
- Brick: http://jsfiddle.net/nosir/6MuVr/
- SideX & SideY: http://jsfiddle.net/nosir/bLsew/
Roadmap
To add more pixel primitives - 4 directions slopes will be the first
Get in Touch
- Build any cool stuff? Please feel free to add it here: User Contributed Showcase I prefer you not to send PR to update README.md, someone will update it at some point:)
- Bugs & Suggestions: open an issue
- Twitter: @rison
Changelog
See details in the release notes.
References
Pixel art is a form of digital art, where images are edited and displayed on the pixel level. The isometric projection is commonly seen in games to provide a 3D view without using any real 3D processing.
- Isometric projection http://en.wikipedia.org/wiki/Isometric_projection
- Flood fill implementation http://en.wikipedia.org/wiki/Flood_fill
- Pixel grapic - Eboy http://eboy.com
License
Obelisk.js is released under the MIT License