-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
47 lines (33 loc) · 954 Bytes
/
main.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
import math
import time
import PIL
import numpy as np
from PIL import Image
pixels = []
def get_div(i):
return math.ceil(math.sqrt(i))
f = open("input.txt", "r", encoding='utf-8')
pan_tadeusz = f.read()
x_range = get_div(len(pan_tadeusz) / 3)
y_range = get_div(len(pan_tadeusz) / 3)
print(x_range)
print(y_range)
pixels_x = []
index = 0
mode = 0
for x in range(x_range):
for y in range(y_range):
if index + 2 >= len(pan_tadeusz):
mode = 1
pixels_x.append((0, 0, 0))
else:
# print(ord(pan_tadeusz[index]), ord(pan_tadeusz[index + 1]), ord(pan_tadeusz[index + 2]))
pixels_x.append((ord(pan_tadeusz[index]), ord(pan_tadeusz[index + 1]), ord(pan_tadeusz[index + 2])))
index += 3
pixels.append(pixels_x)
pixels_x = []
if mode == 1:
break
array = np.array(pixels, dtype=np.uint8)
new_image = Image.fromarray(array)
new_image.save('converted.bmp')