@@ -98,37 +98,46 @@ ctx.stroke(path);
98
98
const ctx = /* ... */ ;
99
99
const animation = blobs2Animate .canvasPath ();
100
100
101
- TODO wiggle
102
-
103
- // Set up "requestAnimationFrame" rendering loop.
101
+ // Set up rendering loop.
104
102
const renderAnimation = () => {
105
103
ctx .clearRect (0 , 0 , width, height);
106
104
ctx .fill (animation .renderFrame ());
107
105
requestAnimationFrame (renderAnimation);
108
106
};
109
107
requestAnimationFrame (renderAnimation);
110
108
111
- // Keyframe loop .
112
- const loopAnimation = () => {
109
+ // Transition to new blob on canvas click .
110
+ ctx . canvas . onclick = () => {
113
111
animation .transition ({
114
112
duration: 4000 ,
115
113
timingFunction: " ease" ,
116
114
callback: loopAnimation,
117
115
blobOptions: {... },
118
116
});
119
117
};
118
+ ```
120
119
121
- // Initial frame.
122
- animation .transition ({
123
- duration: 0 , // Render immediately.
124
- callback: loopAnimation,
125
- blobOptions: {... },
126
- });
120
+ ## Canvas Wiggle
127
121
128
- // Toggle play/pause animation on canvas click.
129
- ctx .canvas .onclick = () => {
130
- animation .playPause ();
122
+ ``` js
123
+ const ctx = /* ... */ ;
124
+ const animation = blobs2Animate .canvasPath ();
125
+
126
+ // Set up rendering loop.
127
+ const renderAnimation = () => {
128
+ ctx .clearRect (0 , 0 , width, height);
129
+ ctx .fill (animation .renderFrame ());
130
+ requestAnimationFrame (renderAnimation);
131
131
};
132
+ requestAnimationFrame (renderAnimation);
133
+
134
+ // Begin wiggle animation.
135
+ blobs2Animate .wigglePreset (
136
+ animation
137
+ /* blobOptions= */ {... },
138
+ /* canvasOptions= */ {},
139
+ /* wiggleOptions= */ {speed: 2 },
140
+ )
132
141
```
133
142
134
143
## Complete API
0 commit comments