def __init__(self, snake): self.snake = snake plane = pi3d.Plane(w=BLOCK_SIZE * 2.0, h=BLOCK_SIZE * 2.0) self.shape = pi3d.MergeShape() self.shape.add(plane, 0, 0, 0) self.shape.add(plane, 0, 0, 0, 0, 90, 0) self.shape.set_draw_details(shader, [foodTex]) self.spawn()
def __init__(self, model, recalc_time, refid): self.refid = refid self.recalc_time = recalc_time #in theory use different values for enemy self.x, self.y, self.z = 0.0, 0.0, 0.0 self.x_perr, self.y_perr, self.z_perr = 0.0, 0.0, 0.0 self.x_ierr, self.y_ierr, self.z_ierr = 0.0, 0.0, 0.0 self.d_err = 0.0 self.v_speed, self.h_speed = 0.0, 0.0 self.rollrate, self.pitchrate, self.yaw = 0.0, 0.0, 0.0 self.direction, self.roll, self.pitch = 0.0, 0.0, 0.0 self.max_roll, self.max_pitch = 65, 30 #limit rotations self.ailerons, self.elevator = 0.0, 0.0 self.max_ailerons, self.max_elevator = 10.0, 10.0 #limit conrol surface movement self.VNE = 120 #max speed (Velocity Not to be Exceeded) self.mass = 300 self.a_factor, self.e_factor = 10, 10 self.roll_inrta, self.pitch_inrta = 100, 100 self.max_power = 2000 #force units of thrust really self.lift_factor = 20.0 #randomly adjusted to give required performance! self.power_setting = 0.0 self.throttle_step = 20 self.last_time = time.time() self.last_pos_time = self.last_time self.del_time = None #difference in pi time for other aero c.f. main one self.rtime = 60 self.nearest = None self.other_damage = 0.0 #done to nearest others since last json_load self.damage = 0.0 #done to this aeroplane by others #create the actual model self.model = pi3d.Model(file_string=model, camera=CAMERA) self.model.set_shader(SHADER) self.model.set_normal_shine(flatwhite, 16.0, flatwhite, 0.5) #roration by Les self.model.rotateToX(xoffset) self.model.rotateToY(yoffset) self.model.rotateToZ(zoffset) #create the bullets plane = pi3d.Plane(h=25, w=1) self.bullets = pi3d.MergeShape(camera=CAMERA) #the merge method does rotations 1st Z, 2nd X, 3rd Y for some reason #for multi axis rotations you need to figure it out by rotating a #sheet of paper in the air in front of you (angles counter clockwise)! self.bullets.merge([[plane, -2.0, 0.5, 8.0, 90, 0, 0, 1, 1, 1], [plane, -2.0, 0.5, 8.0, 0, 90, 90, 1, 1, 1], [plane, 2.0, 0.5, 8.0, 90, 0, 0, 1, 1, 1], [plane, 2.0, 0.5, 8.0, 0, 90, 90, 1, 1, 1]]) self.num_b = len(BULLET_TEX) self.seq_b = self.num_b self.bullets.set_draw_details(FLATSH, [BULLET_TEX[0]])
def __init__(self): flatsh = pi3d.Shader("uv_flat") font = pi3d.Pngfont("../fonts/GillSansMT.png", (255,80,0,255)) self.mystring = pi3d.String(font=font, string="CONGRATULATION", size=2, x=0, y=-0, z=-0.5, is_3d=True, rx = 0) #self.mystring2 = pi3d.String(font=font, string="YOU ARE A HERO !!!", size=0.8, x=0, y=-0.2, z=0.5, is_3d=True, rx = 270) #mystring.translate(0.0, 0.0, 1) self.mystring.scale(3, 3, 3) self.mystring.set_shader(flatsh) #self.mystring2.scale(3, 3, 3) #self.mystring2.set_shader(flatsh) self.myplane = pi3d.Plane(w=6, h=2, name="plane") #self.myplane = pi3d.Cylinder(radius=3, height=0.1, name="plane", rx = 90) #self.myplane.set_shader(flatsh) self.myplane.add_child(self.mystring) #self.myplane.add_child(self.mystring2) """
thickness=0.3, ringrots=12, sides=24, name="Torus", x=2, y=-1, z=10) myhemisphere = pi3d.Sphere(radius=1, sides=24, slices=24, hemi=0.5, name="hsphere", x=4, y=-1, z=10) myPlane = pi3d.Plane(w=4, h=4, name="plane", z=12) # Load ttf font and set the font colour to 'raspberry' arialFont = pi3d.Font("fonts/FreeMonoBoldOblique.ttf", (221, 0, 170, 255)) mystring = pi3d.String(font=arialFont, string="Now the Raspberry Pi really does rock", z=4) mystring.set_shader(flatsh) # Fetch key presses mykeys = pi3d.Keyboard() angl = 0.0 # Display scene while DISPLAY.loop_running(): mysphere.draw(shader, [patimg]) mysphere.rotateIncY(0.5)
# environment cube ectex = pi3d.Texture("textures/ecubes/skybox_stormydays.jpg") myecube = pi3d.EnvironmentCube(camera, light, 900.0, "CROSS") myecube.set_draw_details(flatsh, [ectex]) #ball maxdsz = 0.3 radius = 1.0 ball = pi3d.Sphere(camera, light, radius, 12, 12, 0.0, "sphere", -4, 8, -7) # Shape.set_draw_details is a wrapper for calling the method on each item in buf # as is done explicitly here for no reason than to show that it can be done! ball.set_draw_details(shader, [ballimg], 0.0, 0.0) #monster monster = pi3d.Plane(camera, light, 5.0, 5.0, "monster", 0, 0, 0, 0, 0, 0) monster.set_draw_details(flatsh, [monstimg]) # Create elevation map mapwidth = 50.0 mapdepth = 50.0 maphalf = 22.0 mapheight = 40.0 mymap = pi3d.ElevationMap("textures/pong.jpg", camera=camera, light=light, width=mapwidth, depth=mapdepth, height=mapheight, divx=32,
space=0.02, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(textblock) """ back_shader = pi3d.Shader("mat_flat") text_bkg = pi3d.Sprite(w=DISPLAY.width, h=90, y=-DISPLAY.height * 0.4 - 20, z=4.0) text_bkg.set_shader(back_shader) text_bkg.set_material((0, 0, 0)) """ bkg_ht = DISPLAY.height // 3 text_bkg_array = np.zeros((bkg_ht, 1, 4), dtype=np.uint8) text_bkg_array[:, :, 3] = np.linspace(0, 170, bkg_ht).reshape(-1, 1) text_bkg_tex = pi3d.Texture(text_bkg_array, blend=True, free_after_load=True) text_bkg = pi3d.Plane(w=DISPLAY.width, h=bkg_ht, y=-DISPLAY.height // 2 + bkg_ht // 2, z=4.0) back_shader = pi3d.Shader("uv_flat") text_bkg.set_draw_details(back_shader, [text_bkg_tex]) num_run_through = 0 while DISPLAY.loop_running(): tm = time.time() if (tm > nexttm and not paused ) or (tm - nexttm) >= 86400.0: # this must run first iteration of loop if nFi > 0: nexttm = tm + time_delay sbg = sfg sfg = None start_pic_num = next_pic_num loop_count = 0
DISPLAY = pi3d.Display.create() DISPLAY.set_background(0, 0, 0, 1) # r,g,b,alpha # eyeRadius is the size, in pixels, at which the whole eye will be rendered. if DISPLAY.width <= (DISPLAY.height * 2): # For WorldEye, eye size is -almost- full screen height eyeRadius = DISPLAY.height / 2.1 else: eyeRadius = DISPLAY.height * 2 / 5 #cam = pi3d.Camera(is_3d=False, at=(0,0,0), eye=(0,0,-1000)) #shader = pi3d.Shader("uv_light") shader = pi3d.Shader("2d_flat") light = pi3d.Light(lightpos=(0, -500, -500), lightamb=(0.2, 0.2, 0.2)) eyePlane = pi3d.Plane(w=DISPLAY.width, h=DISPLAY.height, name="eyeplane", z=12) #xrat = DISPLAY.width/neutral.ix #yrat = DISPLAY.height/neutral.iy #if yrat < xrat: # xrat = yrat #wi, hi = neutral.ix * xrat, neutral.iy * xrat #wi, hi = tex.ix, tex.iy #xi = (DISPLAY.width - wi)/2 #yi = (DISPLAY.height - hi)/2 #Create canvas canvas = pi3d.Canvas() canvas.set_shader(shader) #initialize timers
class Main(object): # Setup display and initialise pi3d DISPLAY = pi3d.Display.create() pi3d.Light(lightpos=(1, -1, -3), lightcol=(1.0, 1.0, 0.8), lightamb=(0.25, 0.2, 0.3)) # load shader shader = pi3d.Shader("uv_bump") shinesh = pi3d.Shader("uv_reflect") flatsh = pi3d.Shader("uv_flat") tree2img = pi3d.Texture("textures/tree2.png") tree1img = pi3d.Texture("textures/tree1.png") hb2img = pi3d.Texture("textures/hornbeam2.png") bumpimg = pi3d.Texture("textures/grasstile_n.jpg") reflimg = pi3d.Texture("textures/stars.jpg") rockimg = pi3d.Texture("textures/rock1.jpg") FOG = ((0.3, 0.3, 0.4, 0.8), 650.0) TFOG = ((0.2, 0.24, 0.22, 1.0), 150.0) #myecube = pi3d.EnvironmentCube(900.0,"HALFCROSS") ectex = pi3d.loadECfiles("textures/ecubes", "sbox") myecube = pi3d.EnvironmentCube(size=900.0, maptype="FACES", name="cube") myecube.set_draw_details(flatsh, ectex) # Create elevation map mapsize = 1000.0 mapheight = 60.0 mountimg1 = pi3d.Texture("textures/mountains3_512.jpg") mymap = pi3d.ElevationMap("textures/mountainsHgt.png", name="map", width=mapsize, depth=mapsize, height=mapheight, divx=32, divy=32) mymap.set_draw_details(shader, [mountimg1, bumpimg, reflimg], 128.0, 0.0) mymap.set_fog(*FOG) #Create tree models treeplane = pi3d.Plane(w=4.0, h=5.0) treemodel1 = pi3d.MergeShape(name="baretree") treemodel1.add(treeplane.buf[0], 0, 0, 0) treemodel1.add(treeplane.buf[0], 0, 0, 0, 0, 90, 0) treemodel2 = pi3d.MergeShape(name="bushytree") treemodel2.add(treeplane.buf[0], 0, 0, 0) treemodel2.add(treeplane.buf[0], 0, 0, 0, 0, 60, 0) treemodel2.add(treeplane.buf[0], 0, 0, 0, 0, 120, 0) #Scatter them on map using Merge shape's cluster function mytrees1 = pi3d.MergeShape(name="trees1") mytrees1.cluster(treemodel1.buf[0], mymap, 0.0, 0.0, 200.0, 200.0, 20, "", 8.0, 3.0) mytrees1.set_draw_details(flatsh, [tree2img], 0.0, 0.0) mytrees1.set_fog(*TFOG) mytrees2 = pi3d.MergeShape(name="trees2") mytrees2.cluster(treemodel2.buf[0], mymap, 0.0, 0.0, 200.0, 200.0, 20, "", 6.0, 3.0) mytrees2.set_draw_details(flatsh, [tree1img], 0.0, 0.0) mytrees2.set_fog(*TFOG) mytrees3 = pi3d.MergeShape(name="trees3") mytrees3.cluster(treemodel2, mymap, 0.0, 0.0, 300.0, 300.0, 20, "", 4.0, 2.0) mytrees3.set_draw_details(flatsh, [hb2img], 0.0, 0.0) mytrees3.set_fog(*TFOG) #Create monument monument = pi3d.Model(file_string="models/pi3d.obj", name="monument") monument.set_shader(shinesh) monument.set_normal_shine(bumpimg, 16.0, reflimg, 0.4) monument.set_fog(*FOG) monument.translate(100.0, -mymap.calcHeight(100.0, 235) + 12.0, 235.0) monument.scale(20.0, 20.0, 20.0) monument.rotateToY(65) #avatar camera rot = 0.0 tilt = 0.0 avhgt = 3.5 xm = 0.0 zm = 0.0 ym = mymap.calcHeight(xm, zm) + avhgt go_flag = False go_speed = 0.2 CAMERA = pi3d.Camera.instance() def pi3dloop(self, dt): self.DISPLAY.loop_running() self.CAMERA.reset() self.CAMERA.rotate(self.tilt, self.rot, 0) self.CAMERA.position((self.xm, self.ym, self.zm)) self.myecube.position(self.xm, self.ym, self.zm) # for opaque objects it is more efficient to draw from near to far as the # shader will not calculate pixels already concealed by something nearer self.myecube.draw() self.mymap.draw() dx = math.copysign(self.mapsize, self.xm) dz = math.copysign(self.mapsize, self.zm) mid = 0.3 * self.mapsize if abs(self.xm) > mid: #nearing edge self.mymap.position(dx, 0.0, 0.0) self.mymap.draw() if abs(self.zm) > mid: #other edge self.mymap.position(0.0, 0.0, dz) self.mymap.draw() if abs(self.xm) > mid: #i.e. in corner, both edges self.mymap.position(dx, 0.0, dz) self.mymap.draw() self.mymap.position(0.0, 0.0, 0.0) self.monument.draw() self.mytrees1.draw() self.mytrees2.draw() self.mytrees3.draw() if pi3d.PLATFORM == PLATFORM_ANDROID: #***************************** if self.DISPLAY.android.screen.moved: self.rot -= self.DISPLAY.android.screen.touch.dx * 0.25 self.tilt += self.DISPLAY.android.screen.touch.dy * 0.25 self.DISPLAY.android.screen.moved = False self.DISPLAY.android.screen.tapped = False elif self.DISPLAY.android.screen.tapped: self.go_speed *= 1.5 self.DISPLAY.android.screen.tapped = False elif self.DISPLAY.android.screen.double_tapped: self.go_flag = not self.go_flag self.DISPLAY.android.screen.double_tapped = False else: mx, my = self.mymouse.position() #if mx>display.left and mx<display.right and my>display.top and my<display.bottom: self.rot -= (mx - self.omx) * 0.2 self.tilt += (my - self.omy) * 0.2 self.omx = mx self.omy = my #Press ESCAPE to terminate k = self.mykeys.read() if k > -1: if k == ord('w'): #key W self.go_flag = not self.go_flag elif k == 27: #Escape key return False if self.go_flag: self.xm -= math.sin(math.radians(self.rot)) * self.go_speed self.zm += math.cos(math.radians(self.rot)) * self.go_speed self.ym = self.mymap.calcHeight(self.xm, self.zm) + self.avhgt halfmap = self.mapsize / 2.0 # save doing this four times! self.xm = (self.xm + halfmap) % self.mapsize - halfmap self.zm = (self.zm + halfmap) % self.mapsize - halfmap else: self.go_speed = 0.2 return True def run(self): if pi3d.PLATFORM == PLATFORM_ANDROID: #***************************** self.DISPLAY.android.set_loop(self.pi3dloop) self.DISPLAY.android.run() else: # Fetch key presses self.mykeys = pi3d.Keyboard() self.mymouse = pi3d.Mouse(restrict=False) self.mymouse.start() self.omx, self.omy = self.mymouse.position() while self.pi3dloop(0.0): pass self.mykeys.close() self.mymouse.stop() self.DISPLAY.stop()
shader = pi3d.Shader("uv_light") coffimg = pi3d.Texture("../textures/COFFEE.PNG") flatsh = pi3d.Shader("uv_flat") #font = pi3d.Pngfont("../fonts/GillSansMT.png", (221,0,170,255)) font = pi3d.Pngfont("../fonts/GillSansMT.png", (20, 10, 250, 255)) mystring = pi3d.String(font=font, string="Ready to play ??", size=0.8, x=2, y=2, z=2, is_3d=True) #mystring.translate(0.0, 0.0, 1) mystring.scale(3, 3, 3) mystring.set_shader(flatsh) myPlane = pi3d.Plane(w=4, h=1.2, name="plane", z=5) # Fetch key presses mykeys = pi3d.Keyboard() mymouse = pi3d.Mouse(restrict=False) mymouse.start() pos_armR = [0, 0, 0] pos_forarmR = [0, 0, 0] pos_armL = [0, 0, 0] pos_forarmL = [0, 0, 0] body_orientation = 0 joystick_h_axis_pos = 0.0 joystick_v_axis_pos = 0.0 joystick_right_h_axis_pos = 0.0 joystick_right_v_axis_pos = 0.0
def __init__(self): # load shader shader = pi3d.Shader("uv_bump") #shinesh = pi3d.Shader("uv_reflect") flatsh = pi3d.Shader("uv_flat") tree1img = pi3d.Texture("../textures/tree1.png") tree2img = pi3d.Texture("../textures/tree2.png") hb2img = pi3d.Texture("../textures/hornbeam2.png") bumpimg = pi3d.Texture("../textures/grasstile_n.jpg") reflimg = pi3d.Texture("../textures/stars.jpg") floorimg = pi3d.Texture("../textures/floor_nm.jpg") FOG = ((0.3, 0.3, 0.4, 0.8), 650.0) TFOG = ((0.2, 0.24, 0.22, 1.0), 150.0) ectex=pi3d.loadECfiles("../textures/ecubes","sbox") self.myecube = pi3d.EnvironmentCube(size=900.0, maptype="FACES", name="cube") self.myecube.set_draw_details(flatsh, ectex) self.myecube.position(0,0,0) # Create elevation map mapsize = 1000.0 mapheight = 60.0 mountimg1 = pi3d.Texture("../textures/mountains3_512.jpg") self.mymap = pi3d.ElevationMap("../textures/mountainsHgt.png", name="map", width=mapsize, depth=mapsize, height=mapheight, divx=32, divy=32) self.mymap.set_draw_details(shader, [mountimg1, bumpimg, reflimg], 128.0, 0.0) self.mymap.set_fog(*FOG) self.building = pi3d.Model(file_string="../models/ConferenceHall/conferencehall.egg", name="Hall", sx=0.1, sy=0.1, sz=0.1) self.building.set_shader(flatsh) #Create tree models treeplane = pi3d.Plane(w=4.0, h=5.0) treemodel1 = pi3d.MergeShape(name="baretree") treemodel1.add(treeplane.buf[0], 0,0,0) treemodel1.add(treeplane.buf[0], 0,0,0, 0,90,0) treemodel2 = pi3d.MergeShape(name="bushytree") treemodel2.add(treeplane.buf[0], 0,0,0) treemodel2.add(treeplane.buf[0], 0,0,0, 0,60,0) treemodel2.add(treeplane.buf[0], 0,0,0, 0,120,0) #Scatter them on map using Merge shape's cluster function self.mytrees1 = pi3d.MergeShape(name="trees1") self.mytrees1.cluster(treemodel1.buf[0], self.mymap,0.0,0.0,200.0,200.0,20,"",8.0,3.0) self.mytrees1.set_draw_details(flatsh, [tree2img], 0.0, 0.0) self.mytrees1.set_fog(*TFOG) self.mytrees2 = pi3d.MergeShape(name="trees2") self.mytrees2.cluster(treemodel2.buf[0], self.mymap,0.0,0.0,200.0,200.0,20,"",6.0,3.0) self.mytrees2.set_draw_details(flatsh, [tree1img], 0.0, 0.0) self.mytrees2.set_fog(*TFOG) self.mytrees3 = pi3d.MergeShape(name="trees3") self.mytrees3.cluster(treemodel2, self.mymap,0.0,0.0,300.0,300.0,20,"",4.0,2.0) self.mytrees3.set_draw_details(flatsh, [hb2img], 0.0, 0.0) self.mytrees3.set_fog(*TFOG) #screenshot number scshots = 1
shapeshine = pi3d.Texture("textures/stars.jpg") #Create shape myshape = pi3d.MergeShape() num = (2, 2) asphere = pi3d.Sphere(sides=32) for i in range(num[0]): for j in range(num[1]): myshape.add(asphere, -num[0] * 0.9 + 1.8 * i, -num[1] * 0.9 + 1.8 * j, 0.0) myshape.position(0.0, 0.0, 5) myshape.set_draw_details(shader, [shapeimg, shapebump, shapeshine], 1.0, 0.1) myshape.set_material((1.0, 0.5, 0.2, 0.5)) mywater = pi3d.Plane(w=130.0, h=130.0) mywater.set_draw_details(matsh, [waterbump[0], shapeshine], 12.0, 0.6) mywater.set_material((0.0, 0.05, 0.1)) mywater.set_fog((0.4, 0.6, 0.8, 0.0), 150) mywater.rotateToX(90.001) mywater.position(0.0, -2.0, 0.0) arialFont = pi3d.Font( "fonts/FreeMonoBoldOblique.ttf", "#dd00aa") #load ttf font and set the font colour to 'raspberry' mystring = pi3d.String(font=arialFont, string="Now the Raspberry Pi really does rock") mystring.translate(0.0, 0.0, 1) mystring.set_shader(flatsh) tick = 0
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,
flatsh = pi3d.Shader("uv_flat") asteroidShader = pi3d.Shader("uv_light") spaceShipTexture = pi3d.Texture('spaceshipTexture.jpg') asteroidSmall = pi3d.Texture('asteroidSmall.jpg') asteroidBig = pi3d.Texture('asteroidBig.jpg') asteroidMed = pi3d.Texture('asteroidM.jpg') backgroundTexture = pi3d.Texture('background.png') dangerZoneTexture = pi3d.Texture('dangerZone.jpg') safeZoneTexture = pi3d.Texture('safeZone.jpg') ship = pi3d.Sphere(z=20.0) asteroid = pi3d.Sphere(radius=50, z=520) spaceRocket = pi3d.Model(file_string='ship.obj', name='rocket', z=500.0) #spaceRocket.set_shader(flatsh) background = pi3d.Plane(w=1920, h=1080, name="stars", z=800) escapeSimulation = pi3d.Keyboard() newCoordinates = {'x': 4, 'y': 0, 'z': 1} flashGreen = "./FlashGreen" flashRed = "./FlashRed" pressure = './ReadPressure' sensorDataText = "./PrintSensorData" temp = './ReadTemperature' humidity = './PrintHumidityData' timeStamps = './TimeStamps' readOrientation = './ReadOrientation' health8 = './Health8' health7 = './Health7' health6 = './Health6' health5 = './Health5'
def __init__(self, config): # noinspection PyBroadException try: locale.setlocale(locale.LC_TIME, config.local) except Exception as e: log.warning("error trying to set local to {}".format(config.local), e) self._display = pi3d.Display.create( x=config.display_x, y=config.display_y, w=config.display_w, h=config.display_h, frames_per_second=config.fps, display_config=pi3d.DISPLAY_CONFIG_HIDE_CURSOR, background=config.background, ) self._camera = pi3d.Camera(is_3d=False) shader = pi3d.Shader(config.shader) self._slide = pi3d.Sprite( camera=self._camera, w=self._display.width, h=self._display.height, z=5.0 ) self._slide.set_shader(shader) self._slide.unif[47] = config.edge_alpha self._slide.unif[54] = config.blend_type self._slide.unif[55] = 1.0 # brightness used by shader [18][1] if config.keyboard: self.keyboard = pi3d.Keyboard() grid_size = math.ceil(len(config.codepoints) ** 0.5) font = pi3d.Font( config.font_file, codepoints=config.codepoints, grid_size=grid_size ) self._text = pi3d.PointText( font, self._camera, max_chars=200, point_size=config.show_text_sz ) self._textblock = pi3d.TextBlock( x=0, y=-self._display.height // 2 + (config.show_text_sz // 2) + 20, z=0.1, rot=0.0, char_count=199, text_format="{}".format(" "), size=0.99, spacing="F", justify=0.5, space=0.02, colour=(1.0, 1.0, 1.0, 1.0), ) self._text.add_text_block(self._textblock) bkg_ht = self._display.height // 4 text_bkg_array = np.zeros((bkg_ht, 1, 4), dtype=np.uint8) text_bkg_array[:, :, 3] = np.linspace(0, 170, bkg_ht).reshape(-1, 1) text_bkg_tex = pi3d.Texture(text_bkg_array, blend=True, free_after_load=True) self._text_bkg = pi3d.Plane( w=self._display.width, h=bkg_ht, y=-self._display.height // 2 + bkg_ht // 2, z=4.0, ) back_shader = pi3d.Shader("uv_flat") self._text_bkg.set_draw_details(back_shader, [text_bkg_tex]) self._foreground_slide = None self._background_slide = None
# Create elevation map mapsize = 1000.0 mapheight = 60.0 mountimg1 = pi3d.Texture("textures/mountains3_512.jpg") mymap = pi3d.ElevationMap("textures/mountainsHgt.png", name="map", width=mapsize, depth=mapsize, height=mapheight, divx=32, divy=32) mymap.set_draw_details(shader, [mountimg1, bumpimg, reflimg], 128.0, 0.0) mymap.set_fog(*FOG) #Create tree models treeplane = pi3d.Plane(w=4.0, h=5.0) treemodel1 = pi3d.MergeShape(name="baretree") treemodel1.add(treeplane.buf[0], 0, 0, 0) treemodel1.add(treeplane.buf[0], 0, 0, 0, 0, 90, 0) treemodel2 = pi3d.MergeShape(name="bushytree") treemodel2.add(treeplane.buf[0], 0, 0, 0) treemodel2.add(treeplane.buf[0], 0, 0, 0, 0, 60, 0) treemodel2.add(treeplane.buf[0], 0, 0, 0, 0, 120, 0) #Scatter them on map using Merge shape's cluster function mytrees1 = pi3d.MergeShape(name="trees1") mytrees1.cluster(treemodel1.buf[0], mymap, 0.0, 0.0, 400.0, 400.0, 50, "", 8.0, 3.0) mytrees1.set_draw_details(flatsh, [tree2img], 0.0, 0.0)
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(),
myecube = pi3d.EnvironmentCube(size=900.0, maptype="FACES", name="cube") myecube.set_draw_details(flatsh, ectex) # Create elevation map mapwidth = 1000.0 mapdepth = 1000.0 mapheight = 45.0 # can't cope with much elevation mountimg1 = pi3d.Texture("textures/mountains3_512.jpg") mymap = pi3d.ElevationMap("textures/mountainsHgt.jpg", name="map", width=mapwidth, depth=mapdepth, height=mapheight, divx=32, divy=32) #testislands.jpg mymap.set_draw_details(shader, [mountimg1, bumpimg, bumpimg], 128.0, 0.0) mymap.set_fog(*FOG) #Create tree models treeplane = pi3d.Plane(w=4.0, h=5.0) treemodel1 = pi3d.MergeShape(name="baretree") treemodel1.merge([[treeplane, 0,0,0, 0,0,0, 1,1,1], [treeplane, 0,0,0, 0,90,0, 1,1,1]]) treemodel2 = pi3d.MergeShape(name="bushytree") treemodel2.merge([[treeplane, 0,0,0, 0,0,0, 1,1,1], [treeplane, 0,0,0, 0,60,0, 1,1,1], [treeplane, 0,0,0, 0,120,0, 1,1,1]]) #Scatter them on map using Merge shape's cluster function mytrees1 = pi3d.MergeShape(name="trees1") mytrees1.cluster(treemodel1.buf[0], mymap, 50.0, 200.0, 50.0, 500.0, 50, "", 5.0, 20.0) mytrees1.set_draw_details(flatsh, [tree2img], 0.0, 0.0) mytrees1.set_fog(*TFOG)
w=1000, h=1000, background=(0, 0, 0, 1), use_pygame=True, frames_per_second=60) shader = pi3d.Shader('uv_light') pi3d.Light(lightpos=(1, -1, -3), lightcol=(1.0, 1.0, 0.8), lightamb=(0.25, 0.2, 0.3)) flatsh = pi3d.Shader("uv_flat") spaceShipTexture = pi3d.Texture('spaceshipTexture.jpg') #backgroundTexture = pi3d.Texture('spaceTexture.jpg') ship = pi3d.Sphere(z=20.0) background = pi3d.Plane(w=50, h=50, name="stars", z=30) escapeSimulation = pi3d.Keyboard() newCoordinates = {'x': 1, 'y': 1, 'z': 1} flashGreen = "./FlashGreen" flashRed = "./FlashRed" pressure = './ReadPressure' temp = './ReadTemperature' CAMERA = pi3d.Camera.instance() CAMERA = pi3d.Camera.instance() #################### #this block added for fast text changing import time CAMERA2D = pi3d.Camera(is_3d=False) myfont = pi3d.Font('FreeSans.ttf', codepoints='0123456789. FPStm:') myfont.blend = True