Skip to content

Commit ac9c6e1

Browse files
committed
fix(CompassNeedleResponse): adjust spring characteristics and destination
1 parent a836eb0 commit ac9c6e1

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/components/CompassNeedleResponse.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,35 @@ function CompassNeedleResponse (props) {
2424
const responseEmojis = randomNumbers.map((num) => symbols[num])
2525
const rotateDirection = Math.round(random()) ? 1 : -1
2626
const rotateQuantity = Math.ceil(random()) // a number between 2 and 3 inclusive
27-
const rotateTo = getRotation(randomNumbers[0], numberOfSymbols) + (360 * rotateQuantity * rotateDirection)
27+
const rotateTo = getRotation(randomNumbers[0], numberOfSymbols)
28+
29+
// calc rotate to: if diff between current and destination is less than
30+
// one full rotation, then add a full rotation.
31+
let actualRotateTo = rotateTo
32+
if (rotateDirection === -1) {
33+
actualRotateTo = rotateTo - 360
34+
}
35+
if (Math.abs(initialRotation - actualRotateTo) < 360) {
36+
if (initialRotation > actualRotateTo) {
37+
actualRotateTo = actualRotateTo - 360
38+
} else {
39+
actualRotateTo = actualRotateTo + 360
40+
}
41+
}
2842

2943
const spring = useSpring({
3044
from: {
3145
rotate: initialRotation,
3246
transform: `rotate(${initialRotation}deg)`
3347
},
3448
to: {
35-
rotate: rotateTo,
36-
transform: `rotate(${rotateTo}deg)`
49+
rotate: actualRotateTo,
50+
transform: `rotate(${actualRotateTo}deg)`
3751
},
3852
config: {
39-
mass: 10,
40-
tension: 160,
41-
friction: 60,
53+
mass: 1,
54+
tension: 15,
55+
friction: 6,
4256
}
4357
})
4458

0 commit comments

Comments
 (0)