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 = () => {
34
34
} ;
35
35
requestAnimationFrame ( renderFrame ) ;
36
36
37
+ // Extra points that increases when blob gets clicked.
38
+ let extraPoints = 0 ;
39
+
37
40
// 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 ,
44
44
randomness : 4 ,
45
45
seed : Math . random ( ) ,
46
46
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
+ } ;
50
57
51
58
// 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
+ } ;
53
63
54
64
// Quickly animate to a new frame when canvas is clicked.
55
65
canvas . onclick = ( ) => {
56
- animation . transition ( genFrame ( { duration : 400 , timingFunction : "elasticEnd0" } ) ) ;
66
+ extraPoints ++ ;
67
+ animation . transition (
68
+ genFrame ( { duration : 400 , timingFunction : "elasticEnd0" , blobOptions : { extraPoints} } ) ,
69
+ ) ;
57
70
} ;
58
71
59
72
// Immediately show a new frame.
You can’t perform that action at this time.
0 commit comments