-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathnoise-circle.js
82 lines (73 loc) Β· 1.91 KB
/
noise-circle.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const canvasSketch = require('canvas-sketch');
const lerp = require('lerp');
const SimplexNoise = require('simplex-noise');
const getCurvePoints = require('cardinal-spline-js/').getCurvePoints;
const { curve } = require('cardinal-spline-js/curve_func.min');
const R = require('ramda');
const { range } = require('./math');
const { translate, drawShape, arcs } = require('./geometry');
const simplex = new SimplexNoise('1234567890abcdefghijklmnopqrstuvwxyz');
const settings = {
animate: true,
duration: 8,
dimensions: [800, 800],
scaleToView: true,
// playbackRate: 'throttle',
// fps: 8,
};
canvasSketch(() => {
const opts = {
segmentCount: 360,
timeLoops: 4,
loop: true,
displacement: 0.125 / 8,
radius: {
start: 0.3,
delta: 0.05,
},
};
let time = 0;
return ({ context, frame, width, height, playhead }) => {
// clear
context.clearRect(0, 0, width, height);
context.fillStyle = '#fff';
context.fillRect(0, 0, width, height);
// Setup
time += 0.025; // Math.sin(playhead * opts.timeLoops * Math.PI);
const circle = generateCircle(width, height, time, playhead, opts)(
width * opts.radius.start,
);
// Draw
context.lineWidth = width * 0.002;
context.strokeStyle = '#666';
drawShape(context, circle, true);
context.stroke();
};
}, settings);
function generateCircle(
width,
height,
time,
playhead,
{ segmentCount, displacement, loop },
) {
return R.pipe(
radius => arcs(segmentCount, radius),
R.map(displacePt(displacement, loop, time, playhead, segmentCount)),
R.map(translate([width / 2, height / 2])),
);
}
function displacePt(displacement, loop, time, playhead, segmentCount) {
return ({ r, theta }, idx) => ({
r:
r +
r *
displacement *
simplex.noise3D(
Math.cos(theta),
Math.sin(theta),
loop ? time : playhead,
),
theta,
});
}