Created
September 21, 2015 19:51
-
-
Save krokodilerian/80437cb911ae3db2be4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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=0, y=0) | |
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") | |
#======================================== | |
# Setting 2nd param to True renders 'True' Blending | |
# (this can be changed later to 'False' with 'cloudimg.blend = False') | |
cloudimg = pi3d.Texture("textures/of-cloud2.png",False) | |
earthimg = pi3d.Texture("textures/world_map2.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") | |
mooncld = pi3d.Texture("textures/initlab.png") | |
# Load shapes | |
mysphere = pi3d.Sphere(radius=2, slices=24, sides=24, | |
name="earth", z=9.8) | |
mysphere2 = pi3d.Sphere(radius=2.05, slices=24, sides=24, | |
name="clouds", z=9.8) | |
mymoon = pi3d.Sphere(radius=0.4, slices=16, sides=16, name="moon") | |
mymooncld = pi3d.Sphere(radius=0.41, slices=16, sides=16, name="mooncld") | |
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)) | |
mymooncld.position(mymoon.x(), mymoon.y(), mymoon.z()) | |
mymoon.rotateIncY(-0.1) | |
mymoon2.position(mymoon.x() - m2Rad*sin(rot2), mymoon.y(), | |
mymoon.z() + m2Rad*cos(rot2)) | |
mymoon2.rotateIncZ(0.91) | |
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 | |
mymooncld.draw(shader, [mooncld]) | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment