-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharc.py
62 lines (48 loc) · 1.47 KB
/
arc.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
import glfw
from OpenGL.GL import *
from OpenGL.GLU import *
import numpy as np
def draw_arc(radius, start_angle, end_angle, num_segments):
glBegin(GL_LINE_STRIP)
for i in range(num_segments + 1):
theta = start_angle + (end_angle - start_angle) * i / num_segments
x = radius * np.cos(theta)
y = radius * np.sin(theta)
glVertex2f(x, y)
glEnd()
def main():
# Initialize the library
if not glfw.init():
return
# Create a windowed mode window and its OpenGL context
window = glfw.create_window(800, 800, "Dome Arc", None, None)
if not window:
glfw.terminate()
return
# Make the window's context current
glfw.make_context_current(window)
# Set the viewport
glViewport(0, 0, 800, 800)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(-15, 15, -15, 15, -1, 1)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
radius = 10
start_angle = 0
end_angle = np.pi/3
num_segments = 100
# Loop until the user closes the window
while not glfw.window_should_close(window):
# Render here, e.g. using pyOpenGL
glClear(GL_COLOR_BUFFER_BIT)
# Draw the arc
glColor3f(1.0, 1.0, 1.0)
draw_arc(radius, start_angle, end_angle, num_segments)
# Swap front and back buffers
glfw.swap_buffers(window)
# Poll for and process events
glfw.poll_events()
glfw.terminate()
if __name__ == "__main__":
main()