-
Notifications
You must be signed in to change notification settings - Fork 0
/
habitable_zone.py
117 lines (89 loc) · 2.63 KB
/
habitable_zone.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
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
106
107
108
109
110
111
112
113
114
115
116
117
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
import numpy
import math
import random
import world_gen
view_theta, view_phi, view_radius = 0.0, math.pi/2.0, 12.0
vtd, vpd, vrd = 0.0, 0.0, 0.0
def view_handler():
global vtd, vpd, vrd, view_theta, view_phi, view_radius
vtd = numpy.clip(vtd, -0.06, 0.06)
vpd = numpy.clip(vpd, -0.06, 0.06)
vrd = numpy.clip(vrd, -0.06, 0.06)
view_theta += vtd
view_phi += vpd
view_radius += vrd
vtd = 0.0 if abs(vtd) < 0.002 else vtd
vpd = 0.0 if abs(vpd) < 0.002 else vpd
vrd = 0.0 if abs(vrd) < 0.002 else vrd
view_x = view_radius*math.cos(view_theta)*math.sin(view_phi)
view_y = view_radius*math.sin(view_theta)*math.sin(view_phi)
view_z = view_radius*math.cos(view_phi)
vtd *= 0.95
vpd *= 0.95
vrd *= 0.95
glLoadIdentity()
gluLookAt(view_x, view_y, view_z, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0)
def display():
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
view_handler()
world_gen.draw_world(world1)
glutSwapBuffers()
def init():
glClearColor(0.1, 0.1, 0.1, 0.0)
glPointSize(4.0)
glLineWidth(2.0)
glClearDepth(1.0)
glDepthFunc(GL_LESS)
glEnable(GL_DEPTH_TEST)
glShadeModel(GL_SMOOTH)
glMatrixMode(GL_PROJECTION)
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
gluPerspective(45.0, float(640)/float(480), 0.1, 100.0)
glMatrixMode(GL_MODELVIEW)
gluLookAt(6.0, 0.0, 0.0,
0.0, 0.0, 0.0,
0.0, 0.0, 1.0)
def keyboard(key, x, y):
global vtd, vpd, vrd, world1
if key == 'r':
wt = world_gen.WorldType()
wt.terrain_type.values[0] = 0.42
wt.terrain_type.values[2] = 0.3
wt.terrain_type.values[3] = 0.4
wt.terrain_type.values[7] = 0.5
world1 = world_gen.create_world(1, random.random(), 0.35, 10, wt)
if key == 's':
world1.world_smooth += 1
world_gen.create_terrain(world1)
if key == 100:
vtd -= 0.01
if key == 102:
vtd += 0.01
if key == 101:
vpd -= 0.01
if key == 103:
vpd += 0.01
if key == 104:
vrd += 0.05
if key == 105:
vrd -= 0.05
def main():
glutInit()
glutInitWindowSize(640, 480)
glutCreateWindow("!!!")
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
glutDisplayFunc(display)
glutIdleFunc(display)
glutKeyboardFunc(keyboard)
glutSpecialFunc(keyboard)
init()
glutMainLoop()
wt = world_gen.WorldType()
wt.terrain_type.values[0] = 0.42
wt.terrain_type.values[7] = 0.5
world1 = world_gen.create_world(1, 33, 0.35, 10, wt)
main()