diff options
author | Joris Guyonvarch | 2015-03-05 22:55:06 +0100 |
---|---|---|
committer | Joris Guyonvarch | 2015-03-05 22:55:11 +0100 |
commit | 716ce85464ee6d57a424a00d2535b3c2ce6ad9cb (patch) | |
tree | 01728db59af133a94855e536a25d6c5073bbfa38 | |
parent | 2fe50fd2ebb1815a330b20e599f756fa393de81b (diff) |
Adding a wave move
-rw-r--r-- | src/CloudStep.elm | 4 | ||||
-rw-r--r-- | src/Physics.elm | 9 | ||||
-rw-r--r-- | src/Vec2.elm | 9 |
3 files changed, 20 insertions, 2 deletions
diff --git a/src/CloudStep.elm b/src/CloudStep.elm index 033c3c5..e6bfc96 100644 --- a/src/CloudStep.elm +++ b/src/CloudStep.elm @@ -8,7 +8,7 @@ import Geometry (..) import Player (..) import Board (boardSize, boardDiagonal) import Point (..) -import Physics (getMove) +import Physics (getMove, getWaveMove) import Cloud (..) import Config (..) @@ -61,7 +61,7 @@ getNewPoint time seed = , initDest = initDest , move initTime initPos initDest time = let delta = time - initTime - move = getMove (pointSpeed delta) (initDest `sub` initPos) + move = getWaveMove (pointSpeed delta) (initDest `sub` initPos) 10 10 in initPos `add` move } , seed'' diff --git a/src/Physics.elm b/src/Physics.elm index 2d2d627..c68ab58 100644 --- a/src/Physics.elm +++ b/src/Physics.elm @@ -22,6 +22,15 @@ getMove speed dir = , y = speed * sin angle } +getWaveMove : Float -> Vec2 -> Float -> Float -> Vec2 +getWaveMove speed dir amplitude period = + let move = getMove speed dir + perpendMove = + getMove + (amplitude * (sin ((norm move) / period))) + (clockwiseRotate90 move) + in move `add` perpendMove + getAcc : Vec2 -> Vec2 -> Vec2 getAcc move speed = (move `div` 300) `sub` (speed `div` 300) diff --git a/src/Vec2.elm b/src/Vec2.elm index 056c657..c980e1a 100644 --- a/src/Vec2.elm +++ b/src/Vec2.elm @@ -29,6 +29,15 @@ div v d = , y = v.y / d } +norm : Vec2 -> Float +norm v = sqrt(v.x ^ 2 + v.y ^ 2) + +clockwiseRotate90 : Vec2 -> Vec2 +clockwiseRotate90 v = + { x = -v.y + , y = v.x + } + isNull : Vec2 -> Bool isNull v = (v.x == 0) && (v.y == 0) |