Diagrams

Diagrams

Notes

Coordinate System

Circle

circle :: Double -> Diagram
Test>

Note the type of functions and the syntax of function application.

Rectangle

rect :: Double -> Double -> Diagram
Test>
Test>

Note the type of functions with two parameters and their application.

Superposition of two Diagrams

(<|>) :: Diagram -> Diagram -> Diagram
Test>

Note the syntax of operators.

Exercise: “No Entry” Sign

Make a diagram similar to the “no entry” sign shown here (hint: use lengths 2, 5 and 8):

Test>

Moving Diagrams

move :: Diagram -> Point -> Diagram
Test>

Note the application of functions with two parameters as operators.

Note that the precedence of move is higher than the precedence of <|>.

Exercise: Door

Make a diagram similar to the door shown here (hint: use lengths 0, 2, 6, 10, 14 and 20):

Test>

Superposition of Diagrams

union :: [Diagram] -> Diagram
Test>

Note the type of lists and the syntax of conctrete lists.

List Comprehensions

Test>

Dot-dot Expressions

Test>

Exercise: Coins

Make a diagram similar to the coins shown here (hint: the radius of the circles are 4):

Test>

Exercise: Stairs

Make a diagram similar to the stairs shown here (hint: use lengths -5, 1, 2, 5):

Test>

Exercise: Cage

Make a diagram similar to the cage shown here (hint: use lengths -5, 1, 2, 4, 20):

Test>

Exercise: Circles

Test>
Test>
Test>

Exercise: Spheres

The radius of the spheres are 1.5x, x∈{-5,-4,…,4,5}.

The exponentiation operator is: **

Test>

Exercise: Pearl Necklace

A function used is x ↦ x2/10.

Test>

Exercise: Spiral

The new functions used here are pi, sin and cos.

Test>

Coloring

fill :: Diagram -> Color -> Diagram
black :: Color
Test>

Predefined colors: black, gray, white, red, green, blue, yellow


Note the type of constants (nothing special though).

Exercise: Colored “No Entry” Sign

Test>

Rotation

rotate :: Diagram -> Double -> Diagram
Test>

Exercise: Black Star

The used length is 10.

Test>

Exercise: Dial

Test>

Section

(~~) :: Point -> Point -> Diagram
Test>

Exercise: Dandelion

Test>

Polygon

polygon :: [Point] -> Diagram
Test>

Exercise: Star

Test>

Anything Else?

This is just a demo what can we define later.
The following code describes a tree with n levels:

tree n 
  | n <= 0 = empty
  | otherwise 
      = pack (tree (n-1)) $ \t -> 
         ((0,0)~~(0,-5) <|> t `rotate` 15 <|> t `rotate` (-15))
             `move` (0,5) `scale` 0.8

Here is the tree with 6 levels:
(WARNING: you can kill your browser with more than 8 levels!)

Test>

Back to the main page

Main page