From CSULA CS Wiki
< Courses‎ | CS 332F‎ | Winter 2006‎ | Brian Smith
Revision as of 15:16, 22 May 2006 by WikiAdmin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
module UsePictures where

import Pictures

pp :: Picture -> IO ()
pp x = printPicture x

-- 2.1  Basic definitions

blackHorse :: Picture
blackHorse = invertColour horse

-- 'rotate' already in the Pictures module

rotateHorse :: Picture
rotateHorse = rotate horse

-- 2.2  Black rectangle using 'superimpose'

black :: Picture
black = superimpose horse (invertColour horse)

-- 2.3  Checkerboard, 2x2 size only

halfBoard :: Picture
halfBoard = sideBySide white (invertColour white)

checkerBoard1 :: Picture
checkerBoard1 = above halfBoard (invertColour halfBoard)

-- Checkerboard, generalized recursive method

row :: Int -> Picture
row 1 = white
row n | n > 1 && even n = sideBySide (row (n-1)) black
row n | n > 1 && odd n = sideBySide (row (n-1)) white

board :: Int -> Int -> Picture
board x 1 = row x
board x y | y > 1 && even y = above (board x (y-1)) (invertColour (board x 1))
board x y | y > 1 && odd y = above (board x (y-1)) (board x 1)

-- 2.4

rowHorse :: Int -> Picture
rowHorse 1 = horse
rowHorse n | n > 1 && even n = sideBySide (rowHorse (n-1)) blackHorse
rowHorse n | n > 1 && odd n = sideBySide (rowHorse (n-1)) horse

-- Variant 1

board1 :: Int -> Int -> Picture
board1 x 1 = rowHorse x
board1 x y | y > 1 && even y = above (board1 x (y-1)) (invertColour (board1 x 1))
board1 x y | y > 1 && odd y = above (board1 x (y-1)) (board1 x 1)

-- Variant 2

board2 :: Int -> Int -> Picture
board2 x 1 = rowHorse x
board2 x y | y > 1 && even y = above (board2 x (y-1)) (flipV (board2 x 1))
board2 x y | y > 1 && odd y = above (board2 x (y-1)) (board2 x 1)

-- Variant 3

board3 :: Int -> Int -> Picture
board3 x 1 = rowHorse x
board3 x y | y > 1 && even y = above (board3 x (y-1)) (rotate (board3 x 1))
board3 x y | y > 1 && odd y = above (board3 x (y-1)) (board3 x 1)

-- 2.5

board4 :: Int -> Int -> Picture
board4 x 1 = rowHorse x
board4 x y | y > 1 && even y = above (board4 x (y-1)) (invertColour (flipH (board4 x 1)))
board4 x y | y > 1 && odd y = above (board4 x (y-1)) (board4 x 1)