-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtweens.brs
758 lines (688 loc) · 27.4 KB
/
tweens.brs
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
'IMPORTS=
' ******************************************************
' Copyright Steven Kean 2010-2015
' All Rights Reserved.
' ******************************************************
Function CreateTweenObject(start_data as object, dest_data as object, duration as integer, tween as string)
tween_data = {
start: {}
current: {}
dest: {}
duration: duration
timer: invalid
tween: tween
}
for each key in start_data
tween_data.start[key] = start_data[key]
tween_data.current[key] = start_data[key]
end for
for each key in dest_data
tween_data.dest[key] = dest_data[key]
end for
tween_data.timer = CreateObject_GameTimespan()
return tween_data
End Function
Function GetTweenObjectPercentState(tween_object as object)
key = invalid
largest_start_dest_difference = 0
for each k in tween_object.start
start_dest_difference = (tween_object.start[k] - tween_object.dest[k])
if start_dest_difference > largest_start_dest_difference
largest_start_dest_difference = start_dest_difference
key = k
end if
end for
if (tween_object.start[key] - tween_object.dest[key]) = 0
return 1.0
end if
if key = invalid
return 0
end if
return (tween_object.start[key] - tween_object.current[key]) / (tween_object.start[key] - tween_object.dest[key])
End Function
Function HandleTween(tween_data)
' Example
' m.movement_data = {
' start: {x: x, y: y}
' current: {x: x, y: y}
' dest: {x: x, y: y}
' duration: 90
' timer: CreateObject("roTimespan")
' tween: "LinearTween"
' }
tween = "LinearTween"
if tween_data.DoesExist("tween")
tween = tween_data.tween
end if
current_time = tween_data.timer.TotalMilliseconds()
for each key in tween_data.start
tween_data.current[key] = m.tweens[tween](tween_data.start[key], tween_data.dest[key], current_time, tween_data.duration)
end for
return current_time >= tween_data.duration
End Function
Function ChangeTweenDest(tween_data, dest_data)
tween_data.timer.Mark()
for each key in dest_data
tween_data.start[key] = tween_data.current[key]
tween_data.dest[key] = dest_data[key]
end for
End Function
Function GetTweens() As Object
If m.tweens = invalid Then
m.tweens = {
LinearTween: LinearTween
QuadraticTween: QuadraticTween
QuadraticEaseIn: QuadraticEaseIn
QuadraticEaseOut: QuadraticEaseOut
QuadraticEaseInOut: QuadraticEaseInOut
QuadraticEaseOutIn: QuadraticEaseOutIn
SquareTween: SquareTween
SquareEaseIn: SquareEaseIn
SquareEaseOut: SquareEaseOut
SquareEaseInOut: SquareEaseInOut
SquareEaseOutIn: SquareEaseOutIn
CubicTween: CubicTween
CubicEaseIn: CubicEaseIn
CubicEaseOut: CubicEaseOut
CubicEaseInOut: CubicEaseInOut
CubicEaseOutIn: CubicEaseOutIn
QuarticTween: QuarticTween
QuarticEaseIn: QuarticEaseIn
QuarticEaseOut: QuarticEaseOut
QuarticEaseInOut: QuarticEaseInOut
QuarticEaseOutIn: QuarticEaseOutIn
QuinticTween: QuinticTween
QuinticEaseIn: QuinticEaseIn
QuinticEaseOut: QuinticEaseOut
QuinticEaseInOut: QuinticEaseInOut
QuinticEaseOutIn: QuinticEaseOutIn
SinusoidalTween: SinusoidalTween
SinusoidalEaseIn: SinusoidalEaseIn
SinusoidalEaseOut: SinusoidalEaseOut
SinusoidalEaseInOut: SinusoidalEaseInOut
SinusoidalEaseOutIn: SinusoidalEaseOutIn
ExponentialTween: ExponentialTween
ExponentialEaseIn: ExponentialEaseIn
ExponentialEaseOut: ExponentialEaseOut
ExponentialEaseInOut: ExponentialEaseInOut
ExponentialEaseOutIn: ExponentialEaseOutIn
CircularTween: CircularTween
CircularEaseIn: CircularEaseIn
CircularEaseOut: CircularEaseOut
CircularEaseInOut: CircularEaseInOut
CircularEaseOutIn: CircularEaseOutIn
ElasticTween: ElasticTween
ElasticEaseIn: ElasticEaseIn
ElasticEaseOut: ElasticEaseOut
ElasticEaseInOut: ElasticEaseInOut
ElasticEaseOutIn: ElasticEaseOutIn
OvershootTween: OvershootTween
OvershootEaseIn: OvershootEaseIn
OvershootEaseOut: OvershootEaseOut
OvershootEaseInOut: OvershootEaseInOut
OvershootEaseOutIn: OvershootEaseOutIn
BounceTween: BounceTween
BounceEaseIn: BounceEaseIn
BounceEaseOut: BounceEaseOut
BounceEaseInOut: BounceEaseInOut
BounceEaseOutIn: BounceEaseOutIn
}
End If
Return m.tweens
End Function
Function LinearTween(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' c*t/d + b
time = currentTime / duration
Return change * time + start
End Function
' ****************
' Quadratic
' ****************
Function QuadraticTween(start, finish, currentTime, duration)
Return QuadraticEaseInOut(start, finish, currentTime, duration)
End Function
Function QuadraticEaseIn(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' c*(t/=d)*t + b
time = currentTime / duration
Return change * time * time + start
End Function
Function QuadraticEaseOut(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' -c *(t/=d)*(t-2) + b
time = currentTime / duration
Return -change * time * (time - 2) + start
End Function
Function QuadraticEaseInOut(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' if ((t/=d/2) < 1) return c/2*t*t + b;
' return -c/2 * ((--t)*(t-2) - 1) + b;
time = currentTime / (duration / 2)
If time < 1 Then
Return change / 2 * time * time + start
Else
time = time - 1
Return -change / 2 * (time * (time - 2) - 1) + start
End If
End Function
Function QuadraticEaseOutIn(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
If currentTime < duration / 2 Then
Return QuadraticEaseOut(0, change, currentTime * 2, duration) * .5 + start
Else
Return QuadraticEaseIn(0, change, currentTime * 2 - duration, duration) * .5 + (change * .5) + start
End If
End Function
' ****************
' Square
' ****************
Function SquareTween(start, finish, currentTime, duration)
Return SquareEaseInOut(start, finish, currentTime, duration)
End Function
Function SquareEaseIn(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' c*(t/=d)*t*t*t + b
time = currentTime / duration
Return change * time * time + start
End Function
Function SquareEaseOut(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' -c * ((t=t/d-1)*t*t*t - 1) + b
time = (currentTime / duration) - 1
Return -change * (time * time - 1) + start
End Function
Function SquareEaseInOut(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
' return -c/2 * ((t-=2)*t*t*t - 2) + b;
time = currentTime / (duration / 2)
If time < 1 Then
Return change / 2 * time * time + start
Else
time = time - 2
Return -change / 2 * (time * time - 2) + start
End If
End Function
Function SquareEaseOutIn(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
If currentTime < duration / 2 Then
Return SquareEaseOut(0, change, currentTime * 2, duration) * .5 + start
Else
Return SquareEaseIn(0, change, currentTime * 2 - duration, duration) * .5 + (change * .5) + start
End If
End Function
' ****************
' Cubic
' ****************
Function CubicTween(start, finish, currentTime, duration)
Return CubicEaseInOut(start, finish, currentTime, duration)
End Function
Function CubicEaseIn(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' c*(t/=d)*t*t + b
time = currentTime / duration
Return change * time * time * time + start
End Function
Function CubicEaseOut(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' c*((t=t/d-1)*t*t + 1) + b
time = (currentTime / duration) - 1
Return change * (time * time * time + 1) + start
End Function
Function CubicEaseInOut(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' if ((t/=d/2) < 1) return c/2*t*t*t + b;
' return c/2*((t-=2)*t*t + 2) + b
time = currentTime / (duration / 2)
If time < 1 Then
Return change / 2 * time * time * time + start
Else
time = time - 2
Return change / 2 * (time * time * time + 2) + start
End If
End Function
Function CubicEaseOutIn(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
If currentTime < duration / 2 Then
Return CubicEaseOut(0, change, currentTime * 2, duration) * .5 + start
Else
Return CubicEaseIn(0, change, currentTime * 2 - duration, duration) * .5 + (change * .5) + start
End If
End Function
' ****************
' Quartic
' ****************
Function QuarticTween(start, finish, currentTime, duration)
Return QuarticEaseInOut(start, finish, currentTime, duration)
End Function
Function QuarticEaseIn(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' c*(t/=d)*t*t*t + b
time = currentTime / duration
Return change * time * time * time * time + start
End Function
Function QuarticEaseOut(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' -c * ((t=t/d-1)*t*t*t - 1) + b
time = (currentTime / duration) - 1
Return -change * (time * time * time * time - 1) + start
End Function
Function QuarticEaseInOut(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
' return -c/2 * ((t-=2)*t*t*t - 2) + b;
time = currentTime / (duration / 2)
If time < 1 Then
Return change / 2 * time * time * time * time + start
Else
time = time - 2
Return -change / 2 * (time * time * time * time - 2) + start
End If
End Function
Function QuarticEaseOutIn(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
If currentTime < duration / 2 Then
Return QuarticEaseOut(0, change, currentTime * 2, duration) * .5 + start
Else
Return QuarticEaseIn(0, change, currentTime * 2 - duration, duration) * .5 + (change * .5) + start
End If
End Function
' ****************
' Quintic
' ****************
Function QuinticTween(start, finish, currentTime, duration)
Return QuinticEaseInOut(start, finish, currentTime, duration)
End Function
Function QuinticEaseIn(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' c*(t/=d)*t*t*t*t + b
time = currentTime / duration
Return change * time * time * time * time * time + start
End Function
Function QuinticEaseOut(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' c*((t=t/d-1)*t*t*t*t + 1) + b
time = (currentTime / duration) - 1
Return change * (time * time * time * time * time + 1) + start
End Function
Function QuinticEaseInOut(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
' return c/2*((t-=2)*t*t*t*t + 2) + b;
time = currentTime / (duration / 2)
If time < 1 Then
Return change / 2 * time * time * time * time * time + start
Else
time = time - 2
Return change / 2 * (time * time * time * time * time + 2) + start
End If
End Function
Function QuinticEaseOutIn(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
If currentTime < duration / 2 Then
Return QuinticEaseOut(0, change, currentTime * 2, duration) * .5 + start
Else
Return QuinticEaseIn(0, change, currentTime * 2 - duration, duration) * .5 + (change * .5) + start
End If
End Function
' ****************
' Sinusoidal
' ****************
Function SinusoidalTween(start, finish, currentTime, duration)
Return SinusoidalEaseInOut(start, finish, currentTime, duration)
End Function
Function SinusoidalEaseIn(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
pi = 3.1415926535897932384626433832795
change = finish - start
' -c * Math.cos(t/d * (Math.PI/2)) + c + b
time = currentTime / duration
Return -change * Cos(time * (pi / 2)) + change + start
End Function
Function SinusoidalEaseOut(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
pi = 3.1415926535897932384626433832795
change = finish - start
' c * Math.sin(t/d * (Math.PI/2)) + b
time = currentTime / duration
Return change * Sin(time * (pi / 2)) + start
End Function
Function SinusoidalEaseInOut(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
pi = 3.1415926535897932384626433832795
change = finish - start
' -c/2 * (Math.cos(Math.PI*t/d) - 1) + b
time = currentTime / duration
Return -change / 2 * (Cos(pi * time) - 1) + start
End Function
Function SinusoidalEaseOutIn(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
If currentTime < duration / 2 Then
Return SinusoidalEaseOut(0, change, currentTime * 2, duration) * .5 + start
Else
Return SinusoidalEaseIn(0, change, currentTime * 2 - duration, duration) * .5 + (change * .5) + start
End If
End Function
' ****************
' Exponential
' ****************
Function ExponentialTween(start, finish, currentTime, duration)
Return ExponentialEaseInOut(start, finish, currentTime, duration)
End Function
Function ExponentialEaseIn(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b
If currentTime = 0 Then
Return start
Else
Return change * (2 ^ (10 * (currentTime / duration - 1))) + start
End If
End Function
Function ExponentialEaseOut(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b
If currentTime = duration Then
Return start + change
Else
Return change * (-(2 ^ (-10 * currentTime / duration)) + 1) + start
End If
End Function
Function ExponentialEaseInOut(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' if (t==0) return b;
' if (t==d) return b+c;
' if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
' return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
time = currentTime / (duration / 2)
If currentTime = 0 Then
Return start
Else If currentTime = duration Then
Return start + change
Else If time < 1 Then
Return change / 2 * (2 ^ (10 * (time - 1))) + start
Else
time = time - 1
Return change / 2 * (-(2 ^ (-10 * time)) + 2) + start
End If
End Function
Function ExponentialEaseOutIn(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' if (t==0) return b;
' if (t==d) return b+c;
' if ((t/=d/2) < 1) return c/2 * (-Math.pow(2, -10 * t/1) + 1) + b;
' return c/2 * (Math.pow(2, 10 * (t-2)/1) + 1) + b;
time = currentTime / (duration / 2)
If currentTime = 0 Then
Return start
Else If currentTime = duration Then
Return start + change
Else If time < 1 Then
Return change / 2 * (-(2 ^ (-10 * time / 1)) + 1) + start
Else
Return change / 2 * (2 ^ (10 * (time - 2) / 1) + 1) + start
End If
End Function
' ****************
' Circular
' ****************
Function CircularTween(start, finish, currentTime, duration)
Return CircularEaseInOut(start, finish, currentTime, duration)
End Function
Function CircularEaseIn(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b
time = currentTime / duration
Return -change * (Sqr(1 - time * time) - 1) + start
End Function
Function CircularEaseOut(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' c * Math.sqrt(1 - (t=t/d-1)*t) + b
time = (currentTime / duration) - 1
Return change * Sqr(1 - time * time) + start
End Function
Function CircularEaseInOut(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
' return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
time = currentTime / (duration / 2)
If time < 1 Then
Return -change / 2 * (Sqr(1 - time * time) - 1) + start
Else
time = time - 2
Return change / 2 * (Sqr(1 - time * time) + 1) + start
End If
End Function
Function CircularEaseOutIn(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
If currentTime < duration / 2 Then
Return CircularEaseOut(0, change, currentTime * 2, duration) * .5 + start
Else
Return CircularEaseIn(0, change, currentTime * 2 - duration, duration) * .5 + (change * .5) + start
End If
End Function
' ****************
' Elastic
' ****************
Function ElasticTween(start, finish, currentTime, duration)
Return ElasticEaseInOut(start, finish, currentTime, duration)
End Function
Function ElasticEaseIn(start, finish, currentTime, duration, amplitude = invalid As Dynamic, period = invalid As Dynamic)
If currentTime > duration Or duration = 0 Then Return finish
pi = 3.1415926535897932384626433832795
change = finish - start
' if (t==0) return b;
' if ((t/=d)==1) return b+c;
' if (!p) p=d*.3;
' if (!a || a < Math.abs(c)) { a=c; var s=p/4; }
' else var s = p/(2*Math.PI) * Math.asin (c/a);
' return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
time = currentTime / duration
If currentTime = 0 Then
Return start
Else If time = 1 Then
Return start + change
End If
If period = invalid Then
period = duration * .3
End If
speed = period / 4
If amplitude = invalid Or amplitude < Abs(change) Then
amplitude = change
Else
speed = period / (2 * pi) * Asin(change / amplitude)
End If
time = time - 1
Return -(amplitude * (2 ^ (10 * time)) * Sin((time * duration - speed) * (2 * pi) / period)) + start
End Function
Function ElasticEaseOut(start, finish, currentTime, duration, amplitude = invalid As Dynamic, period = invalid As Dynamic)
If currentTime > duration Or duration = 0 Then Return finish
pi = 3.1415926535897932384626433832795
change = finish - start
' if (t==0) return b;
' if ((t/=d)==1) return b+c;
' if (!p) p=d*.3;
' if (!a || a < Math.abs(c)) { a=c; var s=p/4; }
' else var s = p/(2*Math.PI) * Math.asin (c/a);
' return (a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b);
time = currentTime / duration
If currentTime = 0 Then
Return start
Else If time = 1 Then
Return start + change
End If
If period = invalid Then
period = duration * .3
End If
speed = period / 4
If amplitude = invalid Or amplitude < Abs(change) Then
amplitude = change
Else
speed = period / (2 * pi) * Asin(change / amplitude)
End If
Return (amplitude * (2 ^ (-10 * time)) * Sin((time * duration - speed) * (2 * pi) / period) + change + start)
End Function
Function ElasticEaseInOut(start, finish, currentTime, duration, amplitude = invalid As Dynamic, period = invalid As Dynamic)
If currentTime > duration Or duration = 0 Then Return finish
pi = 3.1415926535897932384626433832795
change = finish - start
' if (t==0) return b;
' if ((t/=d/2)==2) return b+c;
' if (!p) p=d*(.3*1.5);
' if (!a || a < Math.abs(c)) { a=c; var s=p/4; }
' else var s = p/(2*Math.PI) * Math.asin (c/a);
' if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
' return (a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b);
time = currentTime / (duration / 2)
If currentTime = 0 Then
Return start
Else If time = 2 Then
Return start + change
End If
If period = invalid Then
period = duration * (.3 * 1.5)
End If
speed = period / 4
If amplitude = invalid Or amplitude < Abs(change) Then
amplitude = change
Else
speed = period / (2 * pi) * Asin(change / amplitude)
End If
time = time - 1
If time < 0 Then
Return -.5 * (amplitude * (2 ^ (10 * time)) * Sin((time * duration - speed) * (2 * pi) / period)) + start
Else
Return (amplitude * (2 ^ (-10 * time)) * Sin((time * duration - speed) * (2 * pi) / period) * .5 + change + start)
End If
End Function
Function ElasticEaseOutIn(start, finish, currentTime, duration, amplitude = invalid As Dynamic, period = invalid As Dynamic)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
If currentTime < duration / 2 Then
Return ElasticEaseOut(0, change, currentTime * 2, duration, amplitude, period) * .5 + start
Else
Return ElasticEaseIn(0, change, currentTime * 2 - duration, duration, amplitude, period) * .5 + (change * .5) + start
End If
End Function
' ****************
' Overshoot
' ****************
Function OvershootTween(start, finish, currentTime, duration)
Return OvershootEaseInOut(start, finish, currentTime, duration)
End Function
Function OvershootEaseIn(start, finish, currentTime, duration, overshoot = 1.70158 As Float)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' if (s == undefined) s = 1.70158;
' return c*(t/=d)*t*((s+1)*t - s) + b;
time = currentTime / duration
Return change * time * time * ((overshoot + 1) * time - overshoot) + start
End Function
Function OvershootEaseOut(start, finish, currentTime, duration, overshoot = 1.70158 As Float)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' if (s == undefined) s = 1.70158;
' return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
time = (currentTime / duration) - 1
Return change * (time * time * ((overshoot + 1) * time + overshoot) + 1) + start
End Function
Function OvershootEaseInOut(start, finish, currentTime, duration, overshoot = 1.70158 As Float)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
' if (s == undefined) s = 1.70158;
' if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
' return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b
time = currentTime / (duration / 2)
overshoot = overshoot * 1.525
If time < 1 Then
Return change / 2 * (time * time * ((overshoot + 1) * time - overshoot)) + start
Else
time = time - 2
Return change / 2 * (time * time * ((overshoot + 1) * time + overshoot) + overshoot) + start
End If
End Function
Function OvershootEaseOutIn(start, finish, currentTime, duration, overshoot = 1.70158 As Float)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
If currentTime < duration / 2 Then
Return OvershootEaseOut(0, change, currentTime * 2, duration, overshoot) * .5 + start
Else
Return OvershootEaseIn(0, change, currentTime * 2 - duration, duration, overshoot) * .5 + (change * .5) + start
End If
End Function
' ****************
' Bounce
' ****************
Function BounceTween(start, finish, currentTime, duration)
Return BounceEaseInOut(start, finish, currentTime, duration)
End Function
Function BounceEaseIn(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
Return change - BounceEaseOut(0, change, duration - currentTime, duration) + start
End Function
Function BounceEaseOut(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
time = currentTime / duration
If time < (1 / 2.75) Then
Return change * (7.5625 * time * time) + start
Else If time < (2 / 2.75) Then
time = time - (1.5 / 2.75)
Return change * (7.5625 * time * time + .75) + start
Else If time < (2.5 / 2.75) Then
time = time - (2.25 / 2.75)
Return change * (7.5625 * time * time + .9375) + start
Else
time = time - (2.625 / 2.75)
Return change * (7.5625 * time * time + .984375) + start
End If
End Function
Function BounceEaseInOut(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
If currentTime < duration / 2 Then
Return BounceEaseIn(0, change, currentTime * 2, duration) * .5 + start
Else
Return BounceEaseOut(0, change, currentTime * 2 - duration, duration) * .5 + (change * .5) + start
End If
End Function
Function BounceEaseOutIn(start, finish, currentTime, duration)
If currentTime > duration Or duration = 0 Then Return finish
change = finish - start
If currentTime < duration / 2 Then
Return BounceEaseOut(0, change, currentTime * 2, duration) * .5 + start
Else
Return BounceEaseIn(0, change, currentTime * 2 - duration, duration) * .5 + (change * .5) + start
End If
End Function