initial framework added
[fp1415-soccerfun.git] / src / Gui / renderGameFlatlandish.icl
1 implementation module renderGameFlatlandish
2
3 import matchControl, render
4 import StdIOCommon, StdPSt
5
6 renderFlatland :: RenderStyle
7 renderFlatland = { name = "Flatland"
8 , look = flatland
9 }
10
11 /** flatland match updSt
12 renders a complete match, given the current dimensions of the drawing environment (updSt).
13 */
14 flatland :: !Match !SelectState !UpdateState !*Picture -> *Picture
15 flatland match=:{theField,theBall,team1,team2} _ updSt=:{newFrame} picture
16 # picture = setPenColour Black picture
17 # picture = fill {corner1={x=pixl,y=zero},corner2={x=w,y=pixw}} picture // exterior right
18 # picture = fill {corner1={x=zero,y=pixw},corner2={x=w,y=h}} picture // exterior bottom
19 # picture = unfill field_rectangle picture // football field
20 # picture = setPenColour White picture
21 # picture = draw field_rectangle picture // field outline
22 # picture = drawMiddleArea picture // middle line, circle and spot
23 # picture = drawGoals picture // goals
24 # picture = drawGoalAreas picture // goal areas
25 # picture = drawPenaltyAreas picture // penalty areas
26 # picture = drawCornerAreas picture // corner areas
27 # picture = foldr (drawPlayer WestColour) picture team1 // team1 players
28 # picture = foldr (drawPlayer EastColour) picture team2 // team2 players
29 # picture = drawBall (getFootball theBall (team1 ++ team2)) picture // football
30 = picture
31 where
32 {w,h} = rectangleSize newFrame
33 {fwidth,flength} = theField
34 field_rectangle = {corner1=ppix {px=scale -0.5 flength,py=scale 0.5 fwidth}, corner2=ppix {px=scale 0.5 flength,py=scale -0.5 fwidth}}
35 ratio = min ((toReal w) / (toReal flength)) ((toReal h) / (toReal fwidth))
36 pixw = pix fwidth
37 pixl = pix flength
38 pix x = toInt (ratio * toReal x)
39 pixx x = pixl / 2 + pix x // convert metres to pixels
40 pixy y = pixw / 2 - pix y
41 ppix {px,py} = {x = pixx px, y = pixy py} // convert Position to pixels
42 vpix {dx,dy} = {vx = pix dx, vy = pix dy} // convert RVector to pixels
43 (northPole,southPole) = goal_poles theField
44
45 drawPlayer :: !Colour !Footballer !*Picture -> *Picture
46 drawPlayer colour fb=:{name,nose=nose_dir,effect,pos} picture
47 # picture = drawName name picture
48 | perhaps isOnTheGround effect
49 = drawLyingPlayer fb picture
50 | otherwise = drawStandingPlayer fb picture
51 where
52 player_width = m 0.5
53 body_circle = circle (pix player_width)
54 bearing_circle = circle (pix (m 0.3))
55 nose_dir_vector = {dx = m (cosinus nose_dir), dy = m (sinus nose_dir) }
56 offset = {vx = -1, vy = -1}
57 nose_dir_point k = move_point (scale k nose_dir_vector) pos
58
59 drawName name picture
60 # picture = setPenColour White picture
61 # picture = drawAt (ppix (move_point one pos)) name picture
62 = picture
63
64 drawLyingPlayer fb=:{length} picture
65 # (w,picture) = getPenSize picture
66 # picture = setPenSize (pix player_width+2) picture
67 # picture = setPenColour Black picture
68 # picture = draw (body_line offset) picture
69 # picture = setPenSize (pix player_width) picture
70 # picture = setPenColour colour picture
71 # picture = draw (body_line zero) picture
72 # picture = setPenSize w picture
73 # picture = fillAt (ppix (nose_dir_point (toReal length+0.2))) bearing_circle picture
74 # picture = setPenColour Black picture
75 # picture = drawAt (ppix (nose_dir_point (toReal length+0.2))) bearing_circle picture
76 = picture
77 where
78 body_line v = { line_end1 = movePoint v (ppix pos)
79 , line_end2 = movePoint v (ppix (nose_dir_point (toReal length)))
80 }
81
82 drawStandingPlayer fb picture
83 # picture = setPenColour colour picture
84 # picture = fillAt (ppix pos) body_circle picture // body
85 # picture = fillAt (ppix (nose_dir_point 1.0)) bearing_circle picture // nose direction
86 # picture = setPenColour Black picture // surrounding circle
87 # picture = drawAt (ppix pos) body_circle picture
88 # picture = drawAt (ppix (nose_dir_point 1.0)) bearing_circle picture // nose direction
89 = picture
90
91 drawMiddleArea :: !*Picture -> *Picture
92 drawMiddleArea picture
93 # picture = drawLine (ppix {zero & py = scale 0.5 fwidth}) (ppix {zero & py = scale -0.5 fwidth}) picture
94 # picture = drawAt (ppix zero) (circle (pix radius_centre_circle)) picture // middle area
95 # picture = drawAt (ppix zero) (circle (pix radius_centre_spot)) picture // center spot
96 = picture
97
98 drawGoals :: !*Picture -> *Picture
99 drawGoals picture
100 # picture = drawAt (ppix {px=scale 0.5 flength-goal_indent,py=northPole}) h_vector picture // east north pole
101 # picture = drawAt (ppix {px=scale 0.5 flength-goal_indent,py=southPole}) h_vector picture // east south pole
102 # picture = drawAt (ppix {px=scale -0.5 flength, py=northPole}) h_vector picture // west north pole
103 # picture = drawAt (ppix {px=scale -0.5 flength, py=southPole}) h_vector picture // west south pole
104 = picture
105 where
106 goal_indent = m 1.0
107 h_vector = vpix {zero & dx=goal_indent}
108
109 drawGoalAreas :: !*Picture -> *Picture
110 drawGoalAreas picture
111 # picture = drawAt (ppix {px=scale 0.5 flength-goal_area_depth, py=northPole+goal_area_depth}) h_vector picture // east north edge
112 # picture = drawAt (ppix {px=scale 0.5 flength-goal_area_depth, py=southPole-goal_area_depth}) h_vector picture // east south edge
113 # picture = drawAt (ppix {px=scale 0.5 flength-goal_area_depth, py=northPole+goal_area_depth}) v_vector picture // east edge
114 # picture = drawAt (ppix {px=scale -0.5 flength, py=northPole+goal_area_depth}) h_vector picture // west north edge
115 # picture = drawAt (ppix {px=scale -0.5 flength, py=southPole-goal_area_depth}) h_vector picture // west south edge
116 # picture = drawAt (ppix {px=scale -0.5 flength + goal_area_depth,py=northPole+goal_area_depth}) v_vector picture // west edge
117 = picture
118 where
119 h_vector = vpix {zero & dx=goal_area_depth}
120 v_vector = vpix {zero & dy=scale 2.0 goal_area_depth + goal_width}
121
122 drawPenaltyAreas :: !*Picture -> *Picture
123 drawPenaltyAreas picture
124 # picture = drawAt (ppix {px=scale 0.5 flength-penalty_area_depth,py=northPole+penalty_area_depth}) h_vector picture // east north edge
125 # picture = drawAt (ppix {px=scale 0.5 flength-penalty_area_depth,py=southPole-penalty_area_depth}) h_vector picture // east south edge
126 # picture = drawAt (ppix {px=scale 0.5 flength-penalty_area_depth,py=northPole+penalty_area_depth}) v_vector picture // east edge
127 # picture = drawAt (ppix east_spot) (circle (pix radius_penalty_spot)) picture // east penalty spot
128 # picture = drawAt (ppix (move_point {dx= ~h_dist,dy= scale (~(sinus angle)) radius_penalty_area} east_spot)) // east curve
129 {curve_oval = circle (pix radius_penalty_area)
130 ,curve_from = pi + angle
131 ,curve_to = pi - angle
132 ,curve_clockwise = True } picture
133 # picture = drawAt (ppix {px=scale -0.5 flength, py=northPole+penalty_area_depth}) h_vector picture // west north edge
134 # picture = drawAt (ppix {px=scale -0.5 flength, py=southPole-penalty_area_depth}) h_vector picture // west south edge
135 # picture = drawAt (ppix {px=scale -0.5 flength + penalty_area_depth,py=northPole+penalty_area_depth}) v_vector picture // west edge
136 # picture = drawAt (ppix west_spot) (circle (pix radius_penalty_spot)) picture // west penalty spot
137 # picture = drawAt (ppix (move_point {dx=h_dist,dy= scale (~(sinus angle)) radius_penalty_area} west_spot)) // west curve
138 {curve_oval = circle (pix radius_penalty_area)
139 ,curve_from = ~angle
140 ,curve_to = angle
141 ,curve_clockwise = False } picture
142 = picture
143 where
144 h_vector = vpix {zero & dx=penalty_area_depth}
145 v_vector = vpix {zero & dy=scale 2.0 penalty_area_depth + goal_width}
146 angle = arccosinus ((toReal h_dist)/(toReal radius_penalty_area))
147 h_dist = penalty_area_depth - penalty_spot_depth
148 east_spot = {zero & px=scale 0.5 flength - penalty_spot_depth}
149 west_spot = {zero & px=scale -0.5 flength + penalty_spot_depth}
150
151 drawCornerAreas :: !*Picture -> *Picture
152 drawCornerAreas picture
153 # picture = drawAt (ppix {px=scale -0.5 flength + radius_corner_kick_area,py=scale 0.5 fwidth}) (corner 0.0 (1.5*pi) True ) picture // west north corner
154 # picture = drawAt (ppix {px=scale -0.5 flength + radius_corner_kick_area,py=scale -0.5 fwidth}) (corner 0.0 (0.5*pi) False) picture // west south corner
155 # picture = drawAt (ppix {px=scale 0.5 flength - radius_corner_kick_area,py=scale 0.5 fwidth}) (corner pi (1.5*pi) False) picture // east north corner
156 # picture = drawAt (ppix {px=scale 0.5 flength - radius_corner_kick_area,py=scale -0.5 fwidth}) (corner pi (0.5*pi) True ) picture // east south corner
157 = picture
158 where
159 corner f t c = {curve_oval=circle (pix radius_corner_kick_area),curve_from=f,curve_to=t,curve_clockwise=c}
160
161 drawBall :: !Football !*Picture -> *Picture
162 drawBall ball picture
163 # picture = setPenColour ball_colour picture
164 # picture = fillAt (ppix ball.ballPos.pxy) (circle (pix (scale (2.8*toReal radius_football) (m 1.0 + scale 0.2 ball.ballPos.pz)))) picture
165 = picture
166
167 ball_colour :== Black
168 circle r :== {oval_rx=r,oval_ry=r}