Mini E

Event walkthrough. Click to place squares.

A SqGame contains

  • a list of (Color, Point) called sqs
  • a single Point called here
  • a single Color called cc

Exercises:

  1. Write a data definition for SqGame.

  2. Make an example variable ex of type SqGame containing

    • sqs: (red, (-1.5, 2.0)) and (orange, (3.0, 1.0))
    • here: (2,-4)
    • cc: purple
  3. 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 color cc at center here.

     render :: SqGame -> Picture
    
  4. 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
    
  5. 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
    
  6. Write an event handler for a keypress that selects the color "0" = gray, "1" = orange, "2" = blue.

     eventh (KeyPress _) = gray -- change
    
  7. Combine it into an animation and test it.

     main = do
       print "Testing..."
       activityOf fixmeInitialModel eventh render