Skip to content

Commit 1e07e69

Browse files
Update Day-18
1 parent eb613b6 commit 1e07e69

File tree

6 files changed

+204
-0
lines changed

6 files changed

+204
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.ipynb_checkpoints
22
*.txt
33
*.pyc
4+
*.vscode

Day-18-TurtleGUI/Modules.ipynb

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Day 19"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"###### Importing Modules"
15+
]
16+
},
17+
{
18+
"cell_type": "markdown",
19+
"metadata": {},
20+
"source": [
21+
"Module or Classes can be imported in three ways\n",
22+
"```python\n",
23+
"import turtle\n",
24+
"timmy = turlte.Turtle()\n",
25+
"```\n",
26+
"```python\n",
27+
"from turtle import Turtle\n",
28+
"timmy = Turtle()\n",
29+
"```\n",
30+
"```python\n",
31+
"from turtle import *\n",
32+
"```"
33+
]
34+
},
35+
{
36+
"cell_type": "markdown",
37+
"metadata": {},
38+
"source": [
39+
"- tk refers to tkinter module, which is one of the ways of creating GUI"
40+
]
41+
},
42+
{
43+
"cell_type": "markdown",
44+
"metadata": {},
45+
"source": [
46+
"###### Aliasing Modules"
47+
]
48+
},
49+
{
50+
"cell_type": "markdown",
51+
"metadata": {},
52+
"source": [
53+
"```python\n",
54+
"import turtle as t\n",
55+
"```"
56+
]
57+
},
58+
{
59+
"cell_type": "markdown",
60+
"metadata": {},
61+
"source": [
62+
"###### Python Tuples\n",
63+
"- Tuples do not support item assignment or cannot be removed ie immutable\n",
64+
"- Tuples can be converted to list\n",
65+
"```python\n",
66+
"list(my_tuple)\n",
67+
"```\n",
68+
"---\n",
69+
"```python\n",
70+
"my_tuple = (1,2,3) # Create\n",
71+
"\n",
72+
"my_tuple[0] # Access\n",
73+
"```"
74+
]
75+
},
76+
{
77+
"cell_type": "markdown",
78+
"metadata": {},
79+
"source": [
80+
"---"
81+
]
82+
}
83+
],
84+
"metadata": {
85+
"kernelspec": {
86+
"display_name": "Python 3",
87+
"language": "python",
88+
"name": "python3"
89+
},
90+
"language_info": {
91+
"codemirror_mode": {
92+
"name": "ipython",
93+
"version": 3
94+
},
95+
"file_extension": ".py",
96+
"mimetype": "text/x-python",
97+
"name": "python",
98+
"nbconvert_exporter": "python",
99+
"pygments_lexer": "ipython3",
100+
"version": "3.7.6"
101+
}
102+
},
103+
"nbformat": 4,
104+
"nbformat_minor": 4
105+
}

Day-18-TurtleGUI/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Hirst-Painting
2+
3+
### An implementation of Hirst-Painting.
4+
5+
<img src= 'https://user-images.githubusercontent.com/65078610/105053195-b1d43200-5a96-11eb-8b3e-3384f20d7787.gif' width="600">

Day-18-TurtleGUI/hirst-painting.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Colorgram lets extract color from images
2+
import colorgram
3+
import turtle
4+
import random
5+
6+
turtle.colormode(255)
7+
8+
# Extract 30 colors from image.jpg
9+
# Returns 30 color object containing rgb & hsl value
10+
colors = colorgram.extract('image.jpg',30)
11+
rgb_colors = []
12+
for color in colors:
13+
rgb = color.rgb
14+
rgb_colors.append((rgb.r, rgb.g, rgb.b))
15+
16+
# Slimming rgb_colors to remove unwanted tuple
17+
color_list = [
18+
(111, 145, 98), (190, 154,125), (137, 84, 66), (22, 26, 48), (143, 158, 186),
19+
(228, 223, 111), (80, 91, 124), (134, 71, 88), (185, 143, 157), (50, 31, 22),
20+
(61, 25, 35), (150, 174, 160), (26, 36, 28), (115, 36, 49), (82, 100, 87),
21+
(46, 50, 107), (173, 99, 124), (118, 40, 34), (173, 182, 223), (186, 99, 85),
22+
(104, 114, 178), (226, 177, 169), (221, 174, 186), (68, 73, 44), (172, 200, 204),
23+
(172, 202, 189)
24+
]
25+
26+
tim = turtle.Turtle()
27+
tim.speed(0)
28+
tim.penup()
29+
tim.hideturtle()
30+
for y in range(0,500,50):
31+
tim.sety(y-250)
32+
for x in range(0,500,50):
33+
tim.setx(x-250)
34+
tim.dot(20, random.choice(color_list))
35+
36+
screen = turtle.Screen()
37+
screen.exitonclick()

Day-18-TurtleGUI/image.jpg

5.6 KB
Loading

Day-18-TurtleGUI/main.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from turtle import Turtle, Screen
2+
import random
3+
4+
# Changing module turtle's property()
5+
# If its set to 255, color() takes rgb value in range(0,255)
6+
# But here we pass decimal values using random() so set to 1 instead
7+
import turtle
8+
turtle.colormode(1)
9+
10+
# Create object of class Turtle
11+
tim = Turtle()
12+
tim.shape('turtle')
13+
tim.color('SeaGreen')
14+
15+
# Draw square
16+
def square():
17+
for i in range(4):
18+
tim.forward(100)
19+
tim.left(90)
20+
21+
# Draw dashed line
22+
def dashedLine():
23+
for i in range(10):
24+
tim.forward(10)
25+
tim.penup()
26+
tim.forward(10)
27+
tim.pendown()
28+
29+
# Draw a triangle, square, pentagon, hexagon, heptagon, octagon, nonagon & decagon
30+
def geometryShapes():
31+
for i in range(3,11):
32+
tim.color(random.random(), random.random(), random.random())
33+
for ii in range(i):
34+
tim.forward(100)
35+
tim.left(360/i)
36+
37+
# Random Walk
38+
def randomWalk():
39+
tim.pensize(10)
40+
tim.speed(0)
41+
for i in range(200):
42+
tim.color(random.random(), random.random(), random.random())
43+
tim.setheading(random.choice([0,90,180,270]))
44+
tim.forward(30)
45+
46+
# Spirograph
47+
def spirograph():
48+
tim.speed(0)
49+
for i in range(0,361,5):
50+
tim.color(random.random(), random.random(), random.random())
51+
tim.setheading(i)
52+
tim.circle(100)
53+
54+
55+
screen = Screen()
56+
screen.exitonclick()

0 commit comments

Comments
 (0)