File tree Expand file tree Collapse file tree 1 file changed +24
-11
lines changed Expand file tree Collapse file tree 1 file changed +24
-11
lines changed Original file line number Diff line number Diff line change @@ -34,26 +34,39 @@ const renderFrame = () => {
3434} ;
3535requestAnimationFrame ( renderFrame ) ;
3636
37+ // Extra points that increases when blob gets clicked.
38+ let extraPoints = 0 ;
39+
3740// Generate a keyframe with overridable default values.
38- const genFrame = ( overrides : Partial < CanvasKeyframe > = { } ) : CanvasKeyframe => ( {
39- duration : 4000 ,
40- timingFunction : "ease" ,
41- callback : loopAnimation ,
42- blobOptions : {
43- extraPoints : 3 ,
41+ const genFrame = ( overrides : any = { } ) : CanvasKeyframe => {
42+ const blobOptions = {
43+ extraPoints : 3 + extraPoints ,
4444 randomness : 4 ,
4545 seed : Math . random ( ) ,
4646 size,
47- } ,
48- ...overrides ,
49- } ) ;
47+ ...overrides . blobOptions ,
48+ } ;
49+ return {
50+ duration : 4000 ,
51+ timingFunction : "ease" ,
52+ callback : loopAnimation ,
53+ ...overrides ,
54+ blobOptions,
55+ } ;
56+ } ;
5057
5158// Callback for every frame which starts transition to a new frame.
52- const loopAnimation = ( ) : void => animation . transition ( genFrame ( ) ) ;
59+ const loopAnimation = ( ) : void => {
60+ extraPoints = 0 ;
61+ animation . transition ( genFrame ( ) ) ;
62+ } ;
5363
5464// Quickly animate to a new frame when canvas is clicked.
5565canvas . onclick = ( ) => {
56- animation . transition ( genFrame ( { duration : 400 , timingFunction : "elasticEnd0" } ) ) ;
66+ extraPoints ++ ;
67+ animation . transition (
68+ genFrame ( { duration : 400 , timingFunction : "elasticEnd0" , blobOptions : { extraPoints} } ) ,
69+ ) ;
5770} ;
5871
5972// Immediately show a new frame.
You can’t perform that action at this time.
0 commit comments