diff --git a/Day 18/README.md b/Day 18/README.md new file mode 100644 index 0000000..a643e71 --- /dev/null +++ b/Day 18/README.md @@ -0,0 +1,29 @@ +# Day 18 - Turtle & the Graphical User Interface (GUI) + +- Developed various basic turtle graphics. + - Spirograph, random walk, various polygons, dashed line, and square. +- Formed a dot art based on Hirst artwork. + +## Dot art + +![Day_18_Dot_Art](https://user-images.githubusercontent.com/30333942/128644328-9128d1b2-e416-4daf-ba05-cc37c2cff9ee.gif) + +## Spirograph + +![Day_18_Spirograph](https://user-images.githubusercontent.com/30333942/128644332-0aad8f64-5d71-4579-9c53-07333bb38233.gif) + +## Random Walk + +![Day_18_Random_Walk](https://user-images.githubusercontent.com/30333942/128644335-00899537-04b9-4f88-bcd6-46b7590082fe.gif) + +## Polygons + +![Day_18_Polygons](https://user-images.githubusercontent.com/30333942/128644338-23011edc-6246-49c2-9574-0f5e0497bcb6.gif) + +## Dashed Line + +![Day_18_Dashed_Line](https://user-images.githubusercontent.com/30333942/128644340-dff27a27-a6e1-44d3-95c0-9f885f9771b2.gif) + +## Square + +![Day_18_Square](https://user-images.githubusercontent.com/30333942/128644342-746c14cf-86f2-47c0-ae93-b3df1bf32b13.gif) diff --git a/Day 18/day-18-start/main.py b/Day 18/day-18-start/main.py new file mode 100644 index 0000000..a6bd49b --- /dev/null +++ b/Day 18/day-18-start/main.py @@ -0,0 +1,66 @@ +from turtle import Turtle, Screen, colormode +from random import randint, choice + +arrow = Turtle() + +# Draw a square +def square(): + for i in range(4): + arrow.forward(100) + arrow.right(90) + +# square() + +# Draw a dashed line +def dashed_line(): + for i in range(20): + arrow.forward(10) + arrow.penup() + arrow.forward(10) + arrow.pendown() + +# dashed_line() + +# Draw a triangle, square, pentagon, hexagon, heptagon, octagon, nonagon, and decagon +def polygons(): + colormode(255) + for i in range(3, 11): + angle = 360 / i + color = (randint(0, 255), randint(0, 255), randint(0, 255)) + arrow.color(color) + for j in range(1, i + 1): + arrow.right(angle) + arrow.forward(100) + +# polygons() + +# Random Walk (thickness, speed up turtle) +def random_walk(steps): + colormode(255) + arrow.pensize(15) + arrow.speed(0) + for i in range(steps): + color = (randint(0, 255), randint(0, 255), randint(0, 255)) + arrow.color(color) + step_size = randint(0, 50) + arrow.setheading(choice([0, 90, 180, 270])) + arrow.forward(step_size) + +# random_walk(1000) + +# Spirograph +def spirograph(): + colormode(255) + arrow.speed(0) + heading = 0 + for i in range(72): + color = (randint(0, 255), randint(0, 255), randint(0, 255)) + arrow.color(color) + arrow.circle(200) + arrow.setheading(heading) + heading += 5 + +# spirograph() + +screen = Screen() +screen.exitonclick() diff --git a/Day 18/dot-art/colors_source.jpg b/Day 18/dot-art/colors_source.jpg new file mode 100644 index 0000000..8e41b18 Binary files /dev/null and b/Day 18/dot-art/colors_source.jpg differ diff --git a/Day 18/dot-art/main.py b/Day 18/dot-art/main.py new file mode 100644 index 0000000..c91507d --- /dev/null +++ b/Day 18/dot-art/main.py @@ -0,0 +1,72 @@ +# # Get color palette from an image +# import colorgram + +# color_list = [] +# colors = colorgram.extract('colors_source.jpg', 30) +# for color in colors: +# r = color.rgb.r +# g = color.rgb.g +# b = color.rgb.b +# new_color = (r, g, b) +# color_list.append(new_color) +# print(color_list) + +from turtle import Turtle, Screen, colormode +import random + +arrow = Turtle() + +color_list = [ + (221, 144, 96), + (165, 57, 88), + (68, 84, 153), + (100, 167, 208), + (154, 66, 54), + (109, 176, 128), + (195, 76, 113), + (209, 123, 155), + (222, 90, 66), + (233, 163, 188), + (238, 223, 97), + (107, 117, 187), + (176, 184, 224), + (141, 210, 221), + (84, 95, 88), + (163, 139, 49), + (58, 173, 186), + (67, 54, 96), + (234, 171, 155), + (166, 206, 188), + (154, 35, 49), + (91, 159, 124), + (189, 27, 24), + (65, 55, 64), + (56, 49, 71), + (71, 56, 49), +] + +# Set arrow starting position +arrow.hideturtle() +arrow.speed(0) +arrow.penup() +arrow.sety(-250) +arrow.setx(-250) +arrow.width(20) + +# Create dots +colormode(255) +number_of_dots = 100 +for i in range(1, number_of_dots + 1): + arrow.pendown() + arrow.dot(20, random.choice(color_list)) + arrow.penup() + arrow.forward(50) + if i % 10 == 0: + arrow.penup() + arrow.backward(500) + arrow.left(90) + arrow.forward(50) + arrow.right(90) + +screen = Screen() +screen.exitonclick()