forked from gil9red/SimplePyScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrosette.py
More file actions
69 lines (52 loc) · 1.58 KB
/
Copy pathrosette.py
File metadata and controls
69 lines (52 loc) · 1.58 KB
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
import math
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
"""
Rosette
Introduction
A rosette appears when the points of an n-gon (regular polygon with points
P_i = (R cos(2*pi*i/n),R sin(2*pi*i/n)) ) are connected to all other points of
the n-gon. E.g. when n=5, the result is an outer pentagon and an inner pentagram.
In the code below, first all points of the n-gon are calculated, then a double for
loop connect points i to points i+1,...,n-1,n.
http://www.de-brauwer.be/wiki/wikka.php?wakka=PyOpenGLRosette
"""
N = 25
RADIUS = 95
def init_fun():
glClearColor(1.0, 1.0, 1.0, 0.0)
glColor3f(0.0, 0.0, 0.0)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluOrtho2D(-100, 100, -100, 100)
def reshape_fun(w, h):
glViewport(0, 0, w, h)
# if w > h:
# glViewport((w - h) / 2, 0, h, h)
# else:
# glViewport(0, (h - w) / 2, w, w)
def display_fun():
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(0.0, 0.0, 1.0)
xpts = []
ypts = []
for i in range(0, N):
xpts.append(RADIUS * math.sin(2.0 * math.pi * i / N))
ypts.append(RADIUS * math.cos(2.0 * math.pi * i / N))
glBegin(GL_LINE_STRIP)
for i in range(0, N):
for j in range(i, N):
glVertex2f(xpts[i], ypts[i])
glVertex2f(xpts[j], ypts[j])
glEnd()
glFlush()
if __name__ == "__main__":
glutInit()
glutInitWindowSize(400, 400)
glutCreateWindow(b"Rosette")
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
glutDisplayFunc(display_fun)
glutReshapeFunc(reshape_fun)
init_fun()
glutMainLoop()