day 18 - boring turtle…
This commit is contained in:
BIN
018/image.jpg
Normal file
BIN
018/image.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
55
018/main.py
Normal file
55
018/main.py
Normal 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()
|
||||
52
018/sandbox.py
Normal file
52
018/sandbox.py
Normal file
@ -0,0 +1,52 @@
|
||||
from turtle import Turtle, Screen
|
||||
import random
|
||||
|
||||
def draw_square(turtle):
|
||||
for _ in range(4):
|
||||
turtle.forward(100)
|
||||
turtle.right(90)
|
||||
|
||||
def draw_dashed_line(turtle):
|
||||
for i in range(30):
|
||||
if i % 2 == 0:
|
||||
turtle.up()
|
||||
else:
|
||||
turtle.down()
|
||||
turtle.forward(10)
|
||||
|
||||
def draw_shapes(turtle):
|
||||
for sides_number in range(3, 11):
|
||||
rgb = ()
|
||||
for _ in range(3):
|
||||
rgb += (random.random(),)
|
||||
|
||||
turtle.pencolor(rgb[0], rgb[1] ,rgb[2])
|
||||
angle = 360 / sides_number
|
||||
|
||||
for _ in range(0, sides_number):
|
||||
turtle.forward(100)
|
||||
turtle.right(angle)
|
||||
|
||||
def draw_spirograph(turtle, nb_circles):
|
||||
angle = 360 / nb_circles
|
||||
for _ in range(0, nb_circles):
|
||||
rgb = ()
|
||||
for _ in range(3):
|
||||
rgb += (random.random(),)
|
||||
turtle.pencolor(rgb[0], rgb[1] ,rgb[2])
|
||||
turtle.circle(100)
|
||||
turtle.left(angle)
|
||||
|
||||
|
||||
|
||||
turtle = Turtle()
|
||||
turtle.speed("fastest")
|
||||
# draw_square(turtle)
|
||||
# draw_dashed_line(turtle)
|
||||
# draw_shapes(turtle)
|
||||
draw_spirograph(turtle, 180)
|
||||
|
||||
screen = Screen()
|
||||
screen.exitonclick()
|
||||
|
||||
turtle.pencolor
|
||||
Reference in New Issue
Block a user