Esempio n. 1
0
    def __init__(self):
        ''' The work of maintaining the visible stars at different locations while
    zooming around the galaxy has been delegated to this class
    '''
        self.v = []
        self.names = {
        }  # most stars are unamed so it is more efficient to use a dictionary
        with open('models/hygdata001.csv',
                  'r') as f:  # read the data from the file
            for i, l in enumerate(f.readlines()):
                ln = l.split(',')
                if ln[0] > '':
                    self.names[i] = '' + ln[5] + ' ' + ln[
                        0]  # named star, prefix with constellation
                if ln[1] == '':  # no blue value, use a mid
                    ln[1] = '0.6'
                self.v.append(
                    [float(ln[2]), float(ln[4]),
                     float(ln[3])] +  # z and y swapped to OpenGL orientation.
                    self.bv2rgb(float(ln[1])) + [float(vi) for vi in ln[6:7]] +
                    [1.0 * i])  # last value is for index to names

        self.v = np.array(self.v, dtype='float32')  # and convert to ndarray
        self.xm, self.ym, self.zm = 0.2, 0.0, -2.0
        self.verts, self.norms, self.texs = None, None, None
        self.stars = None
        self.ready = False
        self.select_visible()  # initial run, one off
        self.stars = pi3d.Points(vertices=self.verts,
                                 normals=self.norms,
                                 tex_coords=self.texs,
                                 point_size=15)
        starsh = pi3d.Shader(
            "shaders/star_point")  #shader uses rgb and luninosity
        self.stars.set_shader(starsh)
Esempio n. 2
0
 def position_and_draw(self):
     self.position(self.pos[0], self.pos[1], self.pos[2])
     self.rotateIncY(self.rotation)
     self.draw()
     if self.shell != None:
         self.shell.position(self.pos[0], self.pos[1], self.pos[2])
         self.shell.rotateIncY(self.shell.rotation)
         self.shell.draw()
     if self.track_shader != None:
         self.t_len += 1
         self.t_v.append(tuple(self.pos))
         if (self.t_len % 300) == 0:
             # NB the Points class was only added in pi3d v.1.4 2013/10/17
             self.trace_shape = pi3d.Points(vertices=self.t_v,
                                            material=(1.0, 0.0, 1.0),
                                            point_size=5)
             self.trace_shape.set_shader(self.track_shader)
             if (self.t_len > 2400):
                 self.t_v = self.t_v[-2400:]
                 self.t_len = 2400
         if self.trace_shape:
             self.trace_shape.draw()
Esempio n. 3
0
           pi3d.Texture("textures/blu_ball.png"),
           pi3d.Texture("textures/grn_ball.png")]

loc = np.zeros((MAX_BALLS, 3))
loc[:,0] = np.random.uniform(-HWIDTH, HWIDTH, MAX_BALLS)
loc[:,1] = np.random.uniform(-HHEIGHT, HHEIGHT, MAX_BALLS)
loc[:,2] = np.random.uniform(min_dist, max_dist, MAX_BALLS)
vel = np.random.uniform(-MAX_BALL_VELOCITY, MAX_BALL_VELOCITY, (MAX_BALLS, 2))
dia = (MIN_BALL_SIZE + (max_dist - loc[:,2]) /
                (max_dist - min_dist) * (MAX_BALL_SIZE - MIN_BALL_SIZE))
mass = dia * dia
radii = np.add.outer(dia, dia) / 3.0 # should be / 2.0 this will make balls 'touch' when nearer

color = np.floor(np.random.uniform(0.0, 2.99999, (MAX_BALLS, 3))) 

balls = pi3d.Points(vertices=loc, point_size=MAX_BALL_SIZE, normals=color)
balls.set_draw_details(shader, ballimg)

temperature = 0.6
interact = True
n = 0.0
l_tm = time.time()
while DISPLAY.loop_running():
  balls.draw()
  ##### bounce off walls
  ix = np.where(loc[:,0] < -HWIDTH) # off left side
  vel[ix,0] = np.abs(vel[ix,0]) * temperature # x component +ve
  ix = np.where(loc[:,0] > HWIDTH) # off right
  vel[ix,0] = np.abs(vel[ix,0]) * -temperature # vx -ve
  ix = np.where(loc[:,1] < -HHEIGHT)
  vel[ix,1] = np.abs(vel[ix,1]) * temperature
Esempio n. 4
0
radii = np.add.outer(
    dia, dia) / 7.0  # should be / 2.0 this will make bugs 'touch' when nearer

rot = np.zeros((MAX_BUGS, 3))  # :,0 for rotation
rot[:, 1] = 999.999  # :,1 R, G
rot[:, 2] = 999.999  # :,2 B, A
"""  :,2 for sub-size i.e 8x8 images each is 0.125 but there is 0.0125
margin on each side with 0.1 'useable' image inside. This is to avoid the
corners overlapping other images as they are rotated.
"""
uv = np.zeros((MAX_BUGS, 2))  # u picnum.u v
uv[:, :] = 0.0125  # all start off same. uv is top left corner of square

bugs = pi3d.Points(camera=CAMERA,
                   vertices=loc,
                   normals=rot,
                   tex_coords=uv,
                   point_size=MAX_BUG_SIZE)
bugs.set_draw_details(shader, [img])
bugs.unif[48] = 0.1

temperature = 0.9
interact = True
spin = False
frame_num = 0

while DISPLAY.loop_running():
    bugs.draw()
    frame_num += 1
    ##### bounce off walls
    ix = np.where(loc[:, 0] < -HWIDTH)  # off left side
Esempio n. 5
0
                       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()
Esempio n. 6
0
shader = pi3d.Shader("shaders/uv_sprite")

ballimg = pi3d.Texture("textures/red_ball.png")

loc = np.zeros((MAX_BALLS, 3))
loc[:, 0] = np.random.uniform(-HWIDTH, HWIDTH, MAX_BALLS)
loc[:, 1] = np.random.uniform(-HHEIGHT, HHEIGHT, MAX_BALLS)
loc[:, 2] = np.random.uniform(min_dist, max_dist, MAX_BALLS)
vel = np.random.uniform(-MAX_BALL_VELOCITY, MAX_BALL_VELOCITY, (MAX_BALLS, 2))
dia = (MIN_BALL_SIZE + (max_dist - loc[:, 2]) / (max_dist - min_dist) *
       (MAX_BALL_SIZE - MIN_BALL_SIZE))
mass = dia * dia
radii = np.add.outer(
    dia, dia) / 3.0  # should be / 2.0 this will make balls 'touch' when nearer

balls = pi3d.Points(vertices=loc, point_size=MAX_BALL_SIZE)
balls.set_draw_details(shader, [ballimg])

temperature = 0.9
interact = False

while DISPLAY.loop_running():
    balls.draw()
    ##### bounce off walls
    ix = np.where(loc[:, 0] < -HWIDTH)  # off left side
    vel[ix, 0] = np.abs(vel[ix, 0]) * temperature  # x component +ve
    ix = np.where(loc[:, 0] > HWIDTH)  # off right
    vel[ix, 0] = np.abs(vel[ix, 0]) * -temperature  # vx -ve
    ix = np.where(loc[:, 1] < -HHEIGHT)
    vel[ix, 1] = np.abs(vel[ix, 1]) * temperature
    ix = np.where(loc[:, 1] > HHEIGHT)