Git Product home page Git Product logo

orthogami's Introduction

orthogami

Turn voxel models into foldable origami! For example, you can turn this mario model:

Into this foldable model:

If you want to try making a Mario yourself, here is a PDF in A4 format.

This module works in any reasonable CommonJS environment (includes node.js and browserify). You can also use it with the voxel critter creator (select "Export Orthogami").

Example usage

//First create a voxel set
//  0 = empty
var voxels = require('ndarray-pack')([
  [[0, 1],
   [2, 3]],
  [[0, 0],
   [0, 4]]
])

//Require the module (works with browserify)
var orthogami = require('orthogami')

//Set up options (can skip this if you like)
var options = {
  units: 'mm',            //Units
  bounds: [210, 297],     //Page size
  scale: 10,              //Size of voxel
  lineWidth: 0.1          //Size of dashed line
}

//Then run orthogami
var svgs = orthogami(voxels, options)

//Print out the result
var fs = require('fs')
svgs.forEach(function(svg, idx) {
  fs.writeFileSync('page' + idx + '.svg', svg)
})

Output

Page 1:

Page 2:

Install

npm install orthogami

API

require('orthogami')(voxels[, options])

Generates an origami template for folding a model from the given voxel object.

  • voxels is a 3D ndarray of integer values. 0 values indicate empty voxels.

  • options is an optional object containing any of the following extra parameters:

    • colorMap a function mapping color values in the voxels to SVG color names, or alternatively an array of SVG color names.
    • bounds a 2D array representing the size of each page (default [Infinity, Infinity])
    • scale a number giving the size of each voxel (default 64)
    • convexColor the color of the convex creases (default 'black')
    • concaveColor the color of the concave creases (default 'white')
    • tabColor the color of the tab lines (default 'black')
    • lineWidth the width of the crease lines (default 1)
    • units the units for the coordinate system (default 'px')

Returns An array of SVG files encoding the pages of the origami printout

Credits

(c) 2014 Mikola Lysenko. MIT License

orthogami's People

Contributors

mikolalysenko avatar shama avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.