forked from pi3d/pi3d_demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Earth.py
74 lines (68 loc) · 2.55 KB
/
Earth.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
#!/usr/bin/python
from __future__ import absolute_import, division, print_function, unicode_literals
""" Simple textruring of Sphere objects against a plane. The atmosphere has
blend set to True and so has to be drawn after object behind it to allow them
to show through. Normal map used for moon is just a 'normal' pictures so normals
are calculated strangely and create odd shadows.
Uses the import pi3d method to load *everything*
"""
from math import sin, cos
import demo
import pi3d
# Setup display and initialise pi3d
DISPLAY = pi3d.Display.create(x=50, y=50)
DISPLAY.set_background(0,0,0,1) # r,g,b,alpha
shader = pi3d.Shader("uv_light")
shinesh = pi3d.Shader("uv_reflect")
flatsh = pi3d.Shader("uv_flat")
light = pi3d.Light(lightpos=(1.0, 0.0, 0.1))
#========================================
# Setting 2nd param to True renders 'True' Blending
# (this can be changed later to 'False' with 'cloudimg.blend = False')
cloudimg = pi3d.Texture("textures/earth_clouds.png",True)
earthimg = pi3d.Texture("textures/world_map.jpg")
moonimg = pi3d.Texture("textures/moon.jpg")
starsimg = pi3d.Texture("textures/stars2.jpg")
watimg = pi3d.Texture("textures/water.jpg")
moonbmp = pi3d.Texture("textures/moon_nm.jpg")
# Load shapes
mysphere = pi3d.Sphere(radius=2, slices=24, sides=24,
name="earth", z=5.8)
mysphere2 = pi3d.Sphere(radius=2.05, slices=24, sides=24,
name="clouds", z=5.8)
mymoon = pi3d.Sphere(radius=0.4, slices=16, sides=16, name="moon")
mymoon2 = pi3d.Sphere(radius=0.15, slices=16, sides=16, name="moon2")
myplane = pi3d.Plane(w=50, h=50, name="stars", z=30)
# Fetch key presses
mykeys = pi3d.Keyboard()
rot=0.0
rot1=90.0
rot2=0.0
m1Rad = 4 # radius of moon orbit
m2Rad = 0.6 # radius moon's moon orbit
# Display scene
while DISPLAY.loop_running():
myplane.rotateIncZ(0.01)
mysphere.rotateIncY(-0.1)
mysphere2.rotateIncY(-0.14)
mymoon.position(mysphere.x() + m1Rad*sin(rot1), mysphere.y(),
mysphere.z() - m1Rad*cos(rot1))
mymoon.rotateIncY(-0.1)
mymoon2.position(mymoon.x() - m2Rad*sin(rot2), mymoon.y(),
mymoon.z() + m2Rad*cos(rot2))
mymoon2.rotateIncZ(-0.61)
mysphere.draw(shader, [earthimg])
mymoon.draw(shinesh, [moonimg, moonbmp], 6.0, 0.0)
mymoon2.draw(shinesh, [watimg, moonbmp, starsimg], 3.0, 0.8)
myplane.draw(flatsh,[starsimg])
mysphere2.draw(shader, [cloudimg]) # this has to be last as blend = True
rot1 += 0.005
rot2 += 0.021
k = mykeys.read()
if k >-1:
if k==112:
pi3d.screenshot("earth1.jpg")
elif k==27:
mykeys.close()
DISPLAY.stop()
break