Mini E
Event walkthrough. Click to place squares.
A SqGame contains
- a list of
(Color, Point)calledsqs - a single
Pointcalledhere - a single
Colorcalledcc
Exercises:
-
Write a data definition for
SqGame. -
Make an example variable
exof typeSqGamecontainingsqs:(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
sqslist. In addition, place a r=0.25 circle with colorccat centerhere.render :: SqGame -> Picture -
Write an event handler for a mouse movement that updates the
herepoint.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