Skip to content

Commit

Permalink
move examples to own file
Browse files Browse the repository at this point in the history
  • Loading branch information
patritzenfeld committed Jan 8, 2025
1 parent d96cf36 commit 9175e99
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 66 deletions.
1 change: 1 addition & 0 deletions codeworld-tasks.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ library
exposed-modules:
API
Compare
Examples
HashCons
Normalize
Reify
Expand Down
55 changes: 55 additions & 0 deletions src/Examples.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

module Examples (
sampleSolution,
example1,
example2,
example3,
example4,
example5,
threeCircles,
) where


import API (Drawable(..))
import Types (red, green, yellow)


sampleSolution :: Drawable a => a
sampleSolution = translated 0 6 (colored yellow (solidCircle 1))
& colored green (solidRectangle 20 2)


example1 :: Drawable a => a
example1 = colored yellow (solidCircle 2)
& translated 0 (-5) (colored green (solidRectangle 12 3))


example2 :: Drawable a => a
example2 = translated 0 6 (colored yellow(solidCircle 1))
& colored green (solidRectangle 12 2)


example3 :: Drawable a => a
example3 = grass & sun
where
grass = colored green (solidRectangle 20 2)
sun = translated 0 7 (colored yellow (solidCircle 1.5))


example4 :: Drawable a => a
example4 = ebene & translated 0 9 sonne
where
boden = solidRectangle 20 2
ebene = colored green boden
sonne = colored yellow (solidCircle 1)


example5 :: Drawable a => a
example5 = colored yellow (solidCircle 1)
& translated 0 (-3) (colored green (solidRectangle 8 1.5))


threeCircles :: Drawable a => a
threeCircles = colored red (solidCircle 1)
& translated 2 4 (colored green $ solidCircle 1)
& translated 0 3 (colored yellow $ solidCircle 1)
66 changes: 0 additions & 66 deletions src/Normalize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,8 @@

module Normalize (
NormalizedPicture(..),

(===),
toRelative,

red,
yellow,
green,

sampleSolution,
example1,
example2,
example3,
example4,
example5,
threeCircles,
) where


Expand Down Expand Up @@ -445,18 +432,6 @@ toSize :: Double -> Size
toSize = Size


yellow :: Color
yellow = Yellow


green :: Color
green = Green


red :: Color
red = Red


toRelative :: NormalizedPicture -> [RelativePicSpec]
toRelative p = case p of
Pictures ps -> sort $ relativePosition ps
Expand Down Expand Up @@ -503,44 +478,3 @@ orientation (Translate a b _) = case (a,b) of
"This should never happen. " ++
"translated smart constructor wasn't used."
orientation _ = onTopOf


sampleSolution :: Drawable a => a
sampleSolution = translated 0 6 (colored yellow (solidCircle 1))
& colored green (solidRectangle 20 2)


example1 :: Drawable a => a
example1 = colored yellow (solidCircle 2)
& translated 0 (-5) (colored green (solidRectangle 12 3))


example2 :: Drawable a => a
example2 = translated 0 6 (colored yellow(solidCircle 1))
& colored green (solidRectangle 12 2)


example3 :: Drawable a => a
example3 = grass & sun
where
grass = colored green (solidRectangle 20 2)
sun = translated 0 7 (colored yellow (solidCircle 1.5))


example4 :: Drawable a => a
example4 = ebene & translated 0 9 sonne
where
boden = solidRectangle 20 2
ebene = colored green boden
sonne = colored yellow (solidCircle 1)


example5 :: Drawable a => a
example5 = colored yellow (solidCircle 1)
& translated 0 (-3) (colored green (solidRectangle 8 1.5))


threeCircles :: Drawable a => a
threeCircles = colored red (solidCircle 1)
& translated 2 4 (colored green $ solidCircle 1)
& translated 0 3 (colored yellow $ solidCircle 1)
6 changes: 6 additions & 0 deletions src/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ data Color
| Green
| Red
deriving (Eq,Ord,Show)


green, red, yellow :: Color
yellow = Yellow
green = Green
red = Red

0 comments on commit 9175e99

Please sign in to comment.