-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBody.hs
45 lines (38 loc) · 997 Bytes
/
Body.hs
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
module Body where
import Graphics.Gloss
import Util
data Body =
Body {
bodyMass :: !Float,
bodyRadius :: !Float,
bodyPos :: !Vec2,
bodyVel :: !Vec2,
bodyCol :: !Color
}
createBody :: Float -> Float -> Vec2 -> Vec2 -> Color -> Body
createBody mass radius pos vel color =
Body {
bodyMass = mass,
bodyRadius = radius,
bodyPos = pos,
bodyVel = vel,
bodyCol = color
}
moveBody :: Float -> Body -> Body
moveBody dt body =
body {
bodyPos = pos `v2Plus` (dt `v2Scale` vel)
}
where Body {
bodyPos = pos,
bodyVel = vel
} = body
gravityWell :: Body -> Float -> Float
gravityWell body dist =
(3 / (4 * pi) * mass) ** (1 / 3) * (integral (dist / radius) / 1.5 - 1)
where integral d =
if d < 1
then d ** 2 / 2
else 1.5 - 1 / d
mass = bodyMass body
radius = bodyRadius body