9 -- a Path is a list of locations
10 -- it represents the discrete motion of an object starting from now
11 -- the [] path means the object does not exist
12 -- therefore a finite path manifests itself as an object that moves
13 -- in some way and finally disappears.
15 -- the Monoid instance allows you to compose Paths. This is a sum-type
16 -- composition, mappend p1 p2 is a path that follows p1 + p2 and either
17 -- ends when p1 or p2 ends (whichever comes first) or does not end in
18 -- the case p1 and p2 are infinite. the identity path is repeat 0, i.e.
19 -- does not move from the origin or disappear ever.
21 -- the origin. there is only one origin. in order to shift a path away
22 -- from the origin by amount x, mappend (repeat x).
30 pappend
:: (Num a
) => Path a
-> Path a
-> Path a
33 pappend
(x
:xs
) (y
:ys
) = (x
+y
) : pappend xs ys
35 pconcat
:: (Num a
) => [Path a
] -> Path a
36 pconcat xs
= foldl pappend
(repeat 0) xs
42 ray
:: (Fractional a
) => a
-> Path a
43 ray v
= map ((*) (v
/100) . fromIntegral) [0..]
45 segment
:: (Fractional a
) => a
-> a
-> Path a
49 left
= segment
(1:+0) 1
50 right
= segment
((-1):+0) 1
52 down
= segment
(0:+(-1)) 1
54 timeWarp
:: (Fractional a
) => a
-> Path a
-> Path a
57 forNext
:: Int -> Path a
-> Path a
58 forNext l ps
= take l ps
60 (&>) :: (Num a
) => Path a
-> Path a
-> Path a
61 xs
&> ys
= f xs ys
where
63 f
[x
] ys
= x
: map (+x
) ys
64 f
(x
:xs
) ys
= x
: f xs ys
66 circle
:: Spin
-> Radius
-> Path Coord
67 circle
0 r
= at
(r
:+0)
68 circle w r
= map f xs
where
69 f
= mkPolar r
. (\x
-> 2 * pi * x
/ steps
)
73 freeze
:: Path a
-> Path a