self.butP = pi3d.Button(gui, "l.gif", x, y, label=label, shortcut='d', callback=self.rotp) self.butM = pi3d.Button(gui, "r.gif", x + 32, y, shortcut='l', callback=self.rotm) def rotp(self, *args): self.callback(self.delta) def rotm(self, *args): self.callback(-self.delta) DISPLAY = pi3d.Display.create(w=640, h=480, frames_per_second=30) DISPLAY.set_background(0.8,0.8,0.8,1.0) # r,g,b,alpha shader = pi3d.Shader("uv_reflect") font = pi3d.Font("fonts/FreeSans.ttf", color=(0,0,0,255), font_size=20) gui = pi3d.Gui(font) ww, hh = DISPLAY.width / 2.0, DISPLAY.height / 2.0 img = pi3d.Texture("textures/rock1.jpg") model = pi3d.Cuboid(z=5.0) model.set_draw_details(shader, [img]) radio = pi3d.Radio(gui, ww -20, hh - 32, label="unhides menu!", label_pos="left", callback=cbx) xi = -ww yi = hh for b in ['tool_estop.gif', 'tool_power.gif', 'tool_open.gif', 'tool_reload.gif', 'tool_run.gif', 'tool_step.gif', 'tool_pause.gif', 'tool_stop.gif', 'tool_blockdelete.gif', 'tool_optpause.gif', 'tool_zoomin.gif', 'tool_zoomout.gif',
#inserted BME if INTERACTIVE: kbd = pi3d.Keyboard() # images in iFiles list nexttm = 0.0 iFiles, nFi = get_files(date_from, date_to) next_pic_num = 0 sfg = None # slide for background sbg = None # slide for foreground if nFi == 0: print('No files selected!') exit() # PointText and TextBlock font = pi3d.Font(FONT_FILE, codepoints=CODEPOINTS, grid_size=7, shadow_radius=4.0, shadow=(0,0,0,128)) text = pi3d.PointText(font, CAMERA, max_chars=200, point_size=50) textblock = pi3d.TextBlock(x=-DISPLAY.width * 0.5 + 50, y=-DISPLAY.height * 0.4, z=0.1, rot=0.0, char_count=199, text_format="{}".format(tidy_name(iFiles[next_pic_num][0])), size=0.99, spacing="F", space=0.02, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(textblock) num_run_through = 0 while DISPLAY.loop_running(): tm = time.time() if nFi > 0: if tm > nexttm and not paused: # this must run first iteration of loop nexttm = tm + time_delay a = 0.0 # alpha - proportion front image to back sbg = sfg
zm = 0.0 ym = mymap.calcHeight(xm, zm) + avhgt # Fetch key presses mykeys = pi3d.Keyboard() mymouse = pi3d.Mouse(restrict = False) 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/NotoSerif-Regular.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) mystring.draw() # NB has to be drawn before quick_change() is called as buffer needs to exist #################### # Display scene and move camera
slide.unif[54] = config.BLEND_TYPE if config.KEYBOARD: kbd = pi3d.Keyboard() # images in iFiles list nexttm = 0.0 iFiles, nFi = get_files(date_from, date_to) next_pic_num = 0 sfg = None # slide for background sbg = None # slide for foreground # PointText and TextBlock. If SHOW_TEXT_TM <= 0 then this is just used for no images message grid_size = math.ceil(len(config.CODEPOINTS)**0.5) font = pi3d.Font(config.FONT_FILE, codepoints=config.CODEPOINTS, grid_size=grid_size) text = pi3d.PointText(font, CAMERA, max_chars=200, point_size=config.SHOW_TEXT_SZ) textblock = pi3d.TextBlock(x=-DISPLAY.width * 0.5 + 50, y=-DISPLAY.height * 0.4, z=0.1, rot=0.0, char_count=199, text_format="{}".format(" "), size=0.99, spacing="F", space=0.02, colour=(1.0, 1.0, 1.0, 1.0))
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
dz = math.cos(math.radians(rot)) ym = 200.0 coin_dist = COIN_TARGET coin_count = 0 score = 0 fmap = None cmap = None # Fetch key presses mykeys = pi3d.Keyboard() CAMERA = pi3d.Camera(lens=(1.0, 10000.0, 55.0, 1.6)) #################### #this block added for fast text changing CAMERA2D = pi3d.Camera(is_3d=False) myfont = pi3d.Font('fonts/NotoSerif-Regular.ttf', color = (255, 230, 128, 255), codepoints='0123456789. -goldoz:mskph') myfont.blend = True tstring = "gold {:05d}oz {:02d}m{:02d}s -{:4.1f}km {:3.1f}kph ".format(score, 0, 0, 0.0, 0.0) lasttm = 0.0 tdel = 0.23 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) mystring.draw() #################### # Display scene and move camera while DISPLAY.loop_running():
def __init__(self, angle_fr=-135, angle_to=135, step=5, outer=240, inner=200, min_t=15, max_t=35, shader=None, camera=None): self.angle_fr = angle_fr self.angle_to = angle_to self.step = step self.outer = outer self.inner = inner self.mid = (outer + inner) / 2 self.min_t = min_t self.max_t = max_t gpio.setmode(gpio.BCM) gpio.setwarnings(False) gpio.setup(26, gpio.IN, pull_up_down=gpio.PUD_DOWN) self.bus = i2c.I2C(2) try: self.bus.read(1, 0x5c) self.bus.write([0x6e, 0b00001110], 0x5c) self.bus.write([0x70, 0b00000000], 0x5c) except: print('Error: no touchscreen found') tick_verts = [] dial_verts = [] # first make tick vertices for x in range(self.angle_fr, self.angle_to, self.step): (s, c) = (sin(radians(x)), cos(radians(x)) ) # re-use for brevity below tick_verts.extend([(self.inner * s, self.inner * c, 0.1), (self.outer * s, self.outer * c, 0.1)]) dial_verts.append((self.mid * s, self.mid * c, 2.0)) if shader is None: shader = pi3d.Shader('mat_flat') if camera is None: camera = pi3d.Camera(is_3d=False) uv_shader = pi3d.Shader('uv_flat') tex = pi3d.Texture('color_gradient.jpg') self.ticks = pi3d.PolygonLines(camera=camera, vertices=tick_verts, strip=False, line_width=5) self.ticks.set_shader(shader) self.ticks.set_alpha(0.8) self.sensorticks = pi3d.PolygonLines(camera=camera, vertices=tick_verts, line_width=5, strip=False) self.sensorticks.set_shader(shader) self.bline = pi3d.PolygonLines(camera=camera, vertices=dial_verts, line_width=40) self.bline.set_textures([tex]) self.bline.set_alpha(0.8) self.bline.set_shader(uv_shader) self.bline.set_material((0.5, 0.5, 0.5)) self.dial = pi3d.PolygonLines(camera=camera, vertices=dial_verts, line_width=8) self.dial.set_alpha(0.2) self.dial.set_shader(shader) font = pi3d.Font('opensans.ttf', codepoints='0123456789.-°', grid_size=5) self.actval = pi3d.PointText(font, camera, max_chars=10, point_size=100) self.temp_block = pi3d.TextBlock(0, 0, 0.1, 0.0, 6, justify=0.5, text_format="0°", size=0.79, spacing="F", space=0.02, colour=(1.0, 1.0, 1.0, 1.0)) self.actval.add_text_block(self.temp_block) self.dot2 = pi3d.Disk(radius=20, sides=20, z=0.1, rx=90, camera=camera) self.dot2.set_shader(shader) self.dot2.set_material((1, 1, 1)) self.dot2_alpha = 1.0 self.value = 25.0 self.sensorvalue = 18.0 degree = (self.angle_fr + (self.angle_to - self.angle_fr) * (self.value - self.min_t) / (self.max_t - self.min_t)) self.x1 = self.mid * sin(radians(degree)) self.y1 = self.mid * cos(radians(degree))
#Create shape myshape = pi3d.MergeShape(camera=persp_cam) #specify perspective view asphere = pi3d.Sphere(sides=16, slices=16) myshape.radialCopy(asphere, step=72) myshape.position(0.0, 0.0, 5.0) 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/FreeMonoBoldOblique.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():
button4_pressed = False explosion = False # Has the explosion occured? overloading = 0 # We're in overload mode # Set up the environment DISPLAY = pi3d.Display.create() #DISPLAY = pi3d.Display.create(w=800, h=600) # For debugging DISPLAY.set_background(0.0, 0.0, 0.0, 1) # Black CAM = pi3d.Camera(eye=(0.0, 0.0, -7.0)) CAM2D = pi3d.Camera(is_3d=False) lights = pi3d.Light(lightamb=(0.8, 0.8, 0.9)) shader = pi3d.Shader('uv_light') flatshader = pi3d.Shader("uv_flat") fontfile = '/home/pi/pi3d_demos-master/fonts/NotoSans-Regular.ttf' font = pi3d.Font(fontfile, font_size=32, color=(255, 255, 255, 255)) font.blend = True xmargin = DISPLAY.width * 0.05 ymargin = DISPLAY.height * 0.05 topleftx = DISPLAY.width / -2 + xmargin # Top left corner starting X coordinate for stuff toplefty = DISPLAY.height / 2 - ymargin # Top left corner starting Y coordinate for stuff backplaneZ = 0 # Mining "Stats" num_stations = 120 num_online_stations = num_stations num_stopping_stations = 0 num_offline_stations = 0 collection_rate = 100
def main( startdir, # Root folder for images, with recursive search config_file, # File with list of file names (for fast restart) interval, # Seconds between images shuffle, # True or False geonamesuser, # User name for GeoNames server www.geonames.org check_dirs # Interval between checking folders in seconds ) : global backup_dir,paused,geoloc,last_file_change,kb_up,FIT,BLUR_EDGES # backup_dir = os.path.abspath(os.path.join(startdir,config.BKUP_DIR)) backup_dir = config.BKUP_DIR print(startdir) #print(config.BKUP_DIR) #print(backup_dir) if config.BUTTONS: pause_button = Button(8, hold_time=5) back_button = Button(9, hold_time=5) forward_button = Button(4,hold_time=5) pause_button.when_pressed = handle_press back_button.when_pressed = handle_press pause_button.when_held=handle_hold back_button.when_held=handle_hold forward_button.when_pressed=handle_press forward_button.when_held=handle_hold rotate_button = Button(5, hold_time=5) rotate_button.when_pressed= handle_press rotate_button.when_held=handle_hold paused=False next_check_tm=time.time()+check_dirs time_dot=True ############################################## # Create GeoNames locator object www.geonames.org geoloc=None try: geoloc=GeoNames(username=geonamesuser) except: print("Geographic information server not available") print("Setting up display") DISPLAY = pi3d.Display.create(x=0, y=0, frames_per_second=FPS,display_config=pi3d.DISPLAY_CONFIG_HIDE_CURSOR, background=BACKGROUND) CAMERA = pi3d.Camera(is_3d=False) print(DISPLAY.opengl.gl_id) shader = pi3d.Shader(config.PI3DDEMO + "/shaders/blend_new") #shader = pi3d.Shader("/home/patrick/python/pi3d_demos/shaders/blend_new") slide = pi3d.Sprite(camera=CAMERA, w=DISPLAY.width, h=DISPLAY.height, z=5.0) slide.set_shader(shader) slide.unif[47] = config.EDGE_ALPHA if KEYBOARD: kbd = pi3d.Keyboard() # images in iFiles list nexttm = 0.0 iFiles, nFi = get_files(startdir,config_file,shuffle) next_pic_num = 0 sfg = None # slide for foreground sbg = None # slide for background if nFi == 0: print('No files selected!') exit() # PointText and TextBlock. #font = pi3d.Font(FONT_FILE, codepoints=CODEPOINTS, grid_size=7, shadow_radius=4.0,shadow=(128,128,128,12)) grid_size = math.ceil(len(config.CODEPOINTS) ** 0.5) font = pi3d.Font(config.FONT_FILE, codepoints=config.CODEPOINTS, grid_size=grid_size, shadow_radius=4.0,shadow=(0,0,0,128)) text = pi3d.PointText(font, CAMERA, max_chars=200, point_size=50) text2 = pi3d.PointText(font, CAMERA, max_chars=8, point_size=50) #text = pi3d.PointText(font, CAMERA, max_chars=200, point_size=50) textblock = pi3d.TextBlock(x=-DISPLAY.width * 0.5 + 20, y=-DISPLAY.height * 0.4, z=0.1, rot=0.0, char_count=199, text_format="{}".format(" "), size=0.65, spacing="F", space=0.02, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(textblock) timeblock = pi3d.TextBlock(x=DISPLAY.width*0.5 - 150, y=DISPLAY.height * 0.5 - 50, z=0.1, rot=0.0, char_count=6, text_format="{}".format(" "), size=0.65, spacing="F", space=0.02, colour=(1.0, 1.0, 1.0, 1.0)) text2.add_text_block(timeblock) #Retrieve last image number to restart the slideshow from config.num file #Retrieve next directory check time cacheddata=(0,0,last_file_change,next_check_tm) try: with open(config_file+".num",'r') as f: cacheddata=json.load(f) num_run_through=cacheddata[0] next_pic_num=cacheddata[1] last_file_change=cacheddata[2] next_check_tm=cacheddata[3] except: num_run_through=0 next_pic_num=0 if (next_check_tm < time.time()) : #if stored check time is in the past, make it "now" next_check_tm = time.time() print("Start time ",time.strftime(config.TIME_FORMAT,time.localtime())) print("Next Check time ",time.strftime(config.TIME_FORMAT,time.localtime(next_check_tm))) print("Starting with round number ",num_run_through) print("Starting with picture number ",next_pic_num) tm=time.time() pic_num=next_pic_num # Main loop while DISPLAY.loop_running(): previous = tm # record previous time value, used to make cursor blink tm = time.time() if (time.localtime(previous).tm_sec < time.localtime(tm).tm_sec) : #blink dot time_dot = not(time_dot) #check if there are file to display if nFi > 0: # If needed, display new photo if (tm > nexttm and not paused) or (tm - nexttm) >= 86400.0: # this must run first iteration of loop print("tm es ",tm," nexttm es ", nexttm, " la resta ", tm-nexttm) nexttm = tm + interval a = 0.0 # alpha - proportion front image to back sbg = sfg sfg = None while sfg is None: # keep going through until a usable picture is found TODO break out how? # Calculate next picture index to be shown pic_num = next_pic_num next_pic_num += 1 if next_pic_num >= nFi: num_run_through += 1 next_pic_num = 0 #update persistent cached data for restart cacheddata=(num_run_through,pic_num,last_file_change,next_check_tm) with open(config_file+".num","w") as f: json.dump(cacheddata,f,separators=(',',':')) # File Open and texture build try: temp=time.time() im = Image.open(iFiles[pic_num]) print("foto numero ",pic_num," time ",time.time()) except: print("Error Opening File",iFiles[pic_num]) continue # EXIF data and geolocation analysis # define some default values orientation = 1 # unrotated dt=None # will hold date from EXIF datestruct=None # will hold formatted date # Format metadata try: exif_data = im._getexif() except: exif_data=None try: orientation = int(exif_data[config.EXIF_ORIENTATION]) except: orientation = 1 try: dt = time.mktime(time.strptime(exif_data[config.EXIF_DATID], '%Y:%m:%d %H:%M:%S')) datestruct=time.localtime(dt) except: datestruct=None try: location = get_geo_name(exif_data) except Exception as e: # NB should really check error print('Error preparing geoname: ', e) location = None # Load and format image try: sfg = tex_load(im, orientation, (DISPLAY.width, DISPLAY.height)) except: next_pic_num += 1 # skip to next photo continue nexttm = tm+interval #Time points to next interval # Image Rendering if sbg is None: # first time through sbg = sfg slide.set_textures([sfg, sbg]) slide.unif[45:47] = slide.unif[42:44] # transfer front width and height factors to back slide.unif[51:53] = slide.unif[48:50] # transfer front width and height offsets wh_rat = (DISPLAY.width * sfg.iy) / (DISPLAY.height * sfg.ix) if (wh_rat > 1.0 and FIT) or (wh_rat <= 1.0 and not FIT): sz1, sz2, os1, os2 = 42, 43, 48, 49 else: sz1, sz2, os1, os2 = 43, 42, 49, 48 wh_rat = 1.0 / wh_rat slide.unif[sz1] = wh_rat slide.unif[sz2] = 1.0 slide.unif[os1] = (wh_rat - 1.0) * 0.5 slide.unif[os2] = 0.0 #transition if KENBURNS: xstep, ystep = (slide.unif[i] * 2.0 / interval for i in (48, 49)) slide.unif[48] = 0.0 slide.unif[49] = 0.0 kb_up = not kb_up # Prepare the different texts to be shown overlay_text= "" #this will host the text on screen if SHOW_LOCATION: #(and/or month-year) if location is not None: overlay_text += tidy_name(str(location)) #print(overlay_text) if datestruct is not None : overlay_text += " " + tidy_name(config.MES[datestruct.tm_mon - 1]) + "-" + str(datestruct.tm_year) #print(overlay_text) try: textblock.set_text(text_format="{}".format(overlay_text)) text.regen() except : #print("Wrong Overlay_text Format") textblock.set_text(" ") # print time on screen, blink separator every second if not paused : timetext=timetostring(time_dot,tm) else : timetext="PAUSA" timeblock.set_text(text_format="{}".format(timetext)) # manages transition if KENBURNS: t_factor = nexttm - tm if kb_up: t_factor = interval - t_factor slide.unif[48] = xstep * t_factor slide.unif[49] = ystep * t_factor if a <= 1.0: # transition is happening a += delta_alpha slide.unif[44] = a else: # Check if image files list has to be rebuilt (no transition on going, so no harm to image slide.set_textures([sfg, sfg]) if (num_run_through > config.NUMBEROFROUNDS) or (time.time() > next_check_tm) : #re-load images after running through them or exceeded time print("Refreshing Files list") next_check_tm = time.time() + check_dirs # Set up the next interval try: if check_changes(startdir): #rebuild files list if changes happened print("Re-Fetching images files, erase config file") with open(config_file,'w') as f : json.dump('',f) # creates an empty config file, forces directory reload iFiles, nFi = get_files(startdir,config_file,shuffle) next_pic_num = 0 else : print("No directory changes: do nothing") except: print("Error refreshing file list, keep old one") num_run_through = 0 #render the image slide.draw() #render the text text.draw() text2.draw() else: textblock.set_text("NO IMAGES SELECTED") textblock.colouring.set_colour(alpha=1.0) text.regen() text.draw() # Keyboard and button handling #delta=time.time()-86400.0 delta=0 if KEYBOARD: k = kbd.read() if k != -1: print("Key pressed", tm-nexttm) #nexttm = delta # print(tm - nexttm) if k==27 or quit: #ESC break if k==ord(' '): paused = not paused if k==ord('s'): # go back a picture nexttm = 0 next_pic_num -= 2 if next_pic_num < -1: next_pic_num = -1 nexttm = delta if k==ord('q'): #go forward nexttm = delta if k==ord('r') and paused: # rotate picture (only if paused) nexttm = delta im.close() #close file on disk try: with open(iFiles[pic_num],'rb') as tmp_file: #open file again to be used in exif context tmp_im = exif.Image(tmp_file) tmp_file.close() if (tmp_im.has_exif) : # If it has exif data, rotate it if it does not, do nothing save_file(iFiles[pic_num]) # Copy file to Backup folder tmp_im.orientation = rotate90CW(tmp_im.orientation) # changes EXIF data orientation parameter with open(iFiles[pic_num],'wb') as tmp_file: # Write the file with new exif orientation tmp_file.write(tmp_im.get_file()) next_pic_num -=1 # force reload on screen except: print("Error when rotating photo") # nexttm = delta if config.BUTTONS: #Handling of config.BUTTONS goes here if paused and (rotate_button.estado == 1 or rotate_button.estado == 2): # Need to be on pause rotate_button.estado = 0 nexttm = delta im.close() #close file on disk try: with open(iFiles[pic_num],'rb') as tmp_file: #open file again to be used in exif context tmp_im = exif.Image(tmp_file) tmp_file.close() if (tmp_im.has_exif) : # If it has exif data, rotate it if it does not, do nothing save_file(iFiles[pic_num]) # Copy file to Backup folder tmp_im.orientation = rotate90CW(tmp_im.orientation) # changes EXIF data orientation parameter with open(iFiles[pic_num],'wb') as tmp_file: # Write the file with new exif orientation tmp_file.write(tmp_im.get_file()) next_pic_num -=1 # force reload on screen except: print("Error when rotating photo") if pause_button.estado == 1 or pause_button.estado == 2 : # button was pressed #nexttm = delta paused = not paused pause_button.estado = 0 if back_button.estado == 1 or back_button.estado == 2 : nexttm = delta next_pic_num -= 2 if next_pic_num < -1: next_pic_num = -1 #nexttm = 0 #force reload back_button.estado = 0 if forward_button.estado == 1 or forward_button.estado == 2 : nexttm = delta forward_button.estado = 0 # All config.BUTTONS go to idle after processing them, regardless of state # WHILE LOOP ends here try: DISPLAY.loop_stop() except Exception as e: print("this was going to fail if previous try failed!") if KEYBOARD: kbd.close() DISPLAY.destroy()
clock_min = pi3d.ImageSprite("/home/pi/miniz/textures/clock_minute_hand.png", shader, w=16.0, h=156.0, x=0.0, y=-30.0, z=4.0) global myFont # colors gold = (233, 215, 127) # RGB Values white = (1, 1, 1) black = (0, 0, 0) blue = (0, 0, 255) myFont = pi3d.Font("/home/pi/miniz/fonts/DubbaDubbaNF.ttf", gold, font_size=30) #load ttf font and set the font color to gold # Define GPIO inputs for Tuning/Menu Select TUNE_A = 13 # Pin xx CW / Dial UP TUNE_B = 12 # Pin xx CCW / Dial Down TUNE_BUTTON = 6 # Pin x Switch # Define GPIO inputs for Volume VOLUME_A = 27 VOLUME_B = 23 # VOLUME Button is used on Pimoroni On Off SHIM # Defined here to complete callback; not used in routine VOLUME_BUTTON = 4 degrees = 57 prev_degrees = 0
########################################################################## t = threading.Thread(target=get_pics) # set up and start capture thread t.daemon = True t.start() while not new_pic: # wait for array to be filled first time time.sleep(0.1) ######################################################################## DISPLAY = pi3d.Display.create(x=mdl_dims, y=mdl_dims, frames_per_second=max_fps) DISPLAY.set_background(0.0, 0.0, 0.0, 0.0) txtshader = pi3d.Shader("uv_flat") font = pi3d.Font("fonts/FreeMono.ttf", font_size=30, color=(0, 255, 0, 255)) # blue green 1.0 alpha CAMERA = pi3d.Camera(is_3d=False) tex = pi3d.Texture(npa) sprite = pi3d.Sprite(w=tex.ix, h=tex.iy, z=1.0) sprite.set_draw_details(txtshader, [tex]) mykeys = pi3d.Keyboard() 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)
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 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) mystring.draw(
shinesh = pi3d.Shader("uv_reflect") flatsh = pi3d.Shader("uv_flat") matsh = pi3d.Shader("mat_reflect") ################################# # Textures patimg = pi3d.Texture("textures/PATRN.PNG") shapebump = pi3d.Texture("textures/floor_nm.jpg") shapshine = pi3d.Texture("textures/stars.jpg") light = pi3d.Light(lightpos=(-1.0, 0.0, 10.0), lightcol=(3.0, 3.0, 2.0), lightamb=(0.02, 0.01, 0.03), is_point=True) # Create shape cylinder = pi3d.EnvironmentCube(light=light, size=1, name="Cylinder", x=0, y=0, z=5) cylinder.set_line_width(2) # Text arialFont = pi3d.Font("fonts/FreeMonoBoldOblique.ttf", (221,0,170,255)) delta = 1 # Fetch key presses mykeys = pi3d.Keyboard() scale = 1 lastKeyRead = -1 while DISPLAY.loop_running(): displayString = "Delta: {}, X: {}, Y:{}, Z: {}".format(delta, cylinder.x(), cylinder.y(), cylinder.z()) mystring = pi3d.FixedString("fonts/FreeMonoBoldOblique.ttf", displayString, camera=TEXT_CAMERA, color=(255,255,255,255), font_size=24, margin=0.0, justify='R', background_color=(0,0,0,255), shader=flatsh, f_type='SMOOTH') CAMERA.reset() cylinder.draw(shinesh, [patimg, shapebump, shapshine], 4.0, 0.1) mystring.draw() k = mykeys.read()
#!/usr/bin/python from __future__ import absolute_import, division, print_function, unicode_literals ''' Uses the pi3d.Graph class added to pi3d develop branch on Friday 13th Oct 2017 ''' import pi3d, smbus import numpy as np bus = smbus.SMBus(2) LINES = True # change this to see bar graph display = pi3d.Display.create(w=800, h=480, background=(0, 0, 0, 1), frames_per_second=30) font = pi3d.Font("opensans.ttf") key = pi3d.Keyboard() if LINES: x_vals = np.linspace(0, 500, 500) y_vals = np.zeros((2, 500)) W, H = 800, 480 xpos = (display.width - W) / 2 ypos = (display.height - H) / 2 graph = pi3d.Graph(x_vals, y_vals, W, H, font,
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.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) arialFont = pi3d.Font("fonts/FreeMonoBoldOblique.ttf", (221,0,170,255)) #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 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()
#Create shape myshape = pi3d.MergeShape(camera=persp_cam) #specify perspective view asphere = pi3d.Sphere(sides=16, slices=16) myshape.radialCopy(asphere, step=72) myshape.position(0.0, 0.0, 5.0) 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():
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) # 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) ]