import colorgram
import turtle
import random

def create_colorset(colors_nb):
    colors = colorgram.extract('/Users/tanguy/Workspace/python/bootcamp/018/image.jpg', colors_nb)
    return(colors)

def extract_random_color_from_set(colorset):
    color = random.choice(colorset)
    return(color.rgb)

def set_initial_position(t):
    t.pu()
    t.backward(400)
    t.left(90)
    t.backward(400)
    t.right(90)
    
def draw_line(t):
    for _ in range(11):
        t.pd()
        t.dot(20, extract_random_color_from_set(colorset))
        t.pu()
        t.forward(40)
        
def go_to_next_line(t):
    t.left(90)
    t.forward(40)
    t.left(90)
    t.forward(440)
    t.right(180)
    
colorset = create_colorset(20)    
    
t = turtle.Turtle()
turtle.colormode(255)
t.speed("fastest")
t.hideturtle()


set_initial_position(t)
for _ in range(10):
    draw_line(t)
    go_to_next_line(t)
    
    


    


    
screen = turtle.Screen()
screen.exitonclick()