|
4 | 4 | //
|
5 | 5 | // Example usage:
|
6 | 6 | //
|
7 |
| -// // Run once to initialize. Note the FPS. |
8 |
| -// spring := NewSpring(FPS60, 0.8, 1.0) |
| 7 | +// // Run once to initialize. |
| 8 | +// spring := NewSpring(FPS(60), 0.8, 1.0) |
9 | 9 | //
|
10 | 10 | // // Update on every frame.
|
11 | 11 | // pos := 0.0
|
@@ -55,22 +55,16 @@ import (
|
55 | 55 | "time"
|
56 | 56 | )
|
57 | 57 |
|
58 |
| -// Standard time deltas that can be used when initializing a spring. |
59 |
| -const ( |
60 |
| - FPS60 = float64(int64(time.Second/60)) / float64(int64(time.Second)) |
61 |
| - FPS30 = float64(int64(time.Second/30)) / float64(int64(time.Second)) |
62 |
| -) |
63 |
| - |
64 |
| -// TimeDelta returns a time delta for a given FPS. This is usefaul for setting |
65 |
| -// the time delta when initializing a Spring. |
| 58 | +// FPS returns a time delta for a given number of frames per second. This value |
| 59 | +// can be used as the time delta when initializing a Spring. |
66 | 60 | //
|
67 | 61 | // Example:
|
68 | 62 | //
|
69 |
| -// delta := TimeDelta(time.Second/60) |
70 |
| -// spring := New(delta, 0.98, 0.8) |
| 63 | +// spring := NewSpring(FPS(60), 0.8, 0.98) |
71 | 64 | //
|
72 |
| -func TimeDelta(fps time.Duration) float64 { |
73 |
| - return float64(int64(fps)) / float64(int64(time.Second)) |
| 65 | +func FPS(n int) float64 { |
| 66 | + d := time.Second / time.Duration(n) |
| 67 | + return float64(int64(d)) / float64(int64(time.Second)) |
74 | 68 | }
|
75 | 69 |
|
76 | 70 | // In calculus ε is (in vague terms) an arbitrarily small positive number. In
|
|
0 commit comments