-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOverlapTest.elm
44 lines (34 loc) · 1.17 KB
/
OverlapTest.elm
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
import Graphics.Element exposing (..)
import Graphics.Collage exposing (..)
import Color exposing (..)
import Util exposing (..)
import Mouse exposing (..)
tGray = rgba 0 0 0 0.2
tRed = rgba 255 0 0 0.2
staticRect : Rectangle
staticRect = { center = zeroVec2, size = { x = 100, y = 50 } }
userBaseRect : Rectangle
userBaseRect = { staticRect | size <- { x = 20, y = 20 } }
userRect : Int -> Int -> Rectangle
userRect x y =
{ userBaseRect | center <- {x = toFloat x, y = toFloat y} }
-- the beef
overlapColor : Rectangle -> Rectangle -> Color
overlapColor a b =
if overlap a b then tRed else tGray
renderRect : Color -> Rectangle -> Form
renderRect c r = rect r.size.x r.size.y
|> filled c
|> move (r.center.x, r.center.y)
view : (Int, Int) -> Element
view (x, y) =
let (w, h) = (600, 600)
(w', h') = (toFloat w, toFloat h)
bg = rect w h
|> filled lightGray
user = userRect (x - w//2) (h//2 - y)
userForm = renderRect (overlapColor user staticRect) user
staticForm = renderRect (overlapColor staticRect user) staticRect
in collage w h [ bg, staticForm, userForm ]
main =
Signal.map view Mouse.position