Skip to content

Commit

Permalink
Added algorithm example
Browse files Browse the repository at this point in the history
  • Loading branch information
twolfson committed Dec 14, 2014
1 parent e38cf91 commit 7049358
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,39 @@ For the best results, install from the site rather than through a package manage
[Graphics Magick]: http://www.graphicsmagick.org/
[Image Magick]: http://imagemagick.org/

## Examples
### Algorithm
This is an example of using a custom layout via the `alt-diagonal` algorithm.

```js
// Load in dependencies
var fs = require('fs');
var spritesmith = require('spritesmith');

// Generate our spritesheet
spritesmith({
src: [
__dirname + '/fork.png',
__dirname + '/github.png',
__dirname + '/twitter.png'
],
algorithm: 'alt-diagonal'
}, function handleResult (err, result) {
// If there was an error, throw it
if (err) {
throw err;
}

// Output the image
fs.writeFileSync(__dirname + '/alt-diagonal.png', result.image, 'binary');
result.coordinates, result.properties; // Coordinates and properties
});
```

**Result:**

![alt-diagonal spritesheet](docs/alt-diagonal.png)

## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint via `npm run lint` and test via `npm test`.

Expand Down
22 changes: 22 additions & 0 deletions docs/alt-diagonal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Load in dependencies
var fs = require('fs');
var spritesmith = require('../');

// Generate our spritesheet
spritesmith({
src: [
__dirname + '/fork.png',
__dirname + '/github.png',
__dirname + '/twitter.png'
],
algorithm: 'alt-diagonal'
}, function handleResult (err, result) {
// If there was an error, throw it
if (err) {
throw err;
}

// Output the image
fs.writeFileSync(__dirname + '/alt-diagonal.png', result.image, 'binary');
result.coordinates, result.properties; // Coordinates and properties
});
Binary file added docs/alt-diagonal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7049358

Please sign in to comment.