forked from anamikasharaf/DrawMyEmotions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Generate_Art.py
395 lines (358 loc) · 10.1 KB
/
Generate_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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
_author__ = 'anamika.sharaf'
from turtle import *
from random import randint
from random import *
from Tkinter import *
import glob, os, pdb
from PIL import Image
#for stars
def random_star_color(emotion_num):
if(emotion_num == 1):
random_color = ["hotpink", "MediumVioletRed"]
color = choice(random_color)
if(emotion_num == 2):
random_color = ["slategray", "black","darkslategray"]
color = choice(random_color)
if(emotion_num == 3):
random_color = ["gainsboro", "saddlebrown"]
color = choice(random_color)
if(emotion_num == 4):
random_color = ["Indigo", "midnightblue"]
color = choice(random_color)
if(emotion_num == 5):
random_color = ["LightCoral", "DarkSalmon"]
color = choice(random_color)
return color
#for circle and splatter
def random_dot_color(emotion_num):
if(emotion_num == 1):
random_color = ["MediumVioletRed","lightcoral","hotpink","palevioletred"]
color = choice(random_color)
if(emotion_num == 2):
random_color = ["slategray","darkslategray","black"]
color = choice(random_color)
if(emotion_num == 3):
random_color = ["darkgoldenrod","tan","brown"]
color = choice(random_color)
if(emotion_num == 4):
random_color = ["navy","RoyalBlue"]
color = choice(random_color)
if(emotion_num == 5):
random_color = ["LightCoral","Red","Maroon"]
color = choice(random_color)
if(emotion_num == 6):
random_color = ["yellowgreen","seagreen"]
color = choice(random_color)
return color
#for foreground shapes
def foreground_color(emotion_num):
if(emotion_num == 1):
random_color = ["lightsalmon","coral", "MediumVioletRed", "palevioletred","orange"]
color = choice(random_color)
if(emotion_num == 2):
random_color = ["black","dimgray"]
color = choice(random_color)
if(emotion_num == 3):
random_color = ["rosybrown", "goldenrod", "brown"]
color = choice(random_color)
if(emotion_num == 4):
random_color = ["darkmagenta", "DarkSlateBlue", "DarkRed","MidnightBlue"]
color = choice(random_color)
if(emotion_num == 5):
random_color = ["Red", "DarkRed","IndianRed","firebrick","orangered"]
color = choice(random_color)
if(emotion_num == 6):
random_color = ["darkolivegreen","darkgoldenrod","darkslategray","forestgreen"]
color = choice(random_color)
return color
# random quadrant selection
def random_place(random_qadrant):
penup()
if(random_qadrant == 1):
x = randint(-400,400)
y = randint(0,400)
if(random_qadrant == 2):
x = randint(-400,0)
y = randint(-400,400)
if(random_qadrant == 3):
x = randint(-400,400)
y = randint(-400,0)
if(random_qadrant == 4):
x = randint(0,400)
y = randint(-400,400)
if(random_qadrant == 5):
x = randint(-400,400)
y = randint(-400,400)
goto(x,y)
pendown()
#choose quadarant for dots
def choose_quant(random_qadrant):
if(random_qadrant == 1):
quadrant_alternative = 2
if(random_qadrant == 2):
quadrant_alternative = 3
if(random_qadrant == 3):
quadrant_alternative = 4
if(random_qadrant == 4):
quadrant_alternative = 1
if(random_qadrant == 5):
quadrant_alternative = 5
return quadrant_alternative
#drawing circles
def draw_circle(emotion_num,random_qadrant):
color_picked = foreground_color(emotion_num)
random_place(random_qadrant)
hideturtle()
radius = randint(70,100)
begin_fill()
color(color_picked)
dot(radius)
end_fill()
#drawing ellipse
def draw_ellipse(emotion_num,random_qadrant):
radius1 = randint(3,10)
radius2 = randint(5,15)
color_picked = foreground_color(emotion_num)
random_place(random_qadrant)
shape("circle")
shapesize(radius1,radius2)
pencolor(color_picked)
fillcolor(color_picked)
stamp()
#drawing dots
def draw_dots(emotion_num,size,random_qadrant):
if(size == 0):
radius = randint(20,30)
if(size == 1):
radius = randint(6,10)
if(size == 2):
radius = randint(8,15)
random_place(random_qadrant)
color_picked = random_dot_color(emotion_num)
hideturtle()
begin_fill()
color(color_picked)
dot(radius)
end_fill()
#drawing hollow circles
def draw_hollow_circle(emotion_num,random_qadrant):
random_place(random_qadrant)
radius = randint(20,40)
penup()
color_picked = random_dot_color(emotion_num)
pencolor(color_picked)
width(10)
pendown()
setheading(180)
circle(radius)
penup()
#drawing stars
def draw_star(emotion_num,random_qadrant):
size = randint(5,15)
angle = 120
color_picked = random_star_color(emotion_num)
fillcolor(color_picked)
random_place(random_qadrant)
hideturtle()
begin_fill()
pencolor(color_picked)
for side in range(5):
forward(size)
right(angle)
forward(size)
right(72 - angle)
end_fill()
#draw rectangle
def draw_rectangle(emotion_num,size,random_qadrant):
random_place(random_qadrant)
hideturtle()
if(size == 1):
length = randint(150,250)
height = randint(150,250)
color_picked = foreground_color(emotion_num)
if(size == 2):
length = randint(100,150)
height = randint(100,150)
color_picked = foreground_color(emotion_num)
if(size == 3):
length = randint(10,20)
height = randint(10,20)
color_picked = random_dot_color(emotion_num)
begin_fill()
color(color_picked)
forward(length)
right(90)
forward(height)
right(90)
forward(length)
right(90)
forward(height)
right(90)
end_fill()
#draw polygons based on number of dots
def sprinkle(emotion_num,random_quadrant):
hideturtle()
color_picked = random_dot_color(emotion_num)
begin_fill()
color(color_picked)
for i in range(5):
random_place(random_quadrant)
dot(4)
end_fill()
#generate happy art
def generate_happy_art():
emotion_num = 1
background_color = "hotpink"
bgcolor(background_color)
setup( width = 500, height = 500)
random_quadrant = randint(1,4)
alternative = choose_quant(random_quadrant)
for i in range(60):
if (i%2 == 0):
draw_ellipse(emotion_num,random_quadrant)
draw_circle(emotion_num,random_quadrant)
draw_hollow_circle(emotion_num,random_quadrant)
for i in range(100):
draw_dots(emotion_num,0,alternative)
for i in range(200):
draw_dots(emotion_num,1,alternative)
for i in range(10):
draw_star(emotion_num,random_quadrant)
for i in range(200):
draw_dots(emotion_num,2,5)
for i in range(100):
draw_dots(emotion_num,0,alternative)
convert_file(background_color,0.8)
#generate sad art
def generate_sad_art():
emotion_num = 2
background_color = "gray"
bgcolor(background_color)
setup( width = 500, height = 500)
random_quadrant = randint(1,4)
alternative = choose_quant(random_quadrant)
for i in range(10):
sprinkle(emotion_num,5)
for i in range(60):
if (i%2 == 0):
draw_ellipse(emotion_num,random_quadrant)
draw_circle(emotion_num,random_quadrant)
for i in range(100):
draw_dots(emotion_num,0,alternative)
for i in range(200):
draw_dots(emotion_num,1,alternative)
for i in range(200):
draw_dots(emotion_num,2,5)
for i in range(100):
draw_dots(emotion_num,0,alternative)
convert_file(background_color,0.8)
#generate neutral art
def generate_neutral_art():
emotion_num = 3
background_color = "peru"
bgcolor(background_color)
setup( width = 500, height = 500)
random_quadrant = randint(1,4)
alternative = choose_quant(random_quadrant)
for i in range(60):
if (i%2 == 0):
draw_ellipse(emotion_num,random_quadrant)
draw_circle(emotion_num,random_quadrant)
draw_hollow_circle(emotion_num,random_quadrant)
for i in range(100):
draw_dots(emotion_num,0,alternative)
for i in range(200):
draw_dots(emotion_num,1,alternative)
for i in range(200):
draw_dots(emotion_num,2,5)
for i in range(100):
draw_dots(emotion_num,0,alternative)
convert_file(background_color,0.5)
#generate fear art
def generate_fear_art():
emotion_num = 4
background_color = "Slateblue"
bgcolor(background_color)
setup( width = 500, height = 500)
random_quadrant = randint(1,4)
alternative = choose_quant(random_quadrant)
for i in range(10):
sprinkle(emotion_num,5)
for i in range(60):
if (i%2 == 0):
draw_ellipse(emotion_num,random_quadrant)
draw_circle(emotion_num,random_quadrant)
draw_hollow_circle(emotion_num,random_quadrant)
for i in range(100):
draw_dots(emotion_num,0,alternative)
for i in range(200):
draw_dots(emotion_num,1,alternative)
for i in range(200):
draw_dots(emotion_num,2,5)
for i in range(100):
draw_dots(emotion_num,0,alternative)
convert_file(background_color,0.5)
#generate anger art
def generate_anger_art():
emotion_num = 5
background_color = "brown"
bgcolor(background_color)
setup( width = 500, height = 500)
random_quadrant = randint(1,4)
alternative = choose_quant(random_quadrant)
for i in range(10):
sprinkle(emotion_num,5)
for i in range(60):
if (i%2 == 0):
draw_ellipse(emotion_num,random_quadrant)
draw_circle(emotion_num,random_quadrant)
draw_hollow_circle(emotion_num,random_quadrant)
for i in range(100):
draw_dots(emotion_num,0,alternative)
for i in range(200):
draw_dots(emotion_num,1,alternative)
for i in range(200):
draw_dots(emotion_num,2,5)
for i in range(100):
draw_dots(emotion_num,0,alternative)
convert_file(background_color,0.5)
#generate disgust art
def generate_disgust_art():
emotion_num = 6
background_color = "limegreen"
bgcolor(background_color)
setup( width = 500, height = 500)
random_quadrant = randint(1,4)
alternative = choose_quant(random_quadrant)
for i in range(10):
sprinkle(emotion_num,5)
for i in range(60):
if (i%2 == 0):
draw_ellipse(emotion_num,random_quadrant)
draw_circle(emotion_num,random_quadrant)
draw_hollow_circle(emotion_num,random_quadrant)
for i in range(100):
draw_dots(emotion_num,0,alternative)
for i in range(200):
draw_dots(emotion_num,1,alternative)
for i in range(200):
draw_dots(emotion_num,2,5)
for i in range(100):
draw_dots(emotion_num,0,alternative)
convert_file(background_color,0.7)
def convert_file(background_color, alpha):
#save the turtle module in .eps images
ts = getscreen()
ts.getcanvas().postscript(file="foreground.eps")
#convert .eps file to .png
openFiles = glob.glob('*.eps')
for files in openFiles:
inFile = Image.open(files)
fileName = os.path.splitext(files)[0] # gets filename
image2 = Image.open(fileName + ".eps")
image2.save(fileName+".png","png", quality = 1000)
#blending two images
image1 = Image.new("RGB", (500,500), background_color)
image1.save("background.png", "png", quality = 1000)
image3 = Image.blend(image1,image2,alpha)
image3.save("final_image.png","png", quality = 1000)