-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisualise.hs
More file actions
37 lines (33 loc) · 1.45 KB
/
Visualise.hs
File metadata and controls
37 lines (33 loc) · 1.45 KB
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
module Visualise (visualiseWorld) where
import World
import Graphics.SpriteKit
-- Visualise the world
--
visualiseWorld :: World -> Node u
visualiseWorld (World sf unitMass _ ps) = (node (map visualiseParticle ps))
{ nodeXScale = (floatToDouble sf)
, nodeYScale = (floatToDouble sf)
}
where
visualiseParticle (Particle m (x, y) _) = (solidCircle size)
{ nodePosition = Point (floatToDouble x)
(floatToDouble y)
}
where
size = logBase 10 (m / unitMass) / sf
solidCircle :: Float -> Node u
solidCircle r = (shapeNodeWithPath circlePath)
{ shapeFillColor = orangeColor
, shapeLineWidth = 0
}
where
rd = floatToDouble r
circlePath = [ MoveToPoint (Point 0 rd)
, AddCurveToPoint (Point k rd) (Point rd k) (Point rd 0)
, AddCurveToPoint (Point rd (-k)) (Point k (-rd)) (Point 0 (-rd))
, AddCurveToPoint (Point (-k) (-rd)) (Point (-rd) (-k)) (Point (-rd) 0)
, AddCurveToPoint (Point (-rd) k) (Point (-k) rd) (Point 0 rd)
]
k = 0.5522847498 * rd
floatToDouble :: Float -> Double
floatToDouble = fromRational . toRational