-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw_initial.py
158 lines (135 loc) · 4.86 KB
/
draw_initial.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
"""Creates initial images"""
import random
import math
import os
import xml.etree.ElementTree as ET
from PIL import Image, ImageDraw
import saving as save
def draw_random_image_intial(x, y, seed, pixel_number, file_name, pixel_size):
array_x = [x]
array_y = [y]
new_x = x
new_y = y
img = Image.new("RGBA", (1000, 1000), color=(0, 0, 0, 0))
random.seed(seed)
draw = ImageDraw.Draw(img)
lastrand = 0
draw.rectangle((x, y, x + pixel_size, y + pixel_size), fill=(255, 0, 0, 255))
i = 0
random_color_1 = random.randint(0, 255)
random_color_2 = random.randint(0, 255)
random_color_3 = random.randint(0, 255)
random_color_4 = random.randint(200, 255)
random_color_array = [
random_color_1,
random_color_2,
random_color_3,
random_color_4,
]
while i < pixel_number:
random_number = random.randint(1, 4)
random_color_1 += random.randint(-10, 10)
random_color_2 += random.randint(-10, 10)
random_color_3 += random.randint(-10, 10)
random_color_4 += random.randint(-10, 10)
random_color_array.append(random_color_1)
random_color_array.append(random_color_2)
random_color_array.append(random_color_3)
random_color_array.append(random_color_4)
if random_color_1 <= 0 or random_color_1 >= 255:
random_color_1 = 255
if random_color_2 <= 0 or random_color_2 >= 255:
random_color_2 = 0
if random_color_3 <= 0 or random_color_3 >= 255:
random_color_3 = 0
if random_color_4 <= 0 or random_color_4 >= 255:
random_color_4 = 255
if lastrand == 1 or lastrand == 2:
random_number = random.randint(3, 4)
elif lastrand == 3 or lastrand == 4:
random_number = random.randint(1, 2)
if random_number == 1:
new_x += 5
elif random_number == 2:
new_x -= 5
elif random_number == 3:
new_y += 5
elif random_number == 4:
new_y -= 5
lastrand = random_number
array_x.append(new_x)
array_y.append(new_y)
if new_x < 10 or new_x > 90 or new_y < 10 or new_y > 90:
new_x = x
new_y = y
draw.rectangle(
(new_x, new_y, new_x + pixel_size, new_y + pixel_size),
fill=(random_color_1, random_color_2, random_color_3, random_color_4),
)
i += 1
save.image_saver(img, file_name)
return array_x, array_y, random_color_array
def parse_xml(xml_file_name, file_name):
# Parse the XML file
x = []
y = []
size = []
current_file_path = os.path.dirname(os.path.realpath(__file__))
file_name_loc = current_file_path + "\\patterns\\" + xml_file_name
tree = ET.parse(file_name_loc)
# Get the root element
root = tree.getroot()
color_array = [] # Find all 'sprite' elements and print their 'x' and 'y' attributes
for sprite in root.iter():
if (sprite.tag == "sprite"
and sprite.get("x") != None
and sprite.get("y") != None
):
x.append(int(sprite.get("x")))
y.append(int(sprite.get("y")))
size.append(int(sprite.get("size")))
color_array.append(int(sprite.get("color_1")))
color_array.append(int(sprite.get("color_2")))
color_array.append(int(sprite.get("color_3")))
color_array.append(255)
return x, y,size, color_array
def draw_xml_image(x, y, file_name):
img = Image.new("RGBA", (1000, 1000), color=(0, 0, 0, 0))
draw = ImageDraw.Draw(img)
for i in range(len(x)):
draw.rectangle((x[i], y[i], x[i] + 5, y[i] + 5), fill=(255, 0, 0, 255))
save.image_saver(img, file_name)
def draw_planet(x, y, seed, pixel_number, file_name, pixel_size):
array_x = [x]
array_y = [y]
new_x = x
new_y = y
img = Image.new("RGBA", (1000, 1000), color=(0, 0, 0, 0))
random.seed(seed)
draw = ImageDraw.Draw(img)
draw.rectangle((x, y, x + pixel_size, y + pixel_size), fill=(255, 0, 0, 255))
random_color_array = []
pixel_size = 1
h = x
k = x
r = math.sqrt(100)
# Generate points on the circle
points = [
(h + r * math.cos(t), k + r * math.sin(t))
for t in [i * 0.01 for i in range(int(2 * math.pi / 0.01))]
]
# Split into two lists
array_x = [x for x, y in points]
array_y = [y for x, y in points]
for x in points:
random_color_array.append(255)
random_color_array.append(0)
random_color_array.append(0)
random_color_array.append(255)
for i in range(len(array_x)):
draw.rectangle(
(array_x[i], array_y[i], array_x[i] + pixel_size, array_y[i] + pixel_size),
fill=(255, 0, 0, 255),
)
save.image_saver(img, file_name)
return array_x, array_y, random_color_array