-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolarsystem.py
More file actions
105 lines (64 loc) · 1.54 KB
/
solarsystem.py
File metadata and controls
105 lines (64 loc) · 1.54 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
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
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import math
xc=0
yc=0
r=10
r1=80
r2=40
angle=0
def clearscreen():
glClearColor(0.0,0.0,0.0,1.0)
gluOrtho2D(-100.0,100.0,100.0,-100.0)
glColor3f(1.0,0.0,0.0)
glPointSize(5.0)
def update(value):
global xc,yc,angle
glutPostRedisplay()
glutTimerFunc(int(1000/60),update,int(0))
xc=80*math.cos(angle)
yc=40*math.sin(angle)
angle=angle+0.1
def setpixel(x,y):
glBegin(GL_POINTS)
glColor3f(0.0,0.0,1.0)
glVertex2f(x,y)
glEnd()
glFlush()
def drawcircle(xc,yc,r):
i=0.0
glColor3f(1.0,1.0,0.0)
glBegin(GL_TRIANGLE_FAN)
glVertex2f(xc,yc)
while i<360:
glVertex2f(r*math.cos(math.pi*i/180)+xc,r*math.sin(math.pi*i/180)+yc)
i=i+0.1
glEnd()
glFlush()
def drawellipse(r1,r2,xc,yc):
x,y=r1,0
angle=0
while angle<360:
x=r1*math.cos(angle)
y=r2*math.sin(angle)
angle=angle+0.1
setpixel(x,y)
def display():
glClear(GL_COLOR_BUFFER_BIT)
global xc,yc,r
drawcircle(0,0,20)
drawellipse(80,40,0,0)
drawcircle(xc,yc,r)
glutSwapBuffers()
def main():
glutInit()
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE)
glutInitWindowSize(500,500)
glutInitWindowPosition(200,200)
glutCreateWindow("Solar system")
glutDisplayFunc(display)
glutTimerFunc(0,update,0)
clearscreen()
glutMainLoop()
main()