@@ -259,53 +259,65 @@ const loopBetween = (percentage: number, a: Point[], b: Point[]): Point[] => {
259259 }
260260} ;
261261
262- const genAnimation = ( speed : number ) : blobs2Animate . CanvasAnimation => {
262+ const genAnimation = ( speed : number , offset : number , timing : blobs2Animate . CanvasKeyframe [ "timingFunction" ] ) => {
263263 const animation = blobs2Animate . canvasPath ( ) ;
264264
265265 const loopAnimation = ( ) => {
266266 animation . transition (
267267 {
268268 duration : speed ,
269269 delay : speed ,
270- timingFunction : "easeInOut " ,
270+ timingFunction : "ease " ,
271271 blobOptions : {
272272 extraPoints : 3 ,
273273 randomness : 4 ,
274274 seed : Math . random ( ) ,
275275 size : 200 ,
276276 } ,
277+ canvasOptions : {
278+ offsetX : offset ,
279+ } ,
277280 } ,
278281 {
279282 duration : speed ,
280- timingFunction : "easeInOut " ,
283+ timingFunction : "ease " ,
281284 blobOptions : {
282285 extraPoints : 3 ,
283286 randomness : 4 ,
284287 seed : Math . random ( ) ,
285288 size : 200 ,
286289 } ,
290+ canvasOptions : {
291+ offsetX : offset ,
292+ } ,
287293 } ,
288294 {
289295 duration : speed ,
290296 delay : speed ,
291- timingFunction : "easeInOut " ,
297+ timingFunction : "ease " ,
292298 blobOptions : {
293299 extraPoints : 3 ,
294300 randomness : 4 ,
295301 seed : Math . random ( ) ,
296302 size : 200 ,
297303 } ,
304+ canvasOptions : {
305+ offsetX : offset ,
306+ } ,
298307 } ,
299308 {
300309 duration : speed ,
301310 callback : loopAnimation ,
302- timingFunction : "easeInOut " ,
311+ timingFunction : "ease " ,
303312 blobOptions : {
304313 extraPoints : 39 ,
305314 randomness : 2 ,
306315 seed : Math . random ( ) ,
307316 size : 200 ,
308317 } ,
318+ canvasOptions : {
319+ offsetX : offset ,
320+ } ,
309321 } ,
310322 ) ;
311323 } ;
@@ -319,21 +331,26 @@ const genAnimation = (speed: number): blobs2Animate.CanvasAnimation => {
319331 seed : 0 ,
320332 size : 200 ,
321333 } ,
334+ canvasOptions : {
335+ offsetX : offset ,
336+ } ,
322337 } ) ;
323338
339+ const oldOnclick = interact . onclick || ( ( ) => 0 ) ;
324340 interact . onclick = ( ) => {
341+ oldOnclick ( ) ;
325342 animation . transition ( {
326- duration : 400 ,
343+ duration : speed ,
327344 callback : loopAnimation ,
328- timingFunction : "elasticIn0" ,
345+ timingFunction : timing ,
329346 blobOptions : {
330- extraPoints : 3 ,
347+ extraPoints : 30 ,
331348 randomness : 8 ,
332349 seed : Math . random ( ) ,
333350 size : 180 ,
334351 } ,
335352 canvasOptions : {
336- offsetX : 10 ,
353+ offsetX : 10 + offset ,
337354 offsetY : 10 ,
338355 } ,
339356 } ) ;
@@ -345,7 +362,12 @@ const genAnimation = (speed: number): blobs2Animate.CanvasAnimation => {
345362( ( ) => {
346363 let percentage = animationStart ;
347364
348- const animation = genAnimation ( 1000 ) ;
365+ const animations = [
366+ genAnimation ( 1000 , 0 , "elasticEnd0" ) ,
367+ genAnimation ( 1000 , 200 , "elasticEnd1" ) ,
368+ genAnimation ( 1000 , 400 , "elasticEnd2" ) ,
369+ genAnimation ( 1000 , 600 , "elasticEnd3" ) ,
370+ ] ;
349371
350372 const renderFrame = ( ) => {
351373 clear ( ctx ) ;
@@ -362,7 +384,9 @@ const genAnimation = (speed: number): blobs2Animate.CanvasAnimation => {
362384 testPrepPointsD ( percentage ) ;
363385 testPrepLetters ( percentage ) ;
364386
365- ctx . fill ( animation . renderFrame ( ) ) ;
387+ for ( const animation of animations ) {
388+ ctx . fill ( animation . renderFrame ( ) ) ;
389+ }
366390
367391 percentage += animationSpeed / 1000 ;
368392 percentage = mod ( percentage , 1 ) ;
0 commit comments