Skip to content

Commit 867cd18

Browse files
authored
Merge pull request #188 from mattdesl/prettier-format
Prettier formatting
2 parents cb19601 + c32a798 commit 867cd18

31 files changed

+910
-819
lines changed

examples/experimental/animated-scribble-curves-md.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
* @author Matt DesLauriers (@mattdesl)
44
*/
55

6-
const canvasSketch = require('canvas-sketch');
7-
const canvasPainter = require('./util/canvas-painter');
6+
const canvasSketch = require("canvas-sketch");
7+
const canvasPainter = require("./util/canvas-painter");
88

9-
const Random = require('./util/random');
10-
const { clamp, linspace } = require('./util/math');
9+
const Random = require("./util/random");
10+
const { clamp, linspace } = require("./util/math");
1111

1212
// Setup our sketch & export parameters
1313
const settings = {
14-
dimensions: [ 1024, 1024 ],
14+
dimensions: [1024, 1024],
1515
animate: true,
1616
fps: 24,
1717
duration: 6,
1818
scaleToView: true,
19-
playbackRate: 'throttle'
19+
playbackRate: "throttle",
2020
};
2121

2222
const sketch = ({ context, width, height, render }) => {
@@ -55,13 +55,13 @@ const sketch = ({ context, width, height, render }) => {
5555

5656
// Create the full curve
5757
// Note: This is a bit inefficient! We could just compute only the slice we want.
58-
const array = linspace(resolution, true).map(t => {
58+
const array = linspace(resolution, true).map((t) => {
5959
const angle = Math.PI * 2 * t;
6060

6161
// Get point along torus
6262
let point = torus(torusRadius, torusInnerRadius, angle, rotation);
6363

64-
let [ x, y, z ] = point;
64+
let [x, y, z] = point;
6565

6666
// Apply noise frequency to coordinates
6767
x *= freq;
@@ -71,7 +71,7 @@ const sketch = ({ context, width, height, render }) => {
7171
// Compute noise coordinates
7272
return [
7373
amplitude * Random.noise4D(x, y, z, -1),
74-
amplitude * Random.noise4D(x, y, z, 1)
74+
amplitude * Random.noise4D(x, y, z, 1),
7575
];
7676
});
7777

@@ -92,17 +92,17 @@ const sketch = ({ context, width, height, render }) => {
9292
// Gets new random noise & hue
9393
const randomize = () => {
9494
// Reset our random noise function to a new seed
95-
Random.setSeed( '849151'||Random.getRandomSeed());
95+
Random.setSeed("849151" || Random.getRandomSeed());
9696
// Choose a new starting hue
9797
hueStart = Random.value();
9898
// Log the seed for later reproducibility
99-
console.log('Seed:', Random.getSeed());
99+
console.log("Seed:", Random.getSeed());
100100
};
101101

102102
return {
103103
render: ({ context, width, height, playhead }) => {
104104
// Clear the background with nearly black
105-
context.fillStyle = 'pink';
105+
context.fillStyle = "pink";
106106
context.fillRect(0, 0, width, height);
107107

108108
context.save();
@@ -119,16 +119,16 @@ const sketch = ({ context, width, height, render }) => {
119119
const hsl = [
120120
Math.floor(hue * 360),
121121
`${Math.floor(100 * sat)}%`,
122-
`${Math.floor(100 * light)}%`
123-
].join(', ');
122+
`${Math.floor(100 * light)}%`,
123+
].join(", ");
124124
const stroke = `hsl(${hsl})`;
125125

126126
const line = generate(playhead);
127127
painter.polyline(line, {
128128
stroke,
129129
lineWidth: 6 / scale,
130-
linecap: 'round',
131-
lineJoin: 'round'
130+
linecap: "round",
131+
lineJoin: "round",
132132
});
133133

134134
context.restore();
@@ -137,7 +137,7 @@ const sketch = ({ context, width, height, render }) => {
137137
// On loop start, re-compute the noise tables so we get a new
138138
// set of random values on the next loop
139139
randomize();
140-
}
140+
},
141141
};
142142
};
143143

examples/experimental/canvas-card-simple.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const canvasSketch = require('canvas-sketch');
1+
const canvasSketch = require("canvas-sketch");
22

33
const settings = {
44
// Output resolution, we can use 300PPI for print
55
pixelsPerInch: 300,
66
// Standard business card size
7-
dimensions: [ 3.5, 2 ],
7+
dimensions: [3.5, 2],
88
// all our dimensions and rendering units will use inches
9-
units: 'in'
9+
units: "in",
1010
};
1111

1212
const sketch = ({ context }) => {
@@ -21,14 +21,14 @@ const sketch = ({ context }) => {
2121
return ({ context, width, height, frame }) => {
2222
// Fill page with solid color
2323
// The 'width' and 'height' will be in inches here
24-
context.fillStyle = '#000';
24+
context.fillStyle = "#000";
2525
context.fillRect(0, 0, width, height);
2626

27-
context.strokeStyle = '#fff';
28-
context.fillStyle = '#fff';
27+
context.strokeStyle = "#fff";
28+
context.fillStyle = "#fff";
2929
context.lineWidth = 0.01;
3030
for (let i = 0; i < 5; i++) {
31-
const x = i / 4 * width;
31+
const x = (i / 4) * width;
3232
const y = height / 2;
3333
const radius = i % 2 === 0 ? 0.5 : 0.25;
3434
const fill = i % 4 === 0;

examples/experimental/canvas-dancing-scribble.1.js

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
1-
const canvasSketch = require('canvas-sketch');
2-
const { vec2, quat, mat4 } = require('gl-matrix');
3-
const defined = require('defined');
4-
const { cubicSpline } = require('./util/geom');
5-
const Random = require('./util/random');
6-
const { clamp, lerp, lerpArray, expand2D, linspace } = require('./util/math');
7-
const simplify = require('simplify-path');
8-
const hsl2rgb = require('float-hsl2rgb');
1+
const canvasSketch = require("canvas-sketch");
2+
const { vec2, quat, mat4 } = require("gl-matrix");
3+
const defined = require("defined");
4+
const { cubicSpline } = require("./util/geom");
5+
const Random = require("./util/random");
6+
const { clamp, lerp, lerpArray, expand2D, linspace } = require("./util/math");
7+
const simplify = require("simplify-path");
8+
const hsl2rgb = require("float-hsl2rgb");
99
//73787, 720474, 822882, 40002, 708321
1010
// Random.setSeed(Random.getRandomSeed());
11-
Random.setSeed('708321');
12-
console.log('Seed', Random.getSeed());
11+
Random.setSeed("708321");
12+
console.log("Seed", Random.getSeed());
1313

1414
const settings = {
15-
dimensions: [ 1024, 1024 ],
15+
dimensions: [1024, 1024],
1616
// exportPixelRatio: 2,
1717
animate: true,
1818
fps: 24,
1919
scaleToView: true,
2020
duration: 20,
21-
playbackRate: 'throttle'
21+
playbackRate: "throttle",
2222
};
2323

2424
const colors = {
25-
background: '#f4d9be',
26-
foreground: '#ff911c',
27-
pen: '#1975ff'
25+
background: "#f4d9be",
26+
foreground: "#ff911c",
27+
pen: "#1975ff",
2828
};
2929

3030
const sketch = ({ context, width, height, render }) => {
3131
const paint = (opt = {}) => {
3232
let fill = opt.fill;
3333
let stroke = opt.stroke;
34-
const defaultColor = 'black';
34+
const defaultColor = "black";
3535
const alpha = defined(opt.alpha, 1);
3636

3737
// Default to fill-only
3838
if (opt.fill == null && opt.stroke == null) fill = true;
3939

4040
if (fill) {
4141
const fillAlpha = defined(opt.fillAlpha, 1);
42-
context.fillStyle = typeof fill === 'boolean' ? defaultColor : fill;
42+
context.fillStyle = typeof fill === "boolean" ? defaultColor : fill;
4343
context.globalAlpha = alpha * fillAlpha;
4444
context.fill();
4545
}
4646
if (stroke) {
4747
const strokeAlpha = defined(opt.strokeAlpha, 1);
48-
context.strokeStyle = typeof stroke === 'boolean' ? defaultColor : stroke;
48+
context.strokeStyle = typeof stroke === "boolean" ? defaultColor : stroke;
4949
context.lineWidth = defined(opt.lineWidth, 1);
50-
context.lineCap = opt.lineCap || 'butt';
51-
context.lineJoin = opt.lineJoin || 'miter';
50+
context.lineCap = opt.lineCap || "butt";
51+
context.lineJoin = opt.lineJoin || "miter";
5252
context.miterLimit = defined(opt.miterLimit, 10);
5353
context.globalAlpha = alpha * strokeAlpha;
5454
context.stroke();
@@ -63,27 +63,24 @@ const sketch = ({ context, width, height, render }) => {
6363
paint(opt);
6464
};
6565

66-
const segment = (x, y, length, angle, opt = {}) => {
67-
68-
};
66+
const segment = (x, y, length, angle, opt = {}) => {};
6967

7068
const polyline = (path, opt = {}) => {
7169
context.beginPath();
72-
path.forEach(point => context.lineTo(point[0], point[1]));
70+
path.forEach((point) => context.lineTo(point[0], point[1]));
7371
if (opt.closed) context.closePath();
7472
paint(opt);
7573
};
7674

7775
const polylines = (lines, opt = {}) => {
78-
lines.forEach(path => {
76+
lines.forEach((path) => {
7977
context.beginPath();
80-
path.forEach(point => context.lineTo(point[0], point[1]));
78+
path.forEach((point) => context.lineTo(point[0], point[1]));
8179
if (opt.closed) context.closePath();
8280
paint(opt);
8381
});
8482
};
8583

86-
8784
// Wavy line across the page
8885
// const line = arcs01(100).map(t => {
8986
// return [ t * 2 - 1, Random.noise1D(t * 5) * 0.25 ];
@@ -122,7 +119,7 @@ const sketch = ({ context, width, height, render }) => {
122119
const amplitude = 0.7;
123120
const freq = 2.0;
124121
const resolution = 5000;
125-
const array = linspace(resolution, true).map(t => {
122+
const array = linspace(resolution, true).map((t) => {
126123
// const angle = Math.PI * 2 * t;
127124
// let point = [ Math.cos(angle), Math.sin(angle) ];
128125
// vec2.scale(point, point, freq);
@@ -134,10 +131,10 @@ const sketch = ({ context, width, height, render }) => {
134131
const angle = Math.PI * 2 * t;
135132
let point = torus(0.25, 1.5, angle, theta * 5);
136133
vec2.scale(point, point, freq);
137-
const [ x, y, z ] = point;
134+
const [x, y, z] = point;
138135
return [
139136
amplitude * Random.noise4D(x, y, z, -1),
140-
amplitude * Random.noise4D(x, y, z, 1)
137+
amplitude * Random.noise4D(x, y, z, 1),
141138
];
142139
});
143140

@@ -191,17 +188,17 @@ const sketch = ({ context, width, height, render }) => {
191188
// }
192189

193190
return ({ context, width, height, playhead }) => {
194-
context.fillStyle = 'hsl(0, 0%, 5%)';
195-
context.globalCompositeOperation = 'source-over';
191+
context.fillStyle = "hsl(0, 0%, 5%)";
192+
context.globalCompositeOperation = "source-over";
196193
context.fillRect(0, 0, width, height);
197194

198195
context.save();
199196
context.translate(width / 2, height / 2);
200197
const scale = width / 2;
201198
context.scale(scale, scale);
202199

203-
context.lineJoin = 'round';
204-
context.lineCap = 'round';
200+
context.lineJoin = "round";
201+
context.lineCap = "round";
205202

206203
// polylines(lines, {
207204
// stroke: 'black',
@@ -234,8 +231,10 @@ const sketch = ({ context, width, height, render }) => {
234231
polyline(line, {
235232
// fill: 'black',
236233
// closed: true,
237-
stroke: `rgb(${hsl2rgb([ h, s, l ]).map(n => Math.floor(n * 255)).join(', ')})`,
238-
lineWidth: 6 / scale
234+
stroke: `rgb(${hsl2rgb([h, s, l])
235+
.map((n) => Math.floor(n * 255))
236+
.join(", ")})`,
237+
lineWidth: 6 / scale,
239238
});
240239
}
241240

0 commit comments

Comments
 (0)