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" ) ;
9
9
//73787, 720474, 822882, 40002, 708321
10
10
// Random.setSeed(Random.getRandomSeed());
11
- Random . setSeed ( ' 708321' ) ;
12
- console . log ( ' Seed' , Random . getSeed ( ) ) ;
11
+ Random . setSeed ( " 708321" ) ;
12
+ console . log ( " Seed" , Random . getSeed ( ) ) ;
13
13
14
14
const settings = {
15
- dimensions : [ 1024 , 1024 ] ,
15
+ dimensions : [ 1024 , 1024 ] ,
16
16
// exportPixelRatio: 2,
17
17
animate : true ,
18
18
fps : 24 ,
19
19
scaleToView : true ,
20
20
duration : 20 ,
21
- playbackRate : ' throttle'
21
+ playbackRate : " throttle" ,
22
22
} ;
23
23
24
24
const colors = {
25
- background : ' #f4d9be' ,
26
- foreground : ' #ff911c' ,
27
- pen : ' #1975ff'
25
+ background : " #f4d9be" ,
26
+ foreground : " #ff911c" ,
27
+ pen : " #1975ff" ,
28
28
} ;
29
29
30
30
const sketch = ( { context, width, height, render } ) => {
31
31
const paint = ( opt = { } ) => {
32
32
let fill = opt . fill ;
33
33
let stroke = opt . stroke ;
34
- const defaultColor = ' black' ;
34
+ const defaultColor = " black" ;
35
35
const alpha = defined ( opt . alpha , 1 ) ;
36
36
37
37
// Default to fill-only
38
38
if ( opt . fill == null && opt . stroke == null ) fill = true ;
39
39
40
40
if ( fill ) {
41
41
const fillAlpha = defined ( opt . fillAlpha , 1 ) ;
42
- context . fillStyle = typeof fill === ' boolean' ? defaultColor : fill ;
42
+ context . fillStyle = typeof fill === " boolean" ? defaultColor : fill ;
43
43
context . globalAlpha = alpha * fillAlpha ;
44
44
context . fill ( ) ;
45
45
}
46
46
if ( stroke ) {
47
47
const strokeAlpha = defined ( opt . strokeAlpha , 1 ) ;
48
- context . strokeStyle = typeof stroke === ' boolean' ? defaultColor : stroke ;
48
+ context . strokeStyle = typeof stroke === " boolean" ? defaultColor : stroke ;
49
49
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" ;
52
52
context . miterLimit = defined ( opt . miterLimit , 10 ) ;
53
53
context . globalAlpha = alpha * strokeAlpha ;
54
54
context . stroke ( ) ;
@@ -63,27 +63,24 @@ const sketch = ({ context, width, height, render }) => {
63
63
paint ( opt ) ;
64
64
} ;
65
65
66
- const segment = ( x , y , length , angle , opt = { } ) => {
67
-
68
- } ;
66
+ const segment = ( x , y , length , angle , opt = { } ) => { } ;
69
67
70
68
const polyline = ( path , opt = { } ) => {
71
69
context . beginPath ( ) ;
72
- path . forEach ( point => context . lineTo ( point [ 0 ] , point [ 1 ] ) ) ;
70
+ path . forEach ( ( point ) => context . lineTo ( point [ 0 ] , point [ 1 ] ) ) ;
73
71
if ( opt . closed ) context . closePath ( ) ;
74
72
paint ( opt ) ;
75
73
} ;
76
74
77
75
const polylines = ( lines , opt = { } ) => {
78
- lines . forEach ( path => {
76
+ lines . forEach ( ( path ) => {
79
77
context . beginPath ( ) ;
80
- path . forEach ( point => context . lineTo ( point [ 0 ] , point [ 1 ] ) ) ;
78
+ path . forEach ( ( point ) => context . lineTo ( point [ 0 ] , point [ 1 ] ) ) ;
81
79
if ( opt . closed ) context . closePath ( ) ;
82
80
paint ( opt ) ;
83
81
} ) ;
84
82
} ;
85
83
86
-
87
84
// Wavy line across the page
88
85
// const line = arcs01(100).map(t => {
89
86
// return [ t * 2 - 1, Random.noise1D(t * 5) * 0.25 ];
@@ -122,7 +119,7 @@ const sketch = ({ context, width, height, render }) => {
122
119
const amplitude = 0.7 ;
123
120
const freq = 2.0 ;
124
121
const resolution = 5000 ;
125
- const array = linspace ( resolution , true ) . map ( t => {
122
+ const array = linspace ( resolution , true ) . map ( ( t ) => {
126
123
// const angle = Math.PI * 2 * t;
127
124
// let point = [ Math.cos(angle), Math.sin(angle) ];
128
125
// vec2.scale(point, point, freq);
@@ -134,10 +131,10 @@ const sketch = ({ context, width, height, render }) => {
134
131
const angle = Math . PI * 2 * t ;
135
132
let point = torus ( 0.25 , 1.5 , angle , theta * 5 ) ;
136
133
vec2 . scale ( point , point , freq ) ;
137
- const [ x , y , z ] = point ;
134
+ const [ x , y , z ] = point ;
138
135
return [
139
136
amplitude * Random . noise4D ( x , y , z , - 1 ) ,
140
- amplitude * Random . noise4D ( x , y , z , 1 )
137
+ amplitude * Random . noise4D ( x , y , z , 1 ) ,
141
138
] ;
142
139
} ) ;
143
140
@@ -191,17 +188,17 @@ const sketch = ({ context, width, height, render }) => {
191
188
// }
192
189
193
190
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" ;
196
193
context . fillRect ( 0 , 0 , width , height ) ;
197
194
198
195
context . save ( ) ;
199
196
context . translate ( width / 2 , height / 2 ) ;
200
197
const scale = width / 2 ;
201
198
context . scale ( scale , scale ) ;
202
199
203
- context . lineJoin = ' round' ;
204
- context . lineCap = ' round' ;
200
+ context . lineJoin = " round" ;
201
+ context . lineCap = " round" ;
205
202
206
203
// polylines(lines, {
207
204
// stroke: 'black',
@@ -234,8 +231,10 @@ const sketch = ({ context, width, height, render }) => {
234
231
polyline ( line , {
235
232
// fill: 'black',
236
233
// 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 ,
239
238
} ) ;
240
239
}
241
240
0 commit comments