initial framework added
[fp1415-soccerfun.git] / src / Gui / renderGameFlatlandish.icl
diff --git a/src/Gui/renderGameFlatlandish.icl b/src/Gui/renderGameFlatlandish.icl
new file mode 100644 (file)
index 0000000..6f9e6e2
--- /dev/null
@@ -0,0 +1,168 @@
+implementation module renderGameFlatlandish\r
+\r
+import matchControl, render\r
+import StdIOCommon, StdPSt\r
+\r
+renderFlatland                         :: RenderStyle\r
+renderFlatland                         = { name = "Flatland"\r
+                                                         , look = flatland\r
+                                                         }\r
+\r
+/**    flatland match updSt\r
+               renders a complete match, given the current dimensions of the drawing environment (updSt).\r
+*/\r
+flatland                                       :: !Match !SelectState !UpdateState !*Picture -> *Picture\r
+flatland match=:{theField,theBall,team1,team2} _ updSt=:{newFrame} picture\r
+# picture                                      = setPenColour Black                                  picture\r
+# picture                                      = fill {corner1={x=pixl,y=zero},corner2={x=w,y=pixw}} picture           // exterior right\r
+# picture                                      = fill {corner1={x=zero,y=pixw},corner2={x=w,y=h}}    picture           // exterior bottom\r
+# picture                                      = unfill field_rectangle                              picture           // football field\r
+# picture                                      = setPenColour White                                  picture\r
+# picture                                      = draw field_rectangle                                picture           // field outline\r
+# picture                                      = drawMiddleArea                                      picture           // middle line, circle and spot\r
+# picture                                      = drawGoals                                           picture           // goals\r
+# picture                                      = drawGoalAreas                                       picture           // goal areas\r
+# picture                                      = drawPenaltyAreas                                    picture           // penalty areas\r
+# picture                                      = drawCornerAreas                                     picture           // corner areas\r
+# picture                                      = foldr (drawPlayer WestColour)                       picture team1     // team1 players\r
+# picture                                      = foldr (drawPlayer EastColour)                       picture team2     // team2 players\r
+# picture                                      = drawBall (getFootball theBall (team1 ++ team2))     picture           // football\r
+= picture\r
+where\r
+       {w,h}                                   = rectangleSize newFrame\r
+       {fwidth,flength}                = theField\r
+       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}}\r
+       ratio                                   = min ((toReal w) / (toReal flength)) ((toReal h) / (toReal fwidth))\r
+       pixw                                    = pix fwidth\r
+       pixl                                    = pix flength\r
+       pix  x                                  = toInt (ratio * toReal x)\r
+       pixx x                                  = pixl / 2 + pix x                                              // convert metres   to pixels\r
+       pixy y                                  = pixw / 2 - pix y\r
+       ppix {px,py}                    = {x  = pixx px, y  = pixy py}                  // convert Position to pixels\r
+       vpix {dx,dy}                    = {vx = pix  dx, vy = pix  dy}                  // convert RVector  to pixels\r
+       (northPole,southPole)   = goal_poles theField\r
+       \r
+       drawPlayer                              :: !Colour !Footballer !*Picture -> *Picture\r
+       drawPlayer colour fb=:{name,nose=nose_dir,effect,pos} picture\r
+       # picture                               = drawName          name picture\r
+       | perhaps isOnTheGround effect\r
+                                                       = drawLyingPlayer    fb  picture\r
+       | otherwise                             = drawStandingPlayer fb  picture\r
+       where\r
+               player_width            = m 0.5\r
+               body_circle                     = circle (pix player_width)\r
+               bearing_circle          = circle (pix (m 0.3))\r
+               nose_dir_vector         = {dx = m (cosinus nose_dir), dy = m (sinus nose_dir) }\r
+               offset                          = {vx = -1, vy = -1}\r
+               nose_dir_point k        = move_point (scale k nose_dir_vector) pos\r
+               \r
+               drawName name picture\r
+               # picture                       = setPenColour White                      picture\r
+               # picture                       = drawAt (ppix (move_point one pos)) name picture\r
+               = picture\r
+               \r
+               drawLyingPlayer fb=:{length} picture\r
+               # (w,picture)           = getPenSize                                                        picture\r
+               # picture                       = setPenSize (pix player_width+2)                                   picture\r
+               # picture                       = setPenColour Black                                                picture\r
+               # picture                       = draw (body_line offset)                                           picture\r
+               # picture                       = setPenSize (pix player_width)                                     picture\r
+               # picture                       = setPenColour colour                                               picture\r
+               # picture                       = draw (body_line zero)                                             picture\r
+               # picture                       = setPenSize w                                                      picture\r
+               # picture                       = fillAt (ppix (nose_dir_point (toReal length+0.2))) bearing_circle picture\r
+               # picture                       = setPenColour Black                                                picture\r
+               # picture                       = drawAt (ppix (nose_dir_point (toReal length+0.2))) bearing_circle picture\r
+               = picture\r
+               where\r
+                       body_line v             = { line_end1 = movePoint v (ppix pos)\r
+                                                         , line_end2 = movePoint v (ppix (nose_dir_point (toReal length))) \r
+                                                         }\r
+               \r
+               drawStandingPlayer fb picture\r
+               # picture                       = setPenColour colour                               picture\r
+               # picture                       = fillAt (ppix pos) body_circle                     picture                                     // body\r
+               # picture                       = fillAt (ppix (nose_dir_point 1.0)) bearing_circle picture                                     // nose direction\r
+               # picture                       = setPenColour Black                                picture                                     // surrounding circle\r
+               # picture                       = drawAt (ppix pos) body_circle                     picture\r
+               # picture                       = drawAt (ppix (nose_dir_point 1.0)) bearing_circle picture                                     // nose direction\r
+               = picture\r
+                       \r
+       drawMiddleArea                  :: !*Picture -> *Picture\r
+       drawMiddleArea picture\r
+       # picture                               = drawLine (ppix {zero & py = scale 0.5 fwidth}) (ppix {zero & py = scale -0.5 fwidth}) picture\r
+       # picture                               = drawAt (ppix zero) (circle (pix radius_centre_circle)) picture                        // middle area\r
+       # picture                               = drawAt (ppix zero) (circle (pix radius_centre_spot))   picture                        // center spot\r
+       = picture\r
+       \r
+       drawGoals                               :: !*Picture -> *Picture\r
+       drawGoals picture\r
+       # picture                               = drawAt (ppix {px=scale  0.5 flength-goal_indent,py=northPole}) h_vector picture               // east north pole\r
+       # picture                               = drawAt (ppix {px=scale  0.5 flength-goal_indent,py=southPole}) h_vector picture               // east south pole\r
+       # picture                               = drawAt (ppix {px=scale -0.5 flength,            py=northPole}) h_vector picture               // west north pole\r
+       # picture                               = drawAt (ppix {px=scale -0.5 flength,            py=southPole}) h_vector picture               // west south pole\r
+       = picture\r
+       where\r
+               goal_indent                     = m 1.0\r
+               h_vector                        = vpix {zero & dx=goal_indent}\r
+       \r
+       drawGoalAreas                   :: !*Picture -> *Picture\r
+       drawGoalAreas picture\r
+       # picture                               = drawAt (ppix {px=scale 0.5 flength-goal_area_depth,   py=northPole+goal_area_depth}) h_vector picture                 // east north edge\r
+       # picture                               = drawAt (ppix {px=scale 0.5 flength-goal_area_depth,   py=southPole-goal_area_depth}) h_vector picture                 // east south edge\r
+       # picture                               = drawAt (ppix {px=scale 0.5 flength-goal_area_depth,   py=northPole+goal_area_depth}) v_vector picture                 // east edge\r
+       # picture                               = drawAt (ppix {px=scale -0.5 flength,                  py=northPole+goal_area_depth}) h_vector picture                 // west north edge\r
+       # picture                               = drawAt (ppix {px=scale -0.5 flength,                  py=southPole-goal_area_depth}) h_vector picture                 // west south edge\r
+       # picture                               = drawAt (ppix {px=scale -0.5 flength + goal_area_depth,py=northPole+goal_area_depth}) v_vector picture                 // west edge\r
+       = picture\r
+       where\r
+               h_vector                        = vpix {zero & dx=goal_area_depth}\r
+               v_vector                        = vpix {zero & dy=scale 2.0 goal_area_depth + goal_width}\r
+       \r
+       drawPenaltyAreas                :: !*Picture -> *Picture\r
+       drawPenaltyAreas picture\r
+       # picture                               = drawAt (ppix {px=scale 0.5 flength-penalty_area_depth,py=northPole+penalty_area_depth}) h_vector picture              // east north edge\r
+       # picture                               = drawAt (ppix {px=scale 0.5 flength-penalty_area_depth,py=southPole-penalty_area_depth}) h_vector picture              // east south edge\r
+       # picture                               = drawAt (ppix {px=scale 0.5 flength-penalty_area_depth,py=northPole+penalty_area_depth}) v_vector picture              // east edge\r
+       # picture                               = drawAt (ppix east_spot) (circle (pix radius_penalty_spot))                                       picture              // east penalty spot\r
+       # picture                               = drawAt (ppix (move_point {dx= ~h_dist,dy= scale (~(sinus angle)) radius_penalty_area} east_spot))                             // east curve\r
+                                                                {curve_oval      = circle (pix radius_penalty_area)\r
+                                                                ,curve_from      = pi + angle\r
+                                                                ,curve_to        = pi - angle\r
+                                                                ,curve_clockwise = True } picture\r
+       # picture                               = drawAt (ppix {px=scale -0.5 flength,                     py=northPole+penalty_area_depth}) h_vector picture   // west north edge\r
+       # picture                               = drawAt (ppix {px=scale -0.5 flength,                     py=southPole-penalty_area_depth}) h_vector picture   // west south edge\r
+       # picture                               = drawAt (ppix {px=scale -0.5 flength + penalty_area_depth,py=northPole+penalty_area_depth}) v_vector picture   // west edge\r
+       # picture                               = drawAt (ppix west_spot) (circle (pix radius_penalty_spot))                                          picture   // west penalty spot\r
+       # picture                               = drawAt (ppix (move_point {dx=h_dist,dy= scale (~(sinus angle)) radius_penalty_area} west_spot))                               // west curve\r
+                                                                {curve_oval      = circle (pix radius_penalty_area)\r
+                                                                ,curve_from      = ~angle\r
+                                                                ,curve_to        = angle\r
+                                                                ,curve_clockwise = False } picture\r
+       = picture\r
+       where\r
+               h_vector                        = vpix {zero & dx=penalty_area_depth}\r
+               v_vector                        = vpix {zero & dy=scale 2.0 penalty_area_depth + goal_width}\r
+               angle                           = arccosinus ((toReal h_dist)/(toReal radius_penalty_area))\r
+               h_dist                          = penalty_area_depth - penalty_spot_depth\r
+               east_spot                       = {zero & px=scale  0.5 flength - penalty_spot_depth}\r
+               west_spot                       = {zero & px=scale -0.5 flength + penalty_spot_depth}\r
+       \r
+       drawCornerAreas                 :: !*Picture -> *Picture\r
+       drawCornerAreas picture\r
+       # 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\r
+       # 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\r
+       # 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\r
+       # 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\r
+       = picture\r
+       where\r
+               corner f t c            = {curve_oval=circle (pix radius_corner_kick_area),curve_from=f,curve_to=t,curve_clockwise=c}\r
+       \r
+       drawBall                                :: !Football !*Picture -> *Picture\r
+       drawBall ball picture\r
+       # picture                               = setPenColour ball_colour picture\r
+       # picture                               = fillAt (ppix ball.ballPos.pxy) (circle (pix (scale (2.8*toReal radius_football) (m 1.0 + scale 0.2 ball.ballPos.pz)))) picture\r
+       = picture\r
+\r
+ball_colour                                    :== Black\r
+circle r                                       :== {oval_rx=r,oval_ry=r}\r