def draw_ball_static(canvas, color):
    '''
    draw a static ball
    '''
    canvas.create_oval(0, 0, 200, 200, fill=color)
    canvas.create_oval(50, 0, 150, 200)
    canvas.create_line(100, 0, 100, 200)

def draw_ball_scaled(canvas, scale, color):
    '''
    stretch a ball evenly in both x and y direction
    '''
    canvas.create_oval(0*scale, 0*scale, 200*scale, 200*scale, fill=color)
    canvas.create_oval(50*scale, 0*scale, 150*scale, 200*scale)
    canvas.create_line(100*scale, 0*scale, 100*scale, 200*scale)    

def draw_ball_stretched(canvas, x_scale, y_scale, color):
    '''
    strech a ball in x and y direction with different scales
    '''
    canvas.create_oval(0*x_scale, 0*y_scale, 200*x_scale, 200*y_scale, fill=color)
    canvas.create_oval(50*x_scale, 0*y_scale, 150*x_scale, 200*y_scale)
    canvas.create_line(100*x_scale, 0*y_scale, 100*x_scale, 200*y_scale)

def draw_ball_size(canvas, width, height, color):
    '''
    draw a ball with given width and height
    '''
    x_scale = width / 200
    y_scale = height / 200
    draw_ball_stretched(canvas, x_scale, y_scale, color)

def draw_ball_shifted(canvas, width, height, dx, dy, color):
    '''
    shift the ball from coordinate (0,0)
    '''
    x_scale = width / 200
    y_scale = height / 200
    canvas.create_oval(0*x_scale+dx, 0*y_scale+dy, 200*x_scale+dx, 200*y_scale+dy, fill=color)
    canvas.create_oval(50*x_scale+dx, 0*y_scale+dy, 150*x_scale+dx, 200*y_scale+dy)
    canvas.create_line(100*x_scale+dx, 0*y_scale+dy, 100*x_scale+dx, 200*y_scale+dy)        

def draw_ball_in_box(canvas, x_left, y_top, x_right, y_bottom, color):
    '''
    draw a ball in a box with given coordinates:
    (x_left, y_top) is the top-left coordinate
    (x_right, y_bottom) is the bottom_right coordinate
    '''
    width = x_right - x_left
    height = y_bottom - y_top
    dx = x_left
    dy = y_top
    draw_ball_shifted(canvas, width, height, dx, dy, color)


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

    #draw_ball_static(canvas, 'yellow')

    #draw_ball_scaled(canvas, 2, 'blue')
    #draw_ball_scaled(canvas, 1, 'yellow')

    #draw_ball_stretched(canvas, 2, 1, 'red')
    #draw_ball_stretched(canvas, 1, 2, 'yellow')

    #draw_ball_size(canvas, 175, 240, 'yellow')

    #draw_ball_shifted(canvas, 175, 240, 30, 40, 'red')

    draw_ball_in_box(canvas, 30, 50, 100, 150, 'blue')

    display(canvas)