Mini E
Event walkthrough. Click to place squares.
A SqGame
contains
- a list of
(Color, Point)
calledsqs
- a single
Point
calledhere
- a single
Color
calledcc
Exercises:
-
Write a data definition for
SqGame
. -
Make an example variable
ex
of typeSqGame
containingsqs
:(red, (-1.5, 2.0))
and(orange, (3.0, 1.0))
here
:(2,-4)
cc
:purple
-
Write a drawing function that places a 0.5x0.5 square for each item in the
sqs
list. In addition, place a r=0.25 circle with colorcc
at centerhere
.render :: SqGame -> Picture
-
Write an event handler for a mouse movement that updates the
here
point.eventh :: Event -> SqGame -> SqGame eventh (PointerMovement (x,y)) model = model -- change this eventh _ x = x
-
Write an event handler for a button press that uses the current color and the location of the mouse to add an ordered pair to the front of the list.
eventh (PointerPress (x,y)) model = model -- change this
-
Write an event handler for a keypress that selects the color
"0"
= gray,"1"
= orange,"2"
= blue.eventh (KeyPress _) = gray -- change
-
Combine it into an animation and test it.
main = do print "Testing..." activityOf fixmeInitialModel eventh render