SOE ex.10.1


import Picture

r1, r2, r3, r4 :: Region
r1 = Shape (Rectangle 3 2)
r2 = Shape (Ellipse 1 1.5)
r3 = Shape (RtTriangle 3 2)
r4 = Shape (Polygon [(-2.5, 2.5), (-3, 0), (-1.7, -1), (-1.1, 0.2), (-1.5, 2)])

reg1, reg2 :: Region
pic1, pic2, pic3 :: Picture

reg1 = r3 `xUnion` (r1 `Intersect` Complement r2 `Union` r4)
pic1 = Region Blue reg1

reg2 = let circle = Shape (Ellipse 0.5 0.5)
           square = Shape (Rectangle 1 1)
       in  (Scale (2,2) circle)
           `Union` (Translate (1,0) square)
           `Union` (Translate (-1,0) square)
pic2 = Region Yellow (Translate (0, -1) reg2)

pic3 = pic2 `Over` pic1

main1 = draw "Pic1" pic1
main2 = draw "Pic2" pic2
main3 = draw "Pic3" pic3

-----

oneCircle = Shape (Ellipse 1 1)
manyCircles = [Translate (x,0) oneCircle | x <- [0,2..]]
fiveCircles = foldr Union Empty (take 5 manyCircles)
main4 = draw "5 circles" (Region Blue $ Scale (0.3, 0.3) fiveCircles)

Leave a Reply