Compare commits

...

10 Commits

Author SHA1 Message Date
Matt 3b43d45a5b
Update README.md 2018-09-14 12:29:00 -04:00
Matt e2338401da
Update README.md 2018-09-13 14:33:16 -04:00
mmcw-dev 867939391e Add a dxf attempt. 2018-02-16 10:01:40 -05:00
mmcw-dev cb3b2ee4e5 Install dxf-writer, for laser-cutting version.
Install qunit and jsdoc-to-markdown for testing and generating docs.
2018-02-15 00:18:32 -05:00
mmcwilliams 0de20e6d3e Update github pages and reference local file in example 2018-01-30 11:19:21 -05:00
Matt a8751dc755 Set theme jekyll-theme-cayman 2018-01-30 11:12:14 -05:00
mmcwilliams 69832ea36f Use a 5mm fold size in the demo 2018-01-29 14:18:13 -05:00
mmcwilliams 7e867bc89b Define fold as a variable, not a dependent 2018-01-29 14:13:40 -05:00
mmcw-dev 35f813e9ac Comment out local version for cdn version 2017-12-27 20:14:25 -05:00
mmcw-dev a91da2ef55 Update readme to actually link the github pages. 2017-12-27 20:10:49 -05:00
7 changed files with 4359 additions and 26 deletions

View File

@ -1,15 +1,25 @@
<a name="module_bellows"></a>
## TRY OUT DEMO
[Works in your browser](https://sixteenmillimeter.github.io/bellows-generator/)
## bellows
**Example**
```js
const bellows = require('bellows')
```
* [bellows](#module_bellows)
* [bellows([options])](#exp_module_bellows--bellows) ⏏
* [~IN](#module_bellows--bellows..IN)
<a name="exp_module_bellows--bellows"></a>
### bellows([options]) ⏏
Generate bellows pattern for cutting and folding.
**Kind**: Exported function
**Typicalname:bellows**: Generate bellows pattern for cutting and folding.
**Typicalname:bellows**:
| Param | Type | Description |
| --- | --- | --- |
@ -36,3 +46,22 @@ const bellows = require('bellows')
const b = bellows({ parts : 2 })
console.log(b)
```
<a name="module_bellows--bellows..IN"></a>
#### bellows~IN
Try it out [in the browser](https://sixteenmillimeter.github.io/bellows-generator/).
### Install (node.js)
First, install dependencies required by
[node-canvas](https://github.com/Automattic/node-canvas) by following
the [install instructions](https://github.com/Automattic/node-canvas#installation)
for your OS.
```
git clone https://github.com/sixteenmillimeter/bellows.git
cd bellows
npm install
```
**Kind**: inner constant of [<code>bellows</code>](#exp_module_bellows--bellows)

View File

@ -75,6 +75,10 @@ input{
<label for="frontIH">Front Inner Height</label>
<input name="frontIH" type="number" value="40" /> mm
</div>
<div>
<label for="fold">Fold Section Width</label>
<input name="fold" type="number" value="5" /> mm
</div>
</div>
<div>
<div>
@ -116,8 +120,8 @@ input{
<button id="download" onclick="download();">Download</button>
</div>
<img id="img" />
<script src="../src/bellows.js"> </script>
<!--<script src="https://rawgit.com/sixteenmillimeter/bellows/master/src/bellows.js">-->
<!--<script src="../src/bellows.js"> </script>-->
<script src="https://rawgit.com/sixteenmillimeter/bellows/master/src/bellows.js">
</script>
<script>
'use script'
@ -147,6 +151,7 @@ input{
const frontIH = Math.round($('frontIH').value * MM);
const maxLength = Math.round($('maxLength').value * MM);
const fold = Math.round($('fold').value * MM);
const key = $('key').checked;
const overlap = $('overlap').checked;
@ -172,6 +177,7 @@ input{
frontIW : frontIW,
frontOH : frontOH,
frontIH : frontIH,
fold : fold,
maxLength : maxLength,
parts : parts,

View File

@ -75,6 +75,10 @@ input{
<label for="frontIH">Front Inner Height</label>
<input name="frontIH" type="number" value="40" /> mm
</div>
<div>
<label for="fold">Fold Section</label>
<input name="fold" type="number" value="5" /> mm
</div>
</div>
<div>
<div>
@ -109,7 +113,7 @@ input{
</div>
<img id="img" />
<!--<script src="../src/bellows.js"></script>-->
<script src="https://rawgit.com/sixteenmillimeter/bellows/master/src/bellows.js"></script>
<script src="../src/bellows.js"></script>
<script>
'use script'
const $ = function (select) {
@ -138,6 +142,7 @@ input{
const frontIH = Math.round($('frontIH').value * MM);
const maxLength = Math.round($('maxLength').value * MM);
const fold = Math.round($('fold').value * MM);
const align = Math.round($('align').value);
let parts = Math.round($('parts').value);
@ -161,6 +166,7 @@ input{
frontIW : frontIW,
frontOH : frontOH,
frontIH : frontIH,
fold : fold,
maxLength : maxLength,
parts : parts,

3720
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,9 +4,13 @@
"description": "Generate bellows folding and cutting patterns.",
"main": "./src/bellows.js",
"dependencies": {
"canvas": "^2.0.0-alpha.9"
"canvas": "^2.0.0-alpha.9",
"dxf-writer": "^1.0.8"
},
"devDependencies": {
"jsdoc-to-markdown": "^4.0.1",
"qunit": "^2.5.0"
},
"devDependencies": {},
"scripts": {
"test": "node ./example"
},

566
src/bellows-dxf.js Normal file
View File

@ -0,0 +1,566 @@
'use strict'
/**
* @module bellows
* @example
* const bellows = require('bellows')
*/
/**
* Try it out [in the browser](https://sixteenmillimeter.github.io/bellows/).
*
* ### Install (node.js)
*
* First, install dependencies required by
* [node-canvas](https://github.com/Automattic/node-canvas) by following
* the [install instructions](https://github.com/Automattic/node-canvas#installation)
* for your OS.
*
* ```
* git clone https://github.com/sixteenmillimeter/bellows.git
* cd bellows
* npm install
* ```
*/
const IN = 25.4
const BLACK = '0,0,0,1.0'
const RED = '255,0,0,1.0'
const BLUE = '0,0,255,1.0'
let browser = (typeof module === 'undefined')
let Drawing
let fs
if (!browser) {
Drawing = Drawing = require('dxf-writer')
fs = require('fs')
}
function line (ctx, rgba, start, end) {
/*ctx.strokeStyle = `rgba(${rgba})`
ctx.beginPath()
ctx.moveTo(start[0], start[1])
ctx.lineTo(end[0], end[1])
ctx.stroke()*/
ctx.drawLine(start[0], start[1], end[0], end[1])
}
function dash (ctx, rgba, dpi, start, end) {
/*ctx.strokeStyle = `rgba(${rgba})`
ctx.setLineDash([(dpi / IN) * 1, (dpi / IN) * 0.5])
ctx.beginPath()
ctx.moveTo(start[0], start[1])
ctx.lineTo(end[0], end[1])
ctx.stroke()
ctx.setLineDash([0, 0])*/
}
function basicShape (ctx, offset, front, back, length) {
const frontOffset = Math.round((back - front) / 2)
const X = -back / 2 + offset[0]
const Y = -length / 2 + offset[1]
//sides
line(ctx, BLACK, [X, Y], [X + frontOffset, Y + length])
line(ctx, BLACK, [X + back, Y], [X + front + frontOffset, Y + length])
//top+bottom
line(ctx, BLACK, [X, Y], [X + back, Y])
line(ctx, BLACK, [X + frontOffset, Y + length], [X + front + frontOffset, Y + length])
}
function taper (back, front, length, pos) {
const diff = (back - front) / 2
//0, 0 -> length, diff
return Math.round((diff / length) * pos)
}
/**
* Generate bellows pattern for cutting and folding.
*
* @alias module:bellows
* @typicalname:bellows
*
*
* @param {Object} [options] Bellows configuration options
* @param {Integer} [options.dpi] DPI of the image
* @param {Integer} [options.pageW] Page width in pixels
* @param {Integer} [options.pageH] Page height in pixels
* @param {Integer} [options.frontIW] Front inner width of bellows in pixels
* @param {Integer} [options.frontOW] Front outer width of bellows in pixels
* @param {Integer} [options.frontIH] Front inner height of bellows in pixels
* @param {Integer} [options.frontOH] Front outer height of bellows in pixels
* @param {Integer} [options.backIW] Back inner width of bellows in pixels
* @param {Integer} [options.backOW] Back outer width of bellows in pixels
* @param {Integer} [options.backIH] Back inner height of bellows in pixels
* @param {Integer} [options.backOH] Back outer height of bellows in pixels
* @param {Integer} [options.maxLength] Maximum length of bellows in pixels
* @param {Integer} [options.align] Vertical alignment adjustment in pixels
* @param {Integer} [options.parts] Number of parts to split pattern into: 1, 2, or 4
* @param {Boolean} [options.key] Print key on page
* @param {Boolean} [options.overlap] Add overlapping flap between parts
*
* returns {String} Base64 encoded png data
*
* @example
* const b = bellows({ parts : 2 })
* console.log(b)
*/
function bellows (options = {}) {
let canvas
let ctx
let dpi = options.dpi || 300
const MM = dpi / IN
let pageW = options.pageW || dpi * 8.5
let pageH = options.pageH || dpi * 11
let frontIW = options.frontIW || Math.round(MM * 40)
let frontOW = options.frontOW || Math.round(MM * 50)
let frontIH = options.frontIH || Math.round(MM * 40)
let frontOH = options.frontOH || Math.round(MM * 50)
let backIW = options.backIW || Math.round(MM * 40)
let backOW = options.backOW || Math.round(MM * 50)
let backIH = options.backIH || Math.round(MM * 40)
let backOH = options.backOH || Math.round(MM * 50)
let fold = options.fold || (frontOW - frontIW) / 2
let align = options.align || 0 //adjust the alignment (find formula)
let maxLength = options.maxLength || MM * 280
let parts = options.parts || 2
let centerX = Math.round(pageW / 2)
let centerY = Math.round(pageH / 2)
let key = (typeof options.key !== 'undefined' && options.key === false) ? false : true
let over = (typeof options.overlap !== 'undefined' && options.overlap === false) ? false : true
let folds = Math.floor(maxLength / fold)
let length = folds * fold
let angleW
let angleH
if (!browser) {
//canvas = createCanvas(pageW, pageH)
ctx = new Drawing()
} else {
//canvas = document.createElement('canvas')
//canvas.width = pageW
//canvas.height = pageH
}
//ctx = canvas.getContext('2d')
//ctx.antialias = 'subpixel'
//fill background white
//ctx.fillStyle = 'rgba(255, 255, 255, 1.0)'
//ctx.fillRect(0, 0, pageW, pageH)
//text config
//ctx.fillStyle='rgba(0,0,0,1.0)'
//ctx.font = '24px Arial';
//ctx.textAlign= 'start';
function sideW (side) {
const frontOffset = Math.round((backOW - frontOW) / 2)
const X = -backOW / 2
const Y = -length / 2
let foldIN = X + ((backOW - backIW) / 2) //inside
let foldOUT = X //outside
let t
let t2
//sides
if (side === 1 || parts === 4 || (parts === 2 && side === 3)) {
line(ctx, BLACK, [X, Y], [X + frontOffset, Y + length])
}
if (parts === 4 && !over) {
line(ctx, BLACK, [X + backOW, Y], [X + backOW - frontOffset, Y + length])
for (let i = 1; i < folds; i++) {
if (i % 2 === 0) {
if (backIW !== frontIW) {
t = taper(backIW, frontIW, length, i * fold)
} else {
t = 0
}
line(ctx, BLACK, [foldIN + backIW - t, Y + (i * fold)], [foldIN + backIW - t + ((backOW - backIW) / 2), Y + (i * fold)])
}
}
}
//inner
//line(ctx, BLACK, [X + ((backOW - backIW) / 2), Y], [X + ((backOW - backIW) / 2) + frontOffset, Y + length])
//line(ctx, BLACK, [X + backOW - ((backOW - backIW) / 2), Y], [X + ((backOW - backIW) / 2) + frontIW + frontOffset, Y + length])
//top
line(ctx, BLACK, [X, Y], [X + backOW, Y])
//bottom
line(ctx, BLACK, [X + frontOffset, Y + length], [X + frontOW + frontOffset, Y + length])
//fold lines
for (let i = 1; i < folds; i++) {
if (i % 2 === 0) {
if (backIW !== frontIW) {
t = taper(backIW, frontIW, length, i * fold)
} else {
t = 0
}
//fold out
line(ctx, BLUE, dpi, [foldIN + t, Y + (i * fold)], [foldIN + backIW - t, Y + (i * fold)])
} else {
if (backOW !== frontOW) {
t = taper(backOW, frontOW, length, i * fold)
} else {
t = 0
}
//fold in
line(ctx, RED, dpi, [foldOUT + t, Y + (i * fold)], [foldOUT + backOW - t, Y + (i * fold)])
}
}
//fold corners, left
for (let i = 0; i < folds; i++) {
if (i % 2 === 0) {
if (backIW !== frontIW) {
t = taper(backIW, frontIW, length, i * fold)
t2 = taper(backIW, frontIW, length, (i + 1) * fold)
} else {
t = 0
t2 = 0
}
if (side === 1 || parts > 1) {
line(ctx, BLACK, [foldIN + t, Y + i * fold ], [foldIN - ((backOW - backIW) / 2) + t2, (Y + (i + 1) * fold) ])
} else {
dash(ctx, BLUE, dpi, [foldIN + t, Y + i * fold ], [foldIN - ((backOW - backIW) / 2) + t2, (Y + (i + 1) * fold) ])
}
} else {
if (backIW !== frontIW) {
t = taper(backIW, frontIW, length, i * fold)
t2 = taper(backIW, frontIW, length, (i + 1) * fold)
} else {
t = 0
t2 = 0
}
if (side === 1 || parts > 1) {
line(ctx, BLACK, [foldOUT + t, Y + i * fold ], [foldIN + t2, (Y + (i + 1) * fold) ])
} else {
line(ctx, BLUE, dpi, [foldOUT + t, Y + i * fold ], [foldIN + t2, (Y + (i + 1) * fold) ])
}
}
//
}
//fold corners, right
for (let i = 0; i < folds; i++) {
if (i % 2 === 0) {
if (backIW !== frontIW) {
t = taper(backIW, frontIW, length, i * fold)
t2 = taper(backIW, frontIW, length, (i + 1) * fold)
} else {
t = 0
t2 = 0
}
line(ctx, BLUE, dpi, [foldIN + backIW - t, Y + i * fold ], [foldOUT + backOW - t2, (Y + (i + 1) * fold) ])
} else {
if (backIW !== frontIW) {
t = taper(backIW, frontIW, length, i * fold)
t2 = taper(backIW, frontIW, length, (i + 1) * fold)
} else {
t = 0
t2 = 0
}
line(ctx, BLUE, dpi, [foldOUT + backOW - t, Y + i * fold ], [foldIN + backIW - t2, (Y + (i + 1) * fold) ])
}
//
}
}
function sideH (side) {
const frontOffset = Math.round((backOH - frontOH) / 2)
const X = -backOH / 2
const Y = -length / 2
let foldIN = X + ((backOH - backIH) / 2) //inside
let foldOUT = X //outside
let t
let t2
//sides
if (parts === 4) {
line(ctx, BLACK, [X, Y], [X + frontOffset, Y + length])
}
if ((parts !== 1 || side === 4) && !over) {
line(ctx, BLACK, [X + backOH, Y], [X + backOH - frontOffset, Y + length])
//cut marks
for (let i = 1; i < folds; i++) {
if (i % 2 !== 0) {
if (backIH !== frontIH) {
t = taper(backIH, frontIH, length, i * fold)
} else {
t = 0
}
line(ctx, BLACK, [foldIN + backIH - t, Y + (i * fold)], [foldIN + backIH - t + ((backOH - backIH) / 2), Y + (i * fold)])
}
}
}
//inner
//line(ctx, BLACK, [X + ((backOH - backIH) / 2), Y], [X + ((backOH - backIH) / 2) + frontOffset, Y + length])
//line(ctx, BLACK, [X + backOH - ((backOH - backIH) / 2), Y], [X + ((backOH - backIH) / 2) + frontIH + frontOffset, Y + length])
//top
line(ctx, BLACK, [X, Y], [X + backOH, Y])
//bottom
line(ctx, BLACK, [X + frontOffset, Y + length], [X + frontOH + frontOffset, Y + length])
//fold lines
for (let i = 1; i < folds; i++) {
if (i % 2 !== 0) {
if (backIH !== frontIH) {
t = taper(backIH, frontIH, length, i * fold)
} else {
t = 0
}
//fold out
line(ctx, BLUE, dpi, [foldIN + t, Y + (i * fold)], [foldIN + backIH - t, Y + (i * fold)])
} else {
if (backOH !== frontOH) {
t = taper(backOH, frontOH, length, i * fold)
} else {
t = 0
}
//fold i
line(ctx, RED, dpi, [foldOUT + t, Y + (i * fold)], [foldOUT + backOH - t, Y + (i * fold)])
}
}
//fold corners, left
for (let i = 0; i < folds; i++) {
if (i % 2 !== 0) {
if (backIH !== frontIH) {
t = taper(backIH, frontIH, length, i * fold)
t2 = taper(backIH, frontIH, length, (i + 1) * fold)
} else {
t = 0
t2 = 0
}
if (parts === 4){
line(ctx, BLACK, [foldIN + t, Y + i * fold ], [foldIN - ((backOH - backIH) / 2) + t2, (Y + (i + 1) * fold) ])
} else {
line(ctx, BLUE, dpi, [foldIN + t, Y + i * fold ], [foldIN - ((backOH - backIH) / 2) + t2, (Y + (i + 1) * fold) ])
}
} else {
if (backIH !== frontIH) {
t = taper(backIH, frontIH, length, i * fold)
t2 = taper(backIH, frontIH, length, (i + 1) * fold)
} else {
t = 0
t2 = 0
}
if (parts === 4) {
line(ctx, BLACK, [foldOUT + t, Y + i * fold ], [foldIN + t2, (Y + (i + 1) * fold) ])
} else {
line(ctx, BLUE, dpi, [foldOUT + t, Y + i * fold ], [foldIN + t2, (Y + (i + 1) * fold) ])
}
}
//
}
//fold corners, right
for (let i = 0; i < folds; i++) {
if (i % 2 !== 0) {
if (backIH !== frontIH) {
t = taper(backIH, frontIH, length, i * fold)
t2 = taper(backIH, frontIH, length, (i + 1) * fold)
} else {
t = 0
t2 = 0
}
line(ctx, BLUE, dpi, [foldIN + backIH - t, Y + i * fold ], [foldOUT + backOH - t2, (Y + (i + 1) * fold) ])
} else {
if (backIH !== frontIH) {
t = taper(backIH, frontIH, length, i * fold)
t2 = taper(backIH, frontIH, length, (i + 1) * fold)
} else {
t = 0
t2 = 0
}
line(ctx, BLUE, dpi, [foldOUT + backOH - t, Y + i * fold ], [foldIN + backIH - t2, (Y + (i + 1) * fold) ])
}
}
}
function overlap (side) {
const Y = -length / 2
let X
let frontOffset
let foldIN
let foldOUT
let t
let t2
let backO
let backI
let frontO
let frontI
if (side % 2 === 0) {
X = -backOH / 2
foldIN = X + ((backOH - backIH) / 2)
frontOffset = Math.round((backOH - frontOH) / 2)
backI = backIH
backO = backOH
frontI = frontIH
frontO = frontOH
} else {
X = -backOW / 2
foldIN = X + ((backOW - backIW) / 2)
frontOffset = Math.round((backOW - frontOW) / 2)
backI = backIW
backO = backOW
frontI = frontIW
frontO = frontOW
}
foldOUT = X
//sides
if (side === 1 || parts === 4 || (parts === 2 && side === 3)) {
//line(ctx, BLACK, [X, Y], [X + frontOffset, Y + length])
}
line(ctx, BLACK, [X + (backO * 0.3) + ((backO - backI) / 2), Y], [foldOUT + (backO * 0.3) + ((backO - backI) / 2), Y + length])
//top
line(ctx, BLACK, [X, Y], [X + (backO * 0.3) + ((backO - backI) / 2), Y])
//bottom
line(ctx, BLACK, [X + frontOffset, Y + length], [foldOUT + (backO * 0.3) + ((backO - backI) / 2), Y + length])
//fold lines
for (let i = 1; i < folds; i++) {
if (side % 2 === 0) {
if (i % 2 === 0) {
if (backI !== frontI) {
t = taper(backI, frontI, length, i * fold)
} else {
t = 0
}
//fold out
dash(ctx, BLUE, dpi, [foldIN + t, Y + (i * fold)], [foldIN + (backO * 0.3), Y + (i * fold)])
} else {
if (backO !== frontO) {
t = taper(backO, frontO, length, i * fold)
} else {
t = 0
}
//fold in
dash(ctx, RED, dpi, [foldOUT + t, Y + (i * fold)], [foldOUT + (backO * 0.3) + ((backO - backI) / 2), Y + (i * fold)])
}
} else {
if (i % 2 !== 0) {
if (backI !== frontI) {
t = taper(backI, frontI, length, i * fold)
} else {
t = 0
}
//fold out
dash(ctx, BLUE, dpi, [foldIN + t, Y + (i * fold)], [foldIN + (backO * 0.3), Y + (i * fold)])
} else {
if (backO !== frontO) {
t = taper(backO, frontO, length, i * fold)
} else {
t = 0
}
//fold in
dash(ctx, RED, dpi, [foldOUT + t, Y + (i * fold)], [foldOUT + (backO * 0.3) + ((backO - backI) / 2), Y + (i * fold)])
}
}
}
}
/*if (key) {
//key
ctx.fillText('Cut lines', dpi / 2, dpi / 2);
line(ctx, BLACK, [dpi / 2, (dpi / 2) + 10], [dpi, (dpi / 2) + 10]);
ctx.fillText('Fold away', dpi / 2, (dpi / 2) + (dpi / 6));
dash(ctx, BLUE, dpi, [dpi / 2, (dpi / 2) + (dpi / 6) + 10], [dpi, (dpi / 2) + (dpi / 6) + 10]);
ctx.fillText('Fold toward', dpi / 2, (dpi / 2) + (dpi / 3));
dash(ctx, RED, dpi, [dpi / 2, (dpi / 2) + (dpi / 3) + 10], [dpi, (dpi / 2) + (dpi / 3) + 10]);
}*/
//ctx.translate(centerX, centerY)
angleW = Math.atan( (backOW - frontOW) / length) // / (Math.PI / 180)
angleH = Math.atan( (backOH - frontOH) / length)
//SIDES
//ctx.translate(-backOW - (backOH / 2), 0)
//ctx.rotate((angleW + angleH) / 2)
sideW(1)
/*if (parts === 4) {
if (over) {
ctx.translate((backOW / 2) + (backOH / 2) - ( ((backOW - frontIW) + (backOH - frontIH)) / 4 ), align)
ctx.rotate((angleW + angleH) / 2)
overlap(1)
ctx.rotate(-(angleW + angleH) / 2)
ctx.translate(-(backOW / 2) - (backOH / 2) + ( ((backOW - frontIW) + (backOH - frontIH)) / 4), -align)
}
ctx.translate(backOW - backIW + (0.3 * backOW), 0)
}
ctx.translate((backOW / 2) + (backOH / 2) - (((backOW - frontIW) + (backOH - frontIH)) / 4), align)
ctx.rotate((angleW + angleH) / 2)*/
sideH(2)
/*
if (parts === 4 || parts === 2) {
if (over) {
ctx.translate((backOW / 2) + (backOH / 2) - ( ((backOW - frontIW) + (backOH - frontIH)) / 4 ), align)
ctx.rotate((angleW + angleH) / 2)
overlap(2)
ctx.rotate(-(angleW + angleH) / 2)
ctx.translate(-(backOW / 2) - (backOH / 2) + ( ((backOW - frontIW) + (backOH - frontIH)) / 4), -align)
}
ctx.translate(backOH - backIH + (0.3 * backOH), 0)
}
ctx.translate((backOW / 2) + (backOH / 2) - (((backOW - frontIW) + (backOH - frontIH)) / 4), align)
ctx.rotate((angleW + angleH) / 2)
sideW(3)
if (parts === 4) {
if (over) {
ctx.translate((backOW / 2) + (backOH / 2) - ( ((backOW - frontIW) + (backOH - frontIH)) / 4 ), align)
ctx.rotate((angleW + angleH) / 2)
overlap(3)
ctx.rotate(-(angleW + angleH) / 2)
ctx.translate(-(backOW / 2) - (backOH / 2) + ( ((backOW - frontIW) + (backOH - frontIH)) / 4), -align)
}
ctx.translate(backOW - backIW + (0.3 * backOW), 0)
}
ctx.translate((backOW / 2) + (backOH / 2) - (((backOW - frontIW) + (backOH - frontIH)) / 4), align)
ctx.rotate((angleW + angleH) / 2)
sideH(4)
if (over) {
ctx.translate((backOW / 2) + (backOH / 2) - (((backOW - frontIW) + (backOH - frontIH)) / 4), align)
ctx.rotate((angleW + angleH) / 2)
overlap(4)
}
return canvas.toDataURL()
*/
return fs.writeFileSync('test.dxf', ctx.toDxfString());
}
if (!browser) {
module.exports = bellows
}

View File

@ -6,6 +6,23 @@
* const bellows = require('bellows')
*/
/**
* Try it out [in the browser](https://sixteenmillimeter.github.io/bellows/).
*
* ### Install (node.js)
*
* First, install dependencies required by
* [node-canvas](https://github.com/Automattic/node-canvas) by following
* the [install instructions](https://github.com/Automattic/node-canvas#installation)
* for your OS.
*
* ```
* git clone https://github.com/sixteenmillimeter/bellows.git
* cd bellows
* npm install
* ```
*/
const IN = 25.4
const BLACK = '0,0,0,1.0'
const RED = '255,0,0,1.0'
@ -56,10 +73,11 @@ function taper (back, front, length, pos) {
}
/**
* Generate bellows pattern for cutting and folding.
*
* @alias module:bellows
* @typicalname:bellows
*
* Generate bellows pattern for cutting and folding.
*
* @param {Object} [options] Bellows configuration options
* @param {Integer} [options.dpi] DPI of the image
@ -106,6 +124,8 @@ function bellows (options = {}) {
let backIH = options.backIH || Math.round(MM * 40)
let backOH = options.backOH || Math.round(MM * 50)
let fold = options.fold || (frontOW - frontIW) / 2
let align = options.align || 0 //adjust the alignment (find formula)
let maxLength = options.maxLength || MM * 280
@ -117,7 +137,6 @@ function bellows (options = {}) {
let key = (typeof options.key !== 'undefined' && options.key === false) ? false : true
let over = (typeof options.overlap !== 'undefined' && options.overlap === false) ? false : true
let fold = (frontOW - frontIW) / 2
let folds = Math.floor(maxLength / fold)
let length = folds * fold
@ -538,21 +557,4 @@ function bellows (options = {}) {
if (!browser) {
module.exports = bellows
}
/**
* Try it out [in the browser](https://sixteenmillimeter.github.io/bellows/).
*
* ### Install (node.js)
*
* First, install dependencies required by
* [node-canvas](https://github.com/Automattic/node-canvas) by following
* the [install instructions](https://github.com/Automattic/node-canvas#installation)
* for your OS.
*
*```
* git clone https://github.com/sixteenmillimeter/bellows.git
* cd bellows
* npm install
*```
*/
}