-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathart.py
78 lines (53 loc) · 1.34 KB
/
art.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import random
import colorgram
from turtle import Turtle, Screen
def create_pen(shape, color, speed):
pen = Turtle()
pen.shape(shape)
pen.color(color)
pen.speed(speed)
return pen
def get_colors_from_image(image_path, n_colors):
colors_list = []
for color_object in colorgram.extract(image_path, n_colors):
r, g, b = color_object.rgb
colors_list.append((r, g, b))
return colors_list
def get_random_unique_color(colors):
color = random.choice(colors)
return color
def draw_art(pen):
image_path = 'src/day_18/images/dots.jpg'
n_colors = 35
colors = get_colors_from_image(image_path, n_colors)
n = 10
x = -280
y = -200
move_pen(pen, x, y)
while n:
for _ in range(10):
color = get_random_unique_color(colors)
print(color)
pen.color(color)
move_forward(pen, 50)
pen.dot(20)
y += 50
move_pen(pen, x, y)
n -= 1
def move_forward(pen, distance):
pen.penup()
pen.forward(distance)
pen.pendown()
def move_pen(pen, x, y):
pen.penup()
pen.goto(x, y)
pen.pendown()
def main():
app = Screen()
app.colormode(255)
pen = create_pen('classic', 'black', 'fast')
pen.hideturtle()
draw_art(pen)
app.mainloop()
if __name__ == "__main__":
main()