8
8
9
9
class Renderer :
10
10
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
12
18
13
19
def init (self ):
14
20
glClearColor (0 , 0 , 0 , 0 )
15
- gluOrtho2D (0 ,1000 , 0 , 1000 )
21
+ gluOrtho2D (0 ,self . canvas_width , 0 , self . canvas_height )
16
22
17
23
def test (self ):
18
24
glClear (GL_COLOR_BUFFER_BIT )
@@ -59,7 +65,7 @@ def draw_scene(self):
59
65
def main (self ):
60
66
glutInit (sys .argv )
61
67
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB )
62
- glutInitWindowSize (1000 , 1000 )
68
+ glutInitWindowSize (self . canvas_width , self . canvas_height )
63
69
glutInitWindowPosition (50 , 50 )
64
70
glutCreateWindow ("FUCkCPP" )
65
71
self .init ()
@@ -69,11 +75,29 @@ def main(self):
69
75
70
76
def test_points (self ):
71
77
print ("Test Point" )
72
- for i in range (1000 ):
78
+ for i in range (self . canvas_height ):
73
79
point = Point (i , i ,(1 ,0 ,1 ))
74
80
self .set_points (point )
75
81
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
+
77
101
78
102
79
103
class Point :
@@ -84,21 +108,10 @@ def __init__(self, x, y, color):
84
108
x = 0
85
109
y = 0
86
110
color = (1 ,1 ,1 )
111
+
112
+
87
113
88
114
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 ()
0 commit comments