CS 410/510 - Homework #2
Create a single Haskell file that contains solutions to the following programs.
Be sure it compiles without errors, and submit it via D2L by class time on
Wednesday January 20, 2016. As we did with
examples in the lecture make a single "main" program which asks the
user to select which of the examples he wants to run. Recall that the
SOE library works for compiled programs, not programs run under "ghci".
Start with the file HW2Template.html
which has all the boiler plate you will need. In order to enable this program to
find the libraries, put it in the "src" sub directory of the SOE, libraries or
use a -i command line argument to "ghc" that points to this directory. For example
here is how I compiled my solution
ghc --make -o hw2.exe -i../code/SOE/src hw2.hs
Be sure you put your name and e-mail in a comment
at the beginning of the file. Without this you will not get any feedback.
In this homework you will create several programs that use the SOE library. In order to do this
you will need to do 2 things before you get started.
- Install the OpenGL libraries used by using Cabal.
- Download the SOE library.
Some instructions for doing this can be found here.
You may also want to study the three files we used for examples in the lectures on FRP.
- Static Pictures. Use the Shape, Region, and Picture types to create
a static picture of a "house" with doors, windows etc. Be creastive, try to have a minimum
of 10 or more Shapes, and 4 or more colors. Now draw this static picture.
- Pictures are Data. Write a function "recolor" with type
recolor:: Picture -> [(Color,Color)] -> Picture
That changes the colors of a picture. For example
recolor p [(Red,Green) ,(Blue,Magenta)]
Changes all Red pictures to Green, and all Blue pictures to Magenta. Apply this function
with a list of length three color pairs, and redraw the house from problem 1 above.
- Dynamic Pictures.
Create a picture of a geometric object (you choose what kind of object). The picture should slowly
change size as time progresses. The picture should also change color as time progresses.
Be creative
- Reactive Pictures. Alter the pong game so that it includes a text Graphic
that records the score. The score should increase by one every time the paddle
successfully bounces the ball back into the 3 walls.
- Reactive Pictures. Take the geometric object from part 3 above, and anchor one
of its "points" to the position of the mouse. Redo the size and color changing, but include the
shape changing due to the mouse. Use the FRP combinators. You may have to use a completely
different implementation technique, since part 3 can be done without the FRP combinators.
- Just for fun. This part is optional. Create your own reactive picture.