forked from pi3d/pi3d_demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStarfield.py
63 lines (55 loc) · 1.9 KB
/
Starfield.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
#!/usr/bin/python
from __future__ import absolute_import, division, print_function, unicode_literals
""" Use of points by using set_point_size() to a non-zero value. There is
no attempt to 'tile' the points to give continuous motion
"""
import random
import demo
import pi3d
from six.moves import xrange
# 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_reflect")
flatsh = pi3d.Shader("uv_flat")
matsh = pi3d.Shader("mat_flat")
earthimg = pi3d.Texture("textures/world_map.jpg")
starsimg = pi3d.Texture("textures/stars.jpg")
# Load shapes
mysphere = pi3d.Sphere(radius=2, slices=24, sides=24,
name="earth", x=10, y=-5, z=180)
mysphere.set_draw_details(shader, [earthimg])
myplane = pi3d.Plane(w=500, h=500, name="stars", z=400)
myplane.set_draw_details(flatsh, [starsimg])
"""create the shape to hold the points. This could be encapsulated in its
own class to generate the required distribution and shield the user from
having to explicitly create the Buffer object and set the Shape.buf list
"""
verts = []
for i in xrange(30000):
verts.append((random.random() - 0.5, random.random() - 0.5, random.random() - 0.5))
# NB the Points class was only added in pi3d v.1.4 2013/10/17
mystars = pi3d.Points(vertices=verts, material=(0.9, 0.9, 1.0), point_size=50,
sx=100, sy=100, sz=500)
mystars.set_shader(matsh)
# Fetch key presses
mykeys = pi3d.Keyboard()
# Display scene
while DISPLAY.loop_running():
mysphere.rotateIncY(-0.5)
mysphere.positionZ(mysphere.z() - 0.5)
mystars.positionZ(mystars.z() - 0.5)
if mystars.z() < 75:
mystars.positionZ(250)
mysphere.positionZ(180)
mystars.draw()
mysphere.draw()
myplane.draw()
k = mykeys.read()
if k >-1:
if k==112:
pi3d.screenshot("earth1.jpg")
elif k==27:
mykeys.close()
DISPLAY.stop()
break