-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.py
More file actions
69 lines (57 loc) · 2.11 KB
/
Copy pathstart.py
File metadata and controls
69 lines (57 loc) · 2.11 KB
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
import glob
import os
from PIL import Image, ImageDraw
import random
import uuid
import moviepy.editor as mp
def create_gif():
ids = []
my_images = []
for i in range(100):
run_id = uuid.uuid1()
ids.append(run_id)
#print(f'Processing run nr.: {run_id}')
image = Image.new('RGB', (2000, 2000))
width, height = image.size
rectangle_width = 500
rectangle_height = 500
number_of_squares = random.randint(400, 500)
draw_image = ImageDraw.Draw(image)
for i in range(number_of_squares):
rectangle_x = random.randint(0, width)
rectangle_y = random.randint(0, height)
rectangle_shape = [
(rectangle_x, rectangle_y),
(rectangle_x + random.randint(10, 30), rectangle_y - random.randint(10, 30))
]
draw_image.line(
rectangle_shape,
fill=(
random.randint(0, 255),
random.randint(0, 255),
random.randint(0, 255)
),
width=5
)
draw_image.rectangle([(rectangle_x, rectangle_y),
(rectangle_x + random.randint(10, 30), rectangle_y - random.randint(10, 30))],
fill=(
random.randint(0, 255),
random.randint(0, 255),
random.randint(0, 255)
),
width=5
)
image.save(f'./{run_id}.png')
im1 = Image.open(f'./{run_id}.png')
my_images.append(im1)
#append images together to form a GIF
image.save('out.gif', save_all=True, append_images= my_images, duration=60, loop=0)
#delete all .png files after done using them
pngs = os.listdir(f'./')
for image in pngs:
if image.endswith(".png"):
os.remove(image)
#convert the gif to mp4
clip = mp.VideoFileClip("out.gif")
clip.write_videofile("out.mp4")