def __init__(self, sprites): # Instantiate an Asteroid Generator self.gen = asteroids.AsteroidGenerator(ASTEROIDS, 0.1, None, shader_explosion, shader_uv_flat) self.bullet_gen = bullets.BulletGenerator() self.active_asteroids = {} self.asteroid_id = 0 self.active_bullets = [] self.hit_asteroids = [] self.azimuth = 0.0 self.incl = 0.0 self.self_hit = -1 self.sprites = sprites self.fixed_sprites = [] self.lives = INITIAL_LIVES self.scores = 0 self.scores_changed = True self.pause = False self.free_play = False self.fire_button_state = 1 self.frames = 0 self.mode = [MODE_READY, READY_TIME] self.ready_text = pi3d.String(font=FONT_BALLS, string="READY?", x=-.3, y=1, z=3.9, sx=0.018, sy=0.018) self.ready_text.set_shader(shader_uv_flat) self.go_text = pi3d.String(font=FONT_BALLS, string="GO!", x=-.2, y=0.8, z=3.9 + 5 * .5, sx=0.018, sy=0.018) self.go_text.set_shader(shader_uv_flat) # Initial sprite location s = self.sprites['sight'] s.position(*SIGHT_POSITION) s.scale(*SIGHT_SCALE) self.fixed_sprites.append(s) s = sprites['radar_panel'] s.position(*RADAR_PANEL_POSITION) s.scale(*RADAR_PANEL_SCALE) self.fixed_sprites.append(s) self.radar_target = sprites['radar_target'] self.radar_target.scale(*TARGET_SCALE) self.life_full = sprites['life_full'] self.life_full.scale(*LIFE_BAR_SCALE) self.life_empty = sprites['life_empty'] self.life_empty.scale(*LIFE_BAR_SCALE)
def main(): CAMERA = pi3d.Camera.instance() tex = pi3d.Texture("textures/stripwood.jpg") flatsh = pi3d.Shader("uv_flat") #Define the coordinates for our shape (x,y,z) A = (-1.0, -1.0, -1.0) B = (1.0, -1.0, 1.0) C = (-1.0, -1.0, 1.0) D = (-1.0, 1.0, 1.0) ids = ["A", "B", "C", "D"] coords = [A, B, C, D] my_tetra = pi3d.Tetrahedron(x=0.0, y=0.0, z=0.0, corners=(A, B, C, D)) my_tetra.set_draw_details(flatsh, [tex]) # Load ttf font and set the font to black arial_font = pi3d.Font("fonts/FreeMonoBoldOblique.ttf", "#000000") mystring = [] #Create string objects to show the coordinates for i, pos in enumerate(coords): mystring.append( pi3d.String(font=arial_font, string=ids[i] + str(pos), x=pos[0], y=pos[1], z=pos[2])) mystring.append( pi3d.String(font=arial_font, string=ids[i] + str(pos), x=pos[0], y=pos[1], z=pos[2], ry=180)) for string in mystring: string.set_shader(flatsh) cam_rad = 4.0 # radius of camera position rot = 0.0 # rotation of camera tilt = 0.0 # tilt of camera #Main display loop while DISPLAY.loop_running() and not \ INPUTS.key_state("KEY_ESC"): INPUTS.do_input_events() #Note:Some mice devices will be located on #get_mouse_movement(1) instead of get_mouse_movement() mx, my, mv, mh, md = INPUTS.get_mouse_movement() #mx, my, mv, mh, md = inputs.get_mouse_movement(1) rot -= (mx) * 0.2 tilt -= (my) * 0.2 CAMERA.reset() CAMERA.rotate(-tilt, rot, 0) CAMERA.position((cam_rad * sin(radians(rot)) * cos(radians(tilt)), cam_rad * sin(radians(tilt)), -cam_rad * cos(radians(rot)) * cos(radians(tilt)))) #Draw the Tetrahedron my_tetra.draw() for string in mystring: string.draw()
def update(self): """ draws text data on the screen, currently, gps data and pending tiles to draw usually takes 1~5ms 250ms when updating! """ if (datetime.now() - self.last_info_update).seconds > self.update_rate: width = self.display.width height = self.display.height self.gps_info._unload_opengl() self.gps_info = pi3d.String(font=self.arial_font, string=self.string, x=-width / 2, y=height / 2, z=3, is_3d=False, camera=self.camera, justify='L', size=0.15) bounds = self.gps_info.get_bounds() size = bounds[4] - bounds[1] self.gps_info.position(-width / 2, height / 2 - size / 2, 3) self.gps_info.set_shader(self.shader) self.last_info_update = datetime.now() self.gps_info.draw()
def url_success(req, results): self.txt = pi3d.String(camera=self.CAMERA2D, font=self.font, string=results, is_3d=False, y=self.DISPLAY.height / 2.0 + 30.0) self.txt.set_shader(self.flatsh) self.monument.rotateIncY(4) # rotate by some random amount
def recreate(self): self.c_lookup = [] #mapping between clicked char and char in string for i, l in enumerate(self.txt): if l != '\n': self.c_lookup.append(i) textbox = pi3d.String(font=self.gui.font, string=self.txt, is_3d=False, camera=self.gui.camera, justify='L', z=1.0) textbox.set_shader(self.gui.shader) super(TextBox, self).__init__(self.gui, [textbox], self.x, self.y, callback=self.callback, label=self.label, label_pos=self.label_pos, shortcut=self.shortcut)
def showMessage(text, rot=0): message = pi3d.String(font=arialFont, string=text, x=endpos[0], y=endpos[1] + (avhgt / 4), z=endpos[2], sx=0.05, sy=0.05, ry=-rot) message.set_shader(flatsh) message.draw()
def __init__(self, shinesh, flatsh, reflimg, font, x, y, z, free_version): self.free_version = free_version self.m_list = [] for i in range(0, 7): self.m_list.append(Medal(shinesh, flatsh, reflimg, 0.35, font, M_TEXT[i], x, y, z, i * 45)) ry = 7 * 45 s = sin(radians(ry)) c = cos(radians(ry)) self.summary = pi3d.String(font=font, string=M_TEXT[7], size=200.0, x=x + R*0.5*s, y=y, z=z + R*0.5*c, ry=ry) self.summary.set_shader(flatsh)
def show_message(text, rot=0): ''' Display message on screen ''' message = pi3d.String(font=arial_font, string=text, x=endpos[0], y=endpos[1] + (avhgt / 4), z=endpos[2], sx=0.05, sy=0.05, ry=-rot) message.set_shader(flatsh) message.draw()
def high_score_text(self): text = '\n'.join(['{:,}'.format(i) for i in self.scores]) pi3d_string = pi3d.String(camera=self.CAMERA2D, font=self.font, string=text, justify='c', is_3d=False, y=50.0, x=100.0, size=0.3) pi3d_string.set_shader(self.flatsh) return pi3d_string
def __init__(self): super(OpeningScreen, self).__init__(BITMAP_DIR + "opening.png") # Create a text string self.text = pi3d.String(font=FONT_COMPUTER, string="Press the START Button to Begin"[::-1], x=0, y=.5, z=3.9, sx=0.005, sy=0.005) self.text.set_shader(shader_uv_flat) self.text_ts_delta = 0.1 self.text_ts = 0
def __init__(self, shinesh, flatsh, reflimg, alpha, font, text, x, y, z, ry): self.achieved = False s = sin(radians(ry)) c = cos(radians(ry)) self.coin = pi3d.Model(file_string="models/coin.obj", x=x + R*s, y=y, z=z + R*c, sx=0.2, sy=0.2, sz=0.2, ry=ry) self.coin.set_draw_details(shinesh, [self.coin.buf[0].textures[0], reflimg], 1.0, 0.7) self.coin.set_alpha(alpha) self.coin.set_material((0.5, 0.4, 0.0)) self.string = pi3d.String(font=font, string=text, size=200.0, x=x + R*0.5*s, y=y, z=z + R*0.5*c, ry=ry) self.string.set_shader(flatsh)
def __init__(self, gui, shapes, x, y, callback=None, label=None, label_pos='left', shortcut=None): """contains functionality of buttons and is inherited by other gui components. Arguments: *gui* Gui object parent to this widget *shapes* drawable object such as Sprite or String, or list of two to toggle *x,y* location of top left corner of this widget *label* string to use as label *label_pos* position of label 'left', 'right', 'above', 'below' *shortcut* shortcut key to have same effect as clicking wit mouse??? """ if not (type(shapes) is list or type(shapes) is tuple): self.shapes = [shapes] else: self.shapes = shapes self.toggle = len(self.shapes) > 1 #this widget can toggle between two self.clicked = False self.callback = callback self.shortcut = shortcut self.label_pos = label_pos if label is not None: self.labelobj = pi3d.String(font=gui.font, string=label, is_3d=False, camera=gui.camera, justify='L', size=gui.fontscale) self.labelobj.set_shader(gui.shader) else: self.labelobj = None self.relocate(x, y) if not (self in gui.widgets): #because TextBox re-runs Widget.__init__ gui.widgets.append(self) self.visible = True
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) """
def __init__(self, gui, text, callback=None, shortcut=None): """These are the clickable Widgets of the menu system. Instead of a list of Shapes they have a string argument, there is no label or label_pos and the x and y values are obtained from the position and orientation of the parent Menu. *text* string used to construct a pi3d.String """ menu_text = pi3d.String(font=gui.font, string=text, is_3d=False, camera=gui.camera, justify='L') menu_text.set_shader(gui.shader) super(MenuItem, self).__init__(gui, [menu_text], 0, 0, callback=callback, shortcut=shortcut) self.child_menu = None self.own_menu = None
def __init__(self, display, camera): self.display = display self.camera = camera self.shader = pi3d.Shader("uv_flat") self.arial_font = pi3d.Font("fonts/FreeMonoBoldOblique.ttf", (180, 0, 140, 255), background_color=(255, 255, 255, 180)) self.arial_font.blend = True self.arial_font.mipmap = True self.string = "string not set!" self.gps_info = pi3d.String( font=self.arial_font, string="Now the Raspberry Pi really does rock") self.gps_info.set_shader(self.shader) self.last_info_update = datetime.now() self.update_rate = 3
def score_mod(self, amount): ''' utility function to change score and flash up score and delta ''' w, h = self.DISPLAY.width, self.DISPLAY.height if amount < 0: # this is a reduction in health font = self.font # red self.health += amount amount = -100 * amount if self.health < 0.0: self.endgame() self.health_meter.change_reading(self.health) prefix = '%' else: self.score += amount font = self.font2 # green prefix = '+' self.s_text = pi3d.String(camera=self.CAMERA2D, font=font, string='{}{:,}'.format(prefix, amount), is_3d=False, y=-h / 2.0 + 50.0, size=0.6) self.s_text.set_shader(self.flatsh) self.flash_count = 0
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) myhemisphere.draw(shader, [coffimg]) myhemisphere.rotateIncY(.5)
#avatar camera avhgt = 2.0 xm = 0.0 zm = 0.0 ym = 0.0 lastX0 = 0.0 lastZ0 = 0.0 camera.position((xm, 2 + ym, -maphalf - 2.5)) #scores arialFont = pi3d.Font("fonts/FreeMonoBoldOblique.ttf", (221, 0, 170, 255)) arialFont.blend = True score = [0, 0] score0 = pi3d.String(font=arialFont, string=str(score[0]), y=12, sx=0.05, sy=0.05) score0.set_shader(flatsh) score1 = pi3d.String(font=arialFont, string=str(score[1]), y=12, sx=0.05, sy=0.05) score1.set_shader(flatsh) #sphere loc and speed sx, sy, sz = 0, 5, 0 dsx, dsy, dsz = 0.2, 0.0, -0.1 gravity = 0.02 #monster loc and speed
max_obj = 5 max_fps = 35 DISPLAY = pi3d.Display.create(preview_mid_X, preview_mid_Y, w=preview_W, h=preview_H, layer=1, frames_per_second=25) DISPLAY.set_background(0.0, 0.0, 0.0, 0.0) # transparent txtshader = pi3d.Shader("uv_flat") linshader = pi3d.Shader('mat_flat') # Fetch key presses keybd = pi3d.Keyboard() CAMERA = pi3d.Camera(is_3d=False) font = pi3d.Font("fonts/FreeMono.ttf", font_size=30, color=(0, 255, 0, 255)) # blue green 1.0 alpha elapsed_ms = 1000 ms = str(elapsed_ms) ms_txt = pi3d.String(camera=CAMERA, is_3d=False, font=font, string=ms, x=0, y=preview_H/2 - 30, z=1.0) ms_txt.set_shader(txtshader) fps = "00.0 fps" N = 10 fps_txt = pi3d.String(camera=CAMERA, is_3d=False, font=font, string=fps, x=0, y=preview_H/2 - 10, z=1.0) fps_txt.set_shader(txtshader) i = 0 last_tm = time.time() X_OFF = np.array([0, 0, -1, -1, 0, 0, 1, 1]) Y_OFF = np.array([-1, -1, 0, 0, 1, 1, 0, 0]) X_IX = np.array([0, 1, 1, 1, 1, 0, 0, 0]) Y_IX = np.array([0, 0, 0, 1, 1, 1, 1, 0]) verts = [[0.0, 0.0, 1.0] for i in range(8 * max_obj)] # need a vertex for each end of each side bbox = pi3d.Lines(vertices=verts, material=(1.0,0.8,0.05), closed=False, strip=False, line_width=4) bbox.set_shader(linshader)
def show(self): # camera = pi3d.Camera(is_3d=False) last_slide_time_slot = self.now_time_slot() #################### # Prepare time text CAMERA2D = pi3d.Camera(is_3d=False) myfont = pi3d.Font('fonts/ERASDEMI.TTF', codepoints='0123456789 :', color=(200, 200, 200, 255), background_color=(0, 0, 0, 10), shadow=(0, 0, 0, 255), shadow_radius=5) myfont.blend = True last_text_frame = 0 time_string = pi3d.String(camera=CAMERA2D, font=myfont, is_3d=False, string='88:88') time_string.set_shader( pi3d.Shader("uv_flat")) # TODO: Consider different shader (lt, bm, ft, rt, tp, bk) = time_string.get_bounds() xpos = (self.display.width - rt + lt) / 2.0 ypos = -(self.display.height - tp + bm) / 2.0 time_string.position(xpos, ypos, 1.0) time_string.positionZ(0.0) time_string.draw( ) # NB has to be drawn before quick_change() is called as buffer needs to exist #################### while self.display.loop_running(): if self.alpha < 1.0: # increase fade self.alpha += 1.0 / FADE_DURATION / FPS else: # fade finished - close old slide if self.slide1 and self.slide2: self.slide1 = self.slide2 self.slide1.positionZ(2.0) self.slide1.set_alpha(1.0) self.slide2 = None if self.slide2: self.slide2.set_alpha(self.alpha) if self.slide1: self.slide1.draw() if self.slide2: self.slide2.draw() # Things to check every second last_text_frame += 1 if last_text_frame >= FPS: last_text_frame = 0 # update time text now = datetime.datetime.utcnow() utc_now = pytz.utc.localize(now) pst_now = utc_now.astimezone(pytz.timezone("Israel")) time_string.quick_change( ('{d.hour:>2}:{d.minute:02}'.format(d=pst_now))) # check if the slideshow file has changed status = self.file_watcher.get_status() if status in [FileWatch.State.ADDED, FileWatch.State.MODIFIED]: logging.info('Playlist changed - load new image') self.read_playlist_file() self.display_new_image() # check if it's time to show a new image slide_time_slot = self.now_time_slot() if last_slide_time_slot != slide_time_slot: logging.info('Time interval passed - load new image') last_slide_time_slot = slide_time_slot self.display_new_image() time_string.draw()
DISPLAY.set_background(0, 0, 0, 1) # black! CAM = pi3d.Camera() CAM2D = pi3d.Camera(is_3d=False) flatsh = pi3d.Shader("uv_flat") matsh = pi3d.Shader("mat_flat") target = pi3d.Sprite(camera=CAM2D, z=5.0, w=50, h=50) target.set_draw_details(flatsh, [pi3d.Texture("textures/target.png")]) import stars # tucked away in another file for tidyness! s = stars.Stars() font = pi3d.Font('fonts/NotoSans-Regular.ttf') name_loc = s.v[list( s.names)] # this will be a view of the full array, only for named stars label = pi3d.String(font=font, string='Sol', y=-250, is_3d=False, camera=CAM2D) label.set_shader(flatsh) t = threading.Thread(target=s.select_visible) # run in infinite loop t.daemon = True t.start() while not s.ready: # to ensure stars set up first time in select_visible time.sleep(0.1) ''' constelation lines ''' orion = [ 231, 44288, 52501, 100413, 52501, 42572, 62904, 55898, 71408, 59549, 17025, 5088, 42572, 5088, 17025, 81378, 14265, 14597, 14265, 81378, 51101, 76177 ] orion_line = pi3d.Lines(vertices=s.v[orion, :3]) orion_line.set_shader(matsh)
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) mywater = pi3d.LodSprite(w=250.0, h=250.0, n=6) mywater.set_draw_details(matsh, [waterbump[0], shapeshine], 14.0, 0.6) mywater.set_material((0.1, 0.25, 0.3)) mywater.set_fog((0.4, 0.6, 0.8, 0.0), 100) mywater.rotateToX(85.0) mywater.position(10.0, -2.0, 0.0) font = pi3d.Pngfont("fonts/GillSansMT.png", (221, 0, 170, 255)) mystring = pi3d.String(font=font, string="Now the Raspberry Pi really does rock") mystring.translate(0.0, 0.0, 1) mystring.set_shader(flatsh) tick = 0 av_fps = 0 i_n = 0 spf = 0.1 # seconds per frame, i.e. water image change next_time = time.time() + spf dx = 0.02 offset = 0.0 # uv offset do = -0.001 # uv increment # Fetch key presses. mykeys = pi3d.Keyboard() fr = 0
mymouse.start() omx, omy = mymouse.position() CAMERA = pi3d.Camera.instance() #################### #this block added for fast text changing import time CAMERA2D = pi3d.Camera(is_3d=False) myfont = pi3d.Font('fonts/FreeMonoBoldOblique.ttf', codepoints='0123456789. FPStm:') myfont.blend = True tstring = "{:.0f}FPS tm:{:.1f} ".format(60,time.time()) lasttm = time.time() tdel = 0.23 fcount = 0 mystring = pi3d.String(camera=CAMERA2D, font=myfont, is_3d=False, string=tstring) mystring.set_shader(flatsh) (lt, bm, ft, rt, tp, bk) = mystring.get_bounds() xpos = (-DISPLAY.width + rt - lt) / 2.0 ypos = (-DISPLAY.height + tp - bm) / 2.0 mystring.position(xpos, ypos, 1.0) #################### # Display scene and move camera while DISPLAY.loop_running(): #################### #this block added for fast text changing tm = time.time() fcount += 1 if tm > (lasttm + tdel): newtstring = "{:.0f}FPS tm:{:.1f}".format(fcount / (tm - lasttm), tm)
myshape.set_draw_details(shader, [shapeimg, shapebump, shapeshine], 8.0, 0.1) mysprite = pi3d.Sprite(w=10.0, h=10.0, camera=persp_cam) mysprite.position(0.0, 0.0, 15.0) mysprite.set_draw_details(flatsh, [shapebump]) tick = 0 next_time = time.time() + 2.0 #load ttf font and set the font colour to 'raspberry' arialFont = pi3d.Font("fonts/NotoSerif-Regular.ttf", (221, 0, 170, 255), add_codepoints=[256]) arialFont.blend = True #much better anitaliased look but must String.draw() after everything else mystring = pi3d.String(font=arialFont, string=MESSAGE, camera=ortho_cam, z=1.0, is_3d=False, justify="r") # orthographic view mystring.set_shader(flatsh) # Fetch key presses. mykeys = pi3d.Keyboard() # Display scene and rotate shape while DISPLAY.loop_running(): defocus.start_blur() # 1. drawing objects now renders to an offscreen texture #################### mysprite.draw() myshape.draw() defocus.end_blur()
n_filter = len(filter_list) i_filter = -1 # as incremented prior to loading cx, cz = 70.0, 190.0 c_rad = 80.0 frame = 0 st_time = time.time() while DISPLAY.loop_running(): if rot % 360.0 == 0.0: #NB this has to happen first loop! LOGGER.info("{} FPS was {:.5}".format(filter_list[i_filter % n_filter][0], 360.0 / (time.time() - st_time))) i_filter = (i_filter + 1) % n_filter texetc = [reflimg] if (i_filter < 3) else None post = pi3d.PostProcess(filter_list[i_filter][0], add_tex=texetc, scale=0.5) post.sprite.set_custom_data(48, filter_list[i_filter][1]) string = pi3d.String(font=font, string=filter_list[i_filter][0], camera=CAM2D, is_3d=False, x=0, y=-220, z=0.5) string.set_shader(flatsh) st_time = time.time() if len(filter_list[i_filter]) > 2: for i, delta in enumerate(filter_list[i_filter][2]): post.sprite.set_custom_data(48 + i, [filter_list[i_filter][1][i] + rot * delta]) xm = cx + math.sin(math.radians(rot)) * c_rad zm = cz - math.cos(math.radians(rot)) * c_rad ym = mymap.calcHeight(xm, zm) + avhgt rot += 1.0 CAMERA.reset() CAMERA.rotate(tilt, rot + 15.0, 0) CAMERA.position((xm, ym, zm)) post.start_capture()##<<<<<<<<<<<<<< monument.draw()
def __init__(self, shader, **kwargs): self.s = pi3d.String(**kwargs) self.s.set_shader(shader) self.newtext = None self.first = True super().__init__(self.s)
grey_tex = pi3d.Texture(grey, mipmap=False) sobel_tex = pi3d.Texture(sobel, mipmap=False) hog_tex = pi3d.Texture(hog, mipmap=False) hidden_tex = pi3d.Texture(hidden, mipmap=True) grey_sprite = pi3d.ImageSprite(grey_tex, shader, w=2.5, h=2.5, x=-1.2, y=1.0, z=10.0) sobel_sprite = pi3d.ImageSprite(sobel_tex, shader, w=2.5, h=2.5, x=-0.0, y=0.5, z=8.0) hog_sprite = pi3d.ImageSprite(hog_tex, shader, w=2.5, h=2.5, x=1.0, y=0.0, z=6.0) hidden_sprite = pi3d.ImageSprite(hidden_tex, shader, w=2.0, h=2.0, x=1.4, y=-0.5, z=4.0) sobel_sprite.set_alpha(0.85) hog_sprite.set_alpha(0.85) hidden_sprite.set_alpha(0.85) font = pi3d.Font('fonts/FreeSans.ttf', (150, 150, 150, 255)) str_list = [pi3d.String(font=font, string='1.Border Terrier', x=-1.0, y=1.0, z=3.0), pi3d.String(font=font, string='2.Flat Cap', x=-1.0, y=0.5, z=3.0), pi3d.String(font=font, string='3.Labrador', x=-1.0, y=0.0, z=3.0), pi3d.String(font=font, string='4.Top Hat', x=-1.0, y=-0.5, z=3.0), pi3d.String(font=font, string='5.Whippet', x=-1.0, y=-1.0, z=3.0)] for st in str_list: st.set_shader(shader) arrow_new = arrow_y = -2.0 arrow = pi3d.Cone(radius=0.05, height=0.3, x=0.0, y=arrow_y, z=3.0, rz=90.0) arrow.set_shader(lgtshd) arrow.set_material((1.0, 0.9, 0.4)) mykeys = pi3d.Keyboard() mouse = pi3d.Mouse(restrict=False) mouse.start()
tex = pi3d.Texture(npa) sprite_display = pi3d.Sprite(w=tex.ix, h=tex.iy, z=2.0) sprite_display.set_draw_details(txtshader, [tex]) font = pi3d.Font("fonts/FreeMono.ttf", font_size=18, color=(255, 255, 255, 255)) # blue green 1.0 alpha elapsed_ms = 0 N = 100 ms_total = 0 ms_avg = int(ms_total / (N + 1)) ms_str = "Detection " + "000" + " ms" ms_txt = pi3d.String(camera=CAMERA, is_3d=False, font=font, string=ms_str, x=0, y=preview_H / 2 - 30, z=1.0) ms_txt.set_shader(txtshader) i = 0 tm = time.time() last_tm = time.time() fps = "{:5.1f} fps".format(i / (tm - last_tm)) frame_rate_set = True fps_txt = pi3d.String(camera=CAMERA, is_3d=False, font=font, string=fps, x=0,
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) # Use three ttfs fonts one with the colour 'raspberry', one with background # colour and one using a contrasting shadow txt = "Now the Raspberry Pi really does rock" strings = [ pi3d.String(font=pi3d.Font("fonts/NotoSerif-Regular.ttf", (221, 0, 170, 255)), string=txt, z=4), pi3d.String(font=pi3d.Font("fonts/NotoSerif-Regular.ttf", (0, 0, 26, 255)), string=txt, z=4), pi3d.String(font=pi3d.Font("fonts/NotoSerif-Regular.ttf", (0, 0, 26, 255), background_color=(128, 128, 128, 0)), string=txt, z=4), pi3d.String(font=pi3d.Font("fonts/NotoSerif-Regular.ttf", (0, 0, 26, 255), shadow=(200, 255, 0, 255), shadow_radius=1), string=txt, z=4) ]
def get_curr_conds(): # Optional Current Weather Conditions Display global weather_start_time global weather_check_time global api_key global lat global lng global conds global temp_f global temp_c global shader global time24 if time.time( ) - weather_start_time > weather_check_time: # check the number of seconds in weather_check_time has passed weather_start_time = time.time() forecast = forecastio.load_forecast(api_key, lat, lng) current = forecast.currently() conds = current.summary temp_f = round(current.temperature) else: pass cond_face = { "Light Dizzle": "rain", "Heavy Drizzle": "rain", "Drizzle": "rain", "Light Rain": "rain", "Heavy Rain": "rain", "Rain": "rain", "Clear": "sunny", "Light Snow": "snow", "Heavy Snow": "snow", "Snow": "snow", "Light Fog": "fog", "Heavy Fog": "fog", "Fog": "fog", "Light Fog Patches": "fog", "Heavy Fog Patches": "fog", "Fog Patches": "fog", "Light Smoke": "smoke", "Heavy Smoke": "smoke", "Smoke": "smoke", "Light Haze": "haze", "Heavy Haze": "haze", "Haze": "haze", "Light Low Drifting Snow": "snow", "Heavy Low Drifting Snow": "snow", "Low Drifting Snow": "snow", "Light Blowing Snow": "snow", "Heavy Blowing Snow": "snow", "Blowing Snow": "snow", "Light Rain Mist": "rain", "Heavy Rain Mist": "rain", "Rain Mist": "rain", "Light Rain Showers": "rain", "Heavy Rain Showers": "rain", "Rain Showers": "rain", "Light Snow Showers": "snow", "Heavy Snow Showers": "snow", "Snow Showers": "snow", "Light Snow Blowing Snow Mist": "snow", "Heavy Snow Blowing Snow Mist": "snow", "Snow Blowing Snow Mist": "snow", "Light Thunderstorm": "thunder", "Heavy Thunderstorm": "thunder", "Thunderstorm": "thunder", "Light Thunderstorms and Rain": "thunder", "Heavy Thunderstorms and Rain ": "thunder", "Thunderstorms and Rain": "thunder", "Light Thunderstorms and Snow": "thunder", "Heavy Thunderstorms and Snow ": "thunder", "Thunderstorms and Snow": "thunder", "Patches of Fog": "fog", "Shallow Fog": "fog", "Partial Fog": "fog", "Overcast": "clouds", "Partly Cloudy": "partly_cloudy", "Mostly Cloudy": "clouds", "Scattered Clouds": "partly_cloudy" } weather_face = cond_face.get(conds) weather_dial.draw() # draw the background for weather conds if weather_face == "sunny": sunny.draw() elif weather_face == "rain": rain.draw() elif weather_face == "clouds": clouds.draw() elif weather_face == "partly_cloudy": partly_cloudy.draw() elif weather_face == "thunder": thunder.draw() elif weather_face == "snow": snow.draw() elif weather_face == "haze": haze.draw() elif weather_face == "smoke": smoke.draw() elif weather_face == "fog": fog.draw() else: unknown.draw() if time24 is True: myTime = time.strftime("%H:%M") else: myTime = time.strftime("%-I:%M %p") if centigrade: timetempStr = myTime + " " + str(temp_c) + " C" # centigrade = True elif centigrade is False: timetempStr = myTime + " " + str(temp_f) + " F" dispTemp = pi3d.String(camera=CAMERA, is_3d=False, font=myFont, string=timetempStr, x=12, y=-30, z=1.0) dispTemp.set_shader(shader) dispTemp.draw() dispConds = pi3d.String(camera=CAMERA, is_3d=False, font=myFont, string=conds, x=12, y=-60, z=1.0) dispConds.set_shader(shader) dispConds.draw()