-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFigure.py
executable file
·50 lines (41 loc) · 1.74 KB
/
Figure.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
'''
This program is free software: you can redistribute it and/or modify
t under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
from PIL import Image
import Bricks
import Config
def build_image(figure, x, y, wall):
im = Image.open(figure) #imagem para ser convertida ( TODO: ajustar para receber uma lista de imagens ou uma pasta com imagens)
print im.format, im.size, im.info
#im.show()
# convert to black white
fig = im.convert("L").transpose(Image.FLIP_LEFT_RIGHT).rotate(90)
if wall:
fig = fig.resize((x * Config.WIDTH, (y * Config.HEIGHT) + Config.WIDTH))
else:
fig = fig.resize((x * Config.WIDTH, y * Config.HEIGHT))
return fig
def build_imarray(im, x, y, wall):
if wall:
imarray = Bricks.build_grid_wall(x, y)
pixels = im.load()
for i in range(x * Config.WIDTH):
for j in range((y * Config.HEIGHT) + Config.WIDTH):
imarray[i,j] = pixels[i,j] # load method is faster than getpixel: im.getpixel((i,j))
return imarray
else:
imarray = Bricks.build_grid(x, y)
pixels = im.load()
for i in range(x * Config.WIDTH):
for j in range(y * Config.HEIGHT):
imarray[i,j] = pixels[i,j] # load method is faster than getpixel: im.getpixel((i,j))
return imarray