# Eksempel på funksjon for å tegne et enkelt motiv som
# kan skaleres og strekkes.
#
#                 (0.75 * width + x1)
#                          |
#  (x1, y1)                |
#      * - - - , - ~ ~ ~ - , - - - +            ˜\
#      |   , '               ' ,   |             |
#      | ,                       , |             |
#      |,      ()         ()      ,|_ _ _ (0.35 * height + y1)
#      ,                           ,             |
#      ,                           ,              > height = y2 - y1
#      ,                           ,             |
#      |,       `--_____--'       ,|             |
#      | ,                       , |             |
#      |   ,                  , '  |             |
#      + - - ' - , _ _ _ , -'- - - *            _/
#                               (x2, y2)
#
#       \____________ ____________/
#                    V
#              width = x2 - x1
#
# Når du tegner skissen for figuren, ta utgangspunkt i 
# at lerretet har størrelse 1.0 x 1.0. Alle x-verdier kan
# deretter skaleres med width og flyttes med x1, mens alle
# y-verdier kan skaleres med height og flyttes med y1.

def face(canvas, x1, y1, x2, y2):
    ''' Draws a smiling face on the canvas within the bounds
    of (x1, y1) and (x2, y2). Will stretch and resize to match
    the given bounds. '''

    width = x2 - x1
    height = y2 - y1

    canvas.create_oval(x1, y1, x2, y2) # Face
    canvas.create_oval( # Left eye
        0.25 * width + x1, 0.25 * height + y1,
        0.35 * width + x1, 0.35 * height + y1,
    )
    canvas.create_oval( # Right eye
        0.65 * width + x1, 0.25 * height + y1,
        0.75 * width + x1, 0.35 * height + y1, 
    )
    canvas.create_line( # Smile
        0.30 * width + x1, 0.65 * height + y1,
        0.50 * width + x1, 0.85 * height + y1,
        0.70 * width + x1, 0.65 * height + y1,
        smooth=True
    )


if __name__ == '__main__':
    from uib_inf100_graphics.simple import display, canvas

    face(canvas, 20, 20, 120, 380) # Tall face
    face(canvas, 140, 20, 380, 100) # Wide face
    face(canvas, 160, 140, 160 + 200, 140 + 200) # Circular face 200x200

    display(canvas)