Skip to content

Commit 0db37a3

Browse files
committed
update: renderer
1 parent 70bb714 commit 0db37a3

File tree

2 files changed

+40
-21
lines changed

2 files changed

+40
-21
lines changed

rednerer.py

+34-21
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@
88

99
class Renderer:
1010
points = []
11-
POINT_SIZE = 10
11+
canvas_width = 0
12+
canvas_height = 0
13+
POINT_SIZE = 5
14+
15+
def __init__(self, canvas_width=1000, canvas_height=1000):
16+
self.canvas_height = canvas_height
17+
self.canvas_width = canvas_width
1218

1319
def init(self):
1420
glClearColor(0, 0, 0, 0)
15-
gluOrtho2D(0,1000, 0, 1000)
21+
gluOrtho2D(0,self.canvas_width, 0, self.canvas_height)
1622

1723
def test(self):
1824
glClear(GL_COLOR_BUFFER_BIT)
@@ -59,7 +65,7 @@ def draw_scene(self):
5965
def main(self):
6066
glutInit(sys.argv)
6167
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
62-
glutInitWindowSize(1000, 1000)
68+
glutInitWindowSize(self.canvas_width, self.canvas_height)
6369
glutInitWindowPosition(50, 50)
6470
glutCreateWindow("FUCkCPP")
6571
self.init()
@@ -69,11 +75,29 @@ def main(self):
6975

7076
def test_points(self):
7177
print("Test Point")
72-
for i in range(1000):
78+
for i in range(self.canvas_height):
7379
point = Point(i, i ,(1,0,1))
7480
self.set_points(point)
7581
time.sleep(0.01)
76-
82+
83+
def test_random_points(self):
84+
while True:
85+
print("new point")
86+
x = random.randint(0, self.canvas_width)
87+
y = random.randint(0, self.canvas_height)
88+
color = (random.uniform(0, 1), random.uniform(
89+
0, 1), random.uniform(0, 1))
90+
# color = (1,1,0)
91+
point = Point(x, y, color)
92+
self.set_points(point)
93+
time.sleep(0.001)
94+
95+
96+
def run(self):
97+
mainloop_thread = threading.Thread(target=self.main, args=())
98+
mainloop_thread.start()
99+
100+
77101

78102

79103
class Point:
@@ -84,21 +108,10 @@ def __init__(self, x, y, color):
84108
x = 0
85109
y = 0
86110
color = (1,1,1)
111+
112+
87113

88114
if __name__ == "__main__":
89-
render = Renderer()
90-
mainloop_thread = threading.Thread(target=render.main, args=())
91-
mainloop_thread.start()
92-
# render.test_points()
93-
while True:
94-
print("new point")
95-
x = random.randint(0, 1000)
96-
y = random.randint(0, 1000)
97-
color = (random.uniform(0, 1), random.uniform(
98-
0, 1), random.uniform(0, 1))
99-
# color = (1,1,0)
100-
point = Point(x, y, color)
101-
render.set_points(point)
102-
time.sleep(0.001)
103-
104-
# t1.start()
115+
render = Renderer(500, 500)
116+
render.run()
117+
render.test_random_points()

test_loader.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from rom_loader import BinaryReader
2+
from rednerer import Renderer
23

34

45
testfile = 'masmix.nes'
@@ -14,3 +15,8 @@ def test_reader():
1415

1516
if __name__ == "__main__":
1617
test_reader()
18+
renderer = Renderer()
19+
renderer.run()
20+
renderer.test_random_points()
21+
22+

0 commit comments

Comments
 (0)