-
Notifications
You must be signed in to change notification settings - Fork 0
/
readingFile.py
107 lines (86 loc) · 2.26 KB
/
readingFile.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
import pygame
pygame.init()
points = []
colors = []
black = (0, 0, 0)
white = (255, 255, 255)
xSize = 0
ySize = 0
circRad = 0
cellSize = 0
f = open("map2.txt", "r")
for x in f:
if(x[0:1] == "g"):
x = x[2:]
space = x.find(" ")
xSize = int(x[0:space])
x = x[space+1:]
space = x.find(" ")
ySize = int(x[0:space])
continue
if(x[0:1] == "s"):
x = x[2:]
space = x.find(" ")
circRad = int(x[0:space])
x = x[space+1:]
space = x.find(" ")
cellSize = int(x[0:space])
continue
space = x.find(" ")
red = int(x[0:space])
x = x[space+1:]
space = x.find(" ")
green = int(x[0:space])
x = x[space+1:]
space = x.find(" ")
blue = int(x[0:space])
colors.append((red, green, blue))
x = x[space+3:]
space = x.find(" ")
firstXPos = int(x[0:space])
x = x[space+1:]
space = x.find(" ")
firstYPos = int(x[0:space])
points.append((firstXPos, firstYPos, (red, green, blue)))
x = x[space+3:]
space = x.find(" ")
secondXPos = int(x[0:space])
x = x[space+1:]
secondYPos = int(x[0:])
points.append((secondXPos, secondYPos, (red, green, blue)))
screen_width = cellSize * xSize
screen_height = cellSize * ySize
screen = pygame.display.set_mode((screen_width, screen_height))
typeGrid = [[]]
colorGrid = [[]]
for i in range(xSize):
typeGrid.append([])
colorGrid.append([])
for j in range(ySize):
typeGrid[i].append(0)
colorGrid[i].append(black)
for i in points:
typeGrid[i[0]][i[1]] = 2
colorGrid[i[0]][i[1]] = i[2]
print(points)
def pixelPos(num):
return num * cellSize + 40
def draw():
for row in range(xSize):
for col in range(ySize):
x = row * cellSize
y = col * cellSize
if(typeGrid[row][col] == 2):
pygame.draw.circle(screen, colorGrid[row][col], (pixelPos(row), pixelPos(col)), 40 - 4)
pygame.draw.rect(screen, white, (x, y, cellSize, cellSize), 1)
draw()
pygame.display.flip()
running = True
while(running):
pygame.time.delay(20)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.display.flip()
pygame.quit()
print(colors)