-
Notifications
You must be signed in to change notification settings - Fork 0
/
art_generator.py
142 lines (128 loc) · 3.97 KB
/
art_generator.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import random
from PIL import Image
import all_functions
import image_functions
def generate_art(
image_size,
bg_color=(0, 0, 0),
num_lines=10,
horizontal=False,
vertical=False,
circle=False,
rect=False,
random_line=False,
cir_radius=(),
stroke_clr=None,
stroke_width=12,
rectangle_size=(),
style=None,
small_dots=False,
num_of_dots=100,
dot_clr=(255, 255, 255),
start_color=None,
end_color=None,
padding_=False,
effect="add",
):
# Set size parameters.
rescale = 2
image_size_px = image_size * rescale
pad = image_size // 20
effect = effect.lower()
thick_addition = -20
if num_lines <= 10:
thickness_scale = round(image_size / (150 + thick_addition))
elif 10 < num_lines <= 20:
thickness_scale = round(image_size / (200 + thick_addition))
elif 20 < num_lines <= 30:
thickness_scale = round(image_size / (300 + thick_addition))
elif 30 < num_lines <= 40:
thickness_scale = round(image_size / (420 + thick_addition))
elif 40 < num_lines <= 50:
thickness_scale = round(image_size / (600 + thick_addition))
else:
thickness_scale = round(image_size / (750 + thick_addition))
if not padding_:
padding = 0
else:
padding = padding_
# Create the directory and base image.
image = Image.new("RGB", (image_size_px, image_size_px), bg_color)
# Pick the colors.
if not start_color:
start_color = all_functions.random_color()
if not end_color:
end_color = all_functions.random_color()
# get the image
if small_dots:
image = image_functions.make_small_dots(
image=image,
image_size_px=image_size_px,
color=dot_clr,
number_of_dots=num_of_dots,
)
if horizontal:
image = image_functions.horizontal_line_draw(
image=image,
image_size_px=image_size_px,
num_lines=num_lines,
thickness_scale=thickness_scale,
start_color=start_color,
end_color=end_color,
effect=effect,
)
if vertical:
image = image_functions.vertical_line_draw(
image=image,
image_size_px=image_size_px,
num_lines=num_lines,
thickness_scale=thickness_scale,
start_color=start_color,
end_color=end_color,
effect=effect,
)
if random_line:
image = image_functions.random_lines_draw(
image=image,
image_size_px=image_size_px,
padding=padding,
num_lines=num_lines,
thickness_scale=thickness_scale,
start_color=start_color,
end_color=end_color,
effect=effect,
)
if circle:
image = image_functions.circle_image(
image=image,
image_size_px=image_size_px,
num_circle=num_lines,
radius=cir_radius,
stroke_width=stroke_width,
start_color=start_color,
end_color=end_color,
stroke_color=stroke_clr,
effect=effect,
style=style,
)
if rect:
image = image_functions.rect_image(
image=image,
image_size_px=image_size_px,
num_rect=num_lines,
start_color=start_color,
end_color=end_color,
stroke_color=stroke_clr,
rect_size=rectangle_size,
style=style,
effect=effect,
stroke_width=15,
)
mirror = random.choice([True, False])
if mirror:
image = all_functions.mirror_image(image)
# Image is done! Now resize it to be smooth.
image = image.resize(
(image_size_px // rescale, image_size_px // rescale), resample=Image.LANCZOS
)
return image