day 18 - boring turtle…

This commit is contained in:
2025-06-30 00:16:25 +02:00
parent d23a9c9503
commit 10e04f8744
3 changed files with 107 additions and 0 deletions

55
018/main.py Normal file
View File

@ -0,0 +1,55 @@
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()