-
Notifications
You must be signed in to change notification settings - Fork 0
/
polycircles-test.js
47 lines (40 loc) · 1.28 KB
/
polycircles-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const canvasSketch = require('canvas-sketch');
const { renderPolylines } = require('canvas-sketch-util/penplot');
const { clipPolylinesToBox } = require('canvas-sketch-util/geometry');
const settings = {
dimensions: [115.23, 60.01],
orientation: 'portrait',
pixelsPerInch: 300,
scaleToView: true,
units: 'mm',
};
const sketch = ({ width, height }) => {
// List of polylines for our pen plot
let lines = [];
// Draw some circles expanding outward
const steps = 5;
const count = 20;
const spacing = Math.min(width, height) * 0.05;
const radius = Math.min(width, height) * 0.25;
for (let j = 0; j < count; j++) {
const r = radius + j * spacing;
const circle = [];
for (let i = 0; i < steps; i++) {
const t = i / Math.max(1, steps - 1);
const angle = Math.PI * 2 * t;
circle.push([
width / 2 + Math.cos(angle) * r,
height / 2 + Math.sin(angle) * r
]);
}
lines.push(circle);
}
// Clip all the lines to a margin
const margin = 1.0;
const box = [ margin, margin, width - margin, height - margin ];
lines = clipPolylinesToBox(lines, box);
// The 'penplot' util includes a utility to render
// and export both PNG and SVG files
return props => renderPolylines(lines, props);
};
canvasSketch(sketch, settings);