diff --git a/018/image.jpg b/018/image.jpg new file mode 100644 index 0000000..e31799e Binary files /dev/null and b/018/image.jpg differ diff --git a/018/main.py b/018/main.py new file mode 100644 index 0000000..2ca513d --- /dev/null +++ b/018/main.py @@ -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() \ No newline at end of file diff --git a/018/sandbox.py b/018/sandbox.py new file mode 100644 index 0000000..65d3201 --- /dev/null +++ b/018/sandbox.py @@ -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 \ No newline at end of file