def __draw_clock(self): current_time = datetime.now().strftime(self.__clock_format) # --- Only rebuild the FixedString containing the time valud if the time string has changed. # With the default H:M display, this will only rebuild once each minute. Note however, # time strings containing a "seconds" component will rebuild once per second. if current_time != self.__prev_clock_time: width = self.__display.width - 50 self.__clock_overlay = pi3d.FixedString( self.__font_file, current_time, font_size=self.__clock_text_sz, shader=self.__flat_shader, width=width, shadow_radius=3, color=(255, 255, 255, int(255 * float(self.__clock_opacity)))) x = (width - self.__clock_overlay.sprite.width) // 2 if self.__clock_justify == "L": x *= -1 elif self.__clock_justify == "C": x = 0 y = (self.__display.height - self.__clock_text_sz - 20) // 2 self.__clock_overlay.sprite.position(x, y, 0.1) self.__prev_clock_time = current_time if self.__clock_overlay: self.__clock_overlay.sprite.draw()
def no_highlight(self): self.fixed_string = pi3d.FixedString(font= self.font, string=self.string, camera=self.camera, color=self.font_color, font_size=self.font_size, margin=self.margin, justify=self.justify, background_color=self.background_color, shader=self.shader, f_type=self.f_type) self.fixed_string.sprite.positionX(self.x_posit) self.fixed_string.sprite.positionY(self.y_posit)
def __make_text(self, pic, paused, side=0, pair=False): # if side 0 and pair False then this is a full width text and put into # __textblocks[0] otherwise it is half width and put into __textblocks[position] info_strings = [] if pic is not None and (self.__show_text > 0 or paused): #was SHOW_TEXT_TM > 0.0 if (self.__show_text & 1) == 1 and pic.title is not None: # title info_strings.append(self.__sanitize_string(pic.title)) if (self.__show_text & 2) == 2 and pic.caption is not None: # caption info_strings.append(self.__sanitize_string(pic.caption)) if (self.__show_text & 4) == 4: # name info_strings.append(self.__sanitize_string(pic.fname)) if (self.__show_text & 8) == 8 and pic.exif_datetime > 0: # date fdt = time.strftime(self.__show_text_fm, time.localtime(pic.exif_datetime)) info_strings.append(fdt) if (self.__show_text & 16) == 16 and pic.location is not None: # location info_strings.append( pic.location ) #TODO need to sanitize and check longer than 0 for real if (self.__show_text & 32) == 32: # folder info_strings.append( self.__sanitize_string( os.path.basename(os.path.dirname(pic.fname)))) if paused: info_strings.append("PAUSED") final_string = " • ".join(info_strings) block = None if len(final_string) > 0: if side == 0 and not pair: c_rng = self.__display.width - 100 # range for x loc from L to R justified else: c_rng = self.__display.width * 0.5 - 100 # range for x loc from L to R justified block = pi3d.FixedString(self.__font_file, final_string, font_size=self.__show_text_sz, shader=self.__flat_shader, justify=self.__text_justify, width=c_rng) adj_x = (c_rng - block.sprite.width ) // 2 # half amount of space outside sprite if self.__text_justify == "L": adj_x *= -1 elif self.__text_justify == "C": adj_x = 0 if side == 0 and not pair: # i.e. full width x = adj_x else: x = adj_x + int(self.__display.width * 0.25 * (-1.0 if side == 0 else 1.0)) y = (block.sprite.height - self.__display.height + self.__show_text_sz) // 2 block.sprite.position(x, y, 0.1) block.sprite.set_alpha(0.0) self.__textblocks[side] = block
def inloop(textchange=False, activity=False, x=0, y=0, touch_pressed=False): global wifinetworks, selectednetwork wifinetworkstext.draw() controlx.draw() if wifinetworks is None: # only runs once as this block creates actnetwork = 0 wifinetworks = iwlist.scan() for network in wifinetworks: if network['essid'] == '': network['essid'] = 'hidden' wifinetworks[actnetwork]['string'] = pi3d.FixedString(font_path, 'SSID: {}, Enc:{} Ch:{}'.format( network['essid'], network['enc'], network['ch']), font_size=32, shadow_radius=4, justify='L', background_color=(0,0,0,30), color= (255,255,255,255), camera=graphics.CAMERA, shader=graphics.SHADER, f_type='SMOOTH') wifinetworks[actnetwork]['string'].sprite.position(0, (100 - (actnetwork*80)), 1) actnetwork += 1 else: for network in wifinetworks: network['string'].draw() if peripherals.check_touch_pressed(): activity = True if peripherals.clicked(335, 196): config.subslide = None wifinetworks = None else: selectednetwork = abs(int((peripherals.lasty - 100) / 80)) if -1 < selectednetwork < len(wifinetworks): peripherals.eg_object.usertextshow = 'Please enter WIFI password.' peripherals.eg_object.usertext = '' config.subslide = 'wifikeyboard' return activity
def next_message(self): msg_split = self.messages[self.i_mess].split() self.i_mess -= 1 if self.i_mess < 0: self.i_mess = self.n_mess - 1 message = '' next_line = '' line_feed = '' for word in msg_split: if len(next_line) > 70: message += line_feed + next_line next_line = '' line_feed = '\n' next_line += word + ' ' message += line_feed + next_line msg = pi3d.FixedString('/home/pi/pi3d_pictureframe/FreeSans.ttf', message, font_size=32, camera=CAMERA, shader=flatsh, f_type='EMBOSS') msg.sprite.position(0, (-msg.iy - DISPLAY.height) / 2, 1.0) msg.sprite.set_alpha(0.9) return msg
closed=False, line_width=4) bbox.set_alpha(0.1) bbox.set_shader(graphics.MATSH) textfield = pi3d.Sprite(camera=graphics.CAMERA, w=590, h=70, z=3, x=-95, y=195) textfield.set_shader(graphics.MATSH) textfield.set_material((0.0, 0.0, 0.0)) textfield.set_alpha(0.7) font_path = resource_filename("shpi", "fonts/opensans.ttf") controlok = pi3d.FixedString(font_path, unichr(0xE03E), font_size=65, shadow_radius=4, background_color=(0, 0, 0, 0), color=(255, 255, 255, 255), camera=graphics.CAMERA, shader=graphics.SHADER, f_type='SMOOTH') controlok.sprite.position(245, 196, 1) controlx = pi3d.FixedString(font_path, unichr(0xE01E), font_size=65, shadow_radius=4, background_color=(0, 0, 0, 0), color=(255, 255, 255, 255), camera=graphics.CAMERA, shader=graphics.SHADER, f_type='SMOOTH')
import pi3d sys.path.insert(1, os.path.join(sys.path[0], '..')) import core.peripherals as peripherals import core.graphics as graphics import config try: unichr except NameError: unichr = chr str1 = pi3d.FixedString(config.installpath + 'fonts/opensans.ttf', 'Loading stream', font_size=32, background_color=(0,0,0,0),camera=graphics.CAMERA, shader=graphics.SHADER) str1.sprite.position(0, 0, 0.1) str2 = pi3d.FixedString(config.installpath + 'fonts/opensans.ttf', 'Touch to close stream.', font_size=22, background_color=(0,0,0,0), camera=graphics.CAMERA, shader=graphics.SHADER) str2.sprite.position(0, -225, 0.1) str3 = pi3d.FixedString(config.installpath + 'fonts/opensans.ttf', unichr(0xE017), font_size=200, background_color=(0,0,0,0), camera=graphics.CAMERA, shader=graphics.SHADER) str3.sprite.position(320, -120, 0.0) str5 = pi3d.FixedString(config.installpath + 'fonts/opensans.ttf', unichr(0xE017), font_size=200, background_color=(0,0,0,0), color=(255,0,0,255), camera=graphics.CAMERA, shader=graphics.SHADER) str5.sprite.position(320, -120, 0.0) str4 = pi3d.FixedString(config.installpath + 'fonts/opensans.ttf', unichr(0xE026), font_size=200, background_color=(0,0,0,0), camera=graphics.CAMERA, shader=graphics.SHADER) str4.sprite.position(320, 50, 0.0) def inloop(textchange = False,activity = False): str1.draw() str2.draw() str4.draw()
CAMERA2D = pi3d.Camera(is_3d=False) pi3d.Light(lightpos=(10, -10, 2)) tex = pi3d.Texture('textures/rock1.jpg') mytext = '''Pi3D is a Python module that aims to greatly simplify writing 3D in Python whilst giving access to the power of the Raspberry Pi GPU. It enables both 3D and 2D rendering and aims to provide a host of exciting commands.''' str1 = pi3d.FixedString('fonts/NotoSans-Regular.ttf', mytext, font_size=32, background_color=(200, 140, 20, 235), camera=CAMERA2D, shader=flatsh, f_type='SMOOTH') str1.sprite.positionX(-300) #NB note Shape methods act on FixedString.sprite str2 = pi3d.FixedString('fonts/NotoSerif-Regular.ttf', mytext, font_size=24, f_type='BUMP') mycuboid = pi3d.Cuboid(camera=CAMERA, z=2, x=0.5) mycuboid.set_draw_details(shader, [tex, str2], 1.0, 0.0) #following is a bit low level but makes it fit nicely look in docs to see #how Buffer.unib[6 and 7] control mapping uv to object mycuboid.buf[0].unib[6] = str2.sprite.buf[0].unib[6] mycuboid.buf[0].unib[7] = str2.sprite.buf[0].unib[7]
[-390, -2, Z], [-390, 74, Z], [390, 74, Z], ] bbox = pi3d.Lines(vertices=bbox_vertices, material=(1.0,0.8,0.05), closed=False, line_width=4) bbox.set_alpha(0.1) bbox.set_shader(graphics.MATSH) textfield = pi3d.Sprite(camera=graphics.CAMERA,w=590,h=70,z=3, x = -95, y =195) textfield.set_shader(graphics.MATSH) textfield.set_material((0.0, 0.0, 0.0)) textfield.set_alpha(0.7) controlok= pi3d.FixedString(config.installpath + 'fonts/opensans.ttf', (str)(chr(0xE03E)), font_size=65,shadow_radius=4, background_color=(0,0,0,0), color= (255,255,255,255), camera=graphics.CAMERA, shader=graphics.SHADER, f_type='SMOOTH') controlok.sprite.position(245, 196, 1) controlx= pi3d.FixedString(config.installpath + 'fonts/opensans.ttf', (str)(chr(0xE01E)), font_size=65,shadow_radius=4, background_color=(0,0,0,0), color= (255,255,255,255), camera=graphics.CAMERA, shader=graphics.SHADER, f_type='SMOOTH') controlx.sprite.position(335, 196, 1) keyboardfield = pi3d.Sprite(camera=graphics.CAMERA,w=780,h = 380,z=3, x = 0, y =-40) keyboardfield.set_shader(graphics.MATSH) keyboardfield.set_material((0.0, 0.0, 0.0)) keyboardfield.set_alpha(0.7)
def main(fname="assets/dictionaries/words.txt", N=12): # create display DISPLAY = pi3d.Display.create(background=(0.7, 0.3, 0.9, 1)) # create camera and move it back a bit CAM = pi3d.Camera(at=(0.5, N / 2, 0.0), eye=(0.25, N / 2, -1.5 * N)) letter_matrix = create_letter_matrix(N) cubeMap = [] heightMap = gen_heightMap(N) draw_cubeMap(cubeMap, heightMap, N) # create keyboard listener keys = pi3d.Keyboard() # load shaders shader = pi3d.Shader("uv_bump") lshader = pi3d.Shader('uv_light') shinesh = pi3d.Shader("uv_reflect") matsh = pi3d.Shader("mat_reflect") #Place the words in the matrix placeWords(fname, letter_matrix, N) randomize_empty_cells(letter_matrix, N) print(letter_matrix) r = 0 light = pi3d.Light(lightpos=(-3, -10, 5), lightcol=(0.5, 0.5, 0.5), lightamb=(0.5, 0.5, 0.5), is_point=False) # set cube details for i, cuberow in enumerate(cubeMap): for j, cube in enumerate(cuberow): string1 = pi3d.FixedString(camera=CAM, font="fonts/FreeSans.ttf", font_size=12, string=letter_matrix[i][j] + ("\n" * int(math.ceil(cube.height))), color="#FFFFFF", justify="C", f_type="SMOOTH", background_color="#000000" ) # EMBOSS, CONTOUR, BLUR, SMOOTH, BUMP cube.set_draw_details(lshader, [string1], 1.0) cube.set_light(light, 0) # display loop try: while DISPLAY.loop_running(): CAM.relocate(rot=r, distance=[-5, -5, -5]) #draw loop for cuberow in cubeMap: for cube in cuberow: cube.draw() # take a screenshot every 90 degree rotation if r % 90 == 0: pi3d.util.Screenshot.screenshot("screen_" + str(r) + ".png") r += 1 # only do one rotation if r == 360: break # handle escape if keys.read() == 27: break finally: # can also except KeyboardInterrup: for ctrl c specific things keys.close() DISPLAY.destroy()
CAMERA2D = pi3d.Camera(is_3d=False) pi3d.Light(lightpos=(10, -10, 2)) tex = pi3d.Texture('textures/rock1.jpg') mytext = '''Pi3D is a Python module that aims to greatly simplify writing 3D in Python whilst giving access to the power of the Raspberry Pi GPU. It enables both 3D and 2D rendering and aims to provide a host of exciting commands.''' # 'normal' FixedString on a (fairly) solid background str1 = pi3d.FixedString('fonts/NotoSans-Regular.ttf', mytext, font_size=32, background_color=(200, 140, 20, 235), camera=CAMERA2D, shader=flatsh, f_type='SMOOTH') str1.sprite.position(-300, 0, 2) #NB note Shape methods act on FixedString.sprite # shadow outline FixedString to show up against light or dark backgrounds # try setting shadow_radius to 0 to see what the issue is str1a = pi3d.FixedString('fonts/NotoSans-Regular.ttf', mytext[:53], font_size=48, color=(70, 70, 180, 255), background_color=None, shadow_radius=1, camera=CAMERA2D, shader=flatsh,
def init(): global seplines, degwind, weathericon, text, line, baroneedle, windneedle, linemin, linemax, acttemp text = pi3d.PointText(graphics.pointFont, graphics.CAMERA, max_chars=700, point_size=128) owm = pyowm.OWM(API_key=config.owmkey, language=config.owmlanguage) place = owm.weather_at_place(config.owmcity) weather = place.get_weather() if config.owmlanguage == 'de': weekdays = [ 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag' ] else: weekdays = [ 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' ] if not os.path.exists('sprites/' + weather.get_weather_icon_name() + '.png'): import urllib.request urllib.request.urlretrieve( "http://openweathermap.org/img/wn/" + weather.get_weather_icon_name() + "@2x.png", "sprites/" + weather.get_weather_icon_name() + ".png") weathericon = pi3d.ImageSprite(config.installpath + 'sprites/' + weather.get_weather_icon_name() + '.png', shader=graphics.SHADER, camera=graphics.CAMERA, w=150, h=150, z=2, x=-220) city = pi3d.TextBlock(-390, 180, 0.1, 0.0, 150, text_format=place.get_location().get_name(), size=0.7, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(city) city = pi3d.TextBlock(-380, 80, 0.1, 0.0, 30, text_format=weather.get_detailed_status(), size=0.4, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(city) # acttemp = pi3d.TextBlock(-280, 0, 0.1, 0.0, 10, text_format= str(weather.get_temperature(unit='celsius')['temp']) + '°C' , size=0.5, spacing="F",space=0.05,colour=(1.0, 1.0, 1.0,1.0)) #text.add_text_block(acttemp) acttemp = pi3d.FixedString( config.installpath + 'fonts/opensans.ttf', str(weather.get_temperature(unit='celsius')['temp']) + '°C', font_size=42, shadow_radius=1, justify='L', color=(255, 255, 255, 255), camera=graphics.CAMERA, shader=graphics.SHADER, f_type='SMOOTH') acttemp.sprite.position(-210, -50, 1) sunriset = weather.get_sunrise_time( timeformat='date') + datetime.timedelta(hours=2) sunsett = weather.get_sunset_time(timeformat='date') + datetime.timedelta( hours=2) sunset = pi3d.TextBlock(50, 100, 0.1, 0.0, 20, text_format=chr(0xE041) + " %s:%02d" % (sunriset.hour, sunriset.minute) + ' ' + chr(0xE042) + " %s:%02d" % (sunsett.hour, sunsett.minute), size=0.3, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(sunset) barometer = pi3d.TextBlock(50, -50, 0.1, 0.0, 10, text_format=chr(0xE00B) + ' ' + str(weather.get_pressure()['press']) + ' hPa', size=0.3, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(barometer) baroneedle = pi3d.Triangle(camera=graphics.CAMERA, corners=((-2, 0, 0), (0, 7, 0), (2, 0, 0)), x=barometer.x + 16, y=barometer.y - 6, z=0.1) baroneedle.set_shader(graphics.MATSH) normalizedpressure = (weather.get_pressure()['press'] - 950) if normalizedpressure < 0: normalizedpressure = 0 if normalizedpressure > 100: normalizedpressure = 100 green = 0.02 * (normalizedpressure) if green > 1: green = 1 red = 0.02 * (100 - normalizedpressure) if red > 1: red = 1 barometer.colouring.set_colour([red, green, 0, 1.0]) baroneedle.set_material([red, green, 0]) baroneedle.rotateToZ(100 - (normalizedpressure * 2)) humidity = pi3d.TextBlock(50, 0, 0.1, 0.0, 10, text_format=chr(0xE003) + ' ' + str(weather.get_humidity()) + '%', size=0.3, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(humidity) if 'speed' in weather.get_wind(): wind = pi3d.TextBlock(50, 50, 0.1, 0.0, 10, text_format=chr(0xE040) + ' ' + str(weather.get_wind()['speed']) + 'm/s', size=0.3, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(wind) if 'deg' in weather.get_wind(): degwind = True windneedle = pi3d.Triangle(camera=graphics.CAMERA, corners=((-3, 0, 0), (0, 15, 0), (3, 0, 0)), x=wind.x + 180, y=wind.y, z=0.1) windneedle.set_shader(graphics.MATSH) windneedle.set_material([1, 1, 1]) windneedle.rotateToZ(weather.get_wind()['deg']) else: degwind = False fc = owm.three_hours_forecast(config.owmcity) f = fc.get_forecast() step = 780 / (len(f)) actualy = -400 + step temp_max = [] temp_min = [] temp = [] seplines = [] icons = [] maxdaytemp = -100 mindaytemp = 100 for weather in f: if not os.path.exists('sprites/' + weather.get_weather_icon_name() + '.png'): import urllib.request urllib.request.urlretrieve( "http://openweathermap.org/img/wn/" + weather.get_weather_icon_name() + "@2x.png", "sprites/" + weather.get_weather_icon_name() + ".png") icons.append( pi3d.ImageSprite('sprites/' + weather.get_weather_icon_name() + '.png', shader=graphics.SHADER, camera=graphics.CAMERA, w=20, h=20, z=1, x=actualy, y=-220)) if weather.get_reference_time('iso')[11:16] == '00:00': line = pi3d.Lines(vertices=[[actualy, -50, 2], [actualy, 50, 2]], line_width=1, y=-180, strip=True) line.set_shader(graphics.MATSH) line.set_material((0, 0, 0)) line.set_alpha(0.9) seplines.append(line) #if weather.get_reference_time('iso')[11:16] == '12:00': day = weather.get_reference_time(timeformat='date').weekday() if actualy < 300: city = pi3d.TextBlock(actualy + 65, -100, 0.1, 0.0, 30, text_format=weekdays[day], justify=0.5, size=0.23, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(city) if actualy > -300: city = pi3d.TextBlock(actualy - 6 * step, -150, 0.1, 0.0, 30, text_format=str(round(maxdaytemp, 1)) + '°C', size=0.25, spacing="F", space=0.05, colour=(1.0, 0.0, 0.0, 1.0)) text.add_text_block(city) city = pi3d.TextBlock(actualy - 6 * step, -210, 0.1, 0.0, 30, text_format=str(round(mindaytemp, 1)) + '°C', size=0.25, spacing="F", space=0.05, colour=(0.0, 0.0, 1.0, 1.0)) text.add_text_block(city) maxdaytemp = -100 mindaytemp = 100 if '3h' in weather.get_snow(): line = pi3d.Lines( vertices=[[actualy, -50, 2], [actualy, (-50 + weather.get_snow()['3h'] * 30), 2]], line_width=3, y=-180, strip=True) line.set_shader(graphics.MATSH) line.set_material((0.5, 0.5, 1)) line.set_alpha(1) seplines.append(line) if '3h' in weather.get_rain(): line = pi3d.Lines( vertices=[[actualy, -50, 2], [actualy, (-50 + weather.get_rain()['3h'] * 30), 2]], line_width=3, y=-180, strip=True) line.set_shader(graphics.MATSH) line.set_material((0, 0, 1)) line.set_alpha(1) seplines.append(line) temperatures = weather.get_temperature(unit='celsius') if temperatures['temp_max'] > maxdaytemp: maxdaytemp = temperatures['temp_max'] if temperatures['temp_min'] < mindaytemp: mindaytemp = temperatures['temp_min'] temp_max.append([actualy, temperatures['temp_max'] * 3, 2]) temp_min.append([actualy, temperatures['temp_min'] * 3, 2]) temp.append([actualy, temperatures['temp'] * 3, 2]) actualy += step lastvalue = 0 line = pi3d.Lines(vertices=temp, line_width=2, y=-220, strip=True) line.set_shader(graphics.MATSH) line.set_material((0, 0, 0)) line.set_alpha(0.9) linemin = pi3d.Lines(vertices=temp_min, line_width=1, y=-220, strip=True) linemin.set_shader(graphics.MATSH) linemin.set_material((0, 0, 1)) linemin.set_alpha(0.9) linemax = pi3d.Lines(vertices=temp_max, line_width=1, y=-220, strip=True) linemax.set_shader(graphics.MATSH) linemax.set_material((1, 0, 0)) linemax.set_alpha(0.9)
model.isValidSelection = True pos += positionIncrement model.obj.positionX(pos) print("Placing ", str(model.obj.name), " at ", str(round(model.obj.x(), 4)), "\r") ModelSetup() new_models = models[:] #set up the waiting screen and camera for it waitscreen = pi3d.FixedString(home_path + 'fonts/NotoSans-Regular.ttf', "[ listen ]", font_size=72, color=(0, 0, 0, 255), background_color=(255, 255, 255, 0), camera=CAMERA2D, shader=flatsh, f_type='SMOOTH') waitscreen.sprite.position(0, 0, 0) selectionID = 0 selected = [] #keep track of what has been selected... makeSelection = False clientMachine = 0 isPlayingVideoLoop = False #set initial rotation value rotY = 0 rotX = 0
#!/usr/bin/env python # -*- coding: utf-8 -*- import os import sys import pi3d from pkg_resources import resource_filename from .. import config from ..core import peripherals from ..core import graphics #sys.path.insert(1, os.path.join(sys.path[0], '..')) font_path = resource_filename("shpi", "fonts/opensans.ttf") str1 = pi3d.FixedString(font_path, 'Loading stream', font_size=32, background_color=(0,0,0,0),camera=graphics.CAMERA, shader=graphics.SHADER) str1.sprite.position(0, 0, 0.1) str2 = pi3d.FixedString(font_path, 'Touch to close stream.', font_size=22, background_color=(0,0,0,0), camera=graphics.CAMERA, shader=graphics.SHADER) str2.sprite.position(0, -225, 0.1) do_setup = True #videostream are opened from thermostat slide def inloop(textchange=False, activity=False): global do_setup if do_setup: try: os.popen('killall omxplayer.bin') except: pass os.popen(
cam2D = pi3d.Camera(is_3d=False) shader = pi3d.Shader('uv_flat') keys = pi3d.Keyboard() back = pi3d.ImageSprite('textures/straw1.jpg', shader=shader, w=display.width, h=display.height, z=2000.0, camera=cam2D) text = pi3d.FixedString('fonts/NotoSans-Regular.ttf', '''w,a,s,d move emitter location. switch between different particles with space esc to quit''', font_size=32, camera=cam2D, shader=shader, f_type='SMOOTH') text.z = 150 particles = [ pi3d.PexParticles('pex/jelly_fish.pex', camera=cam2D, z=100, emission_rate=40, scale=0.5), pi3d.PexParticles('pex/fire.pex', camera=cam2D, z=200, emission_rate=80), pi3d.PexParticles('pex/drugs.pex', camera=cam2D, z=300,
# Planet earthimg = pi3d.Texture('planet.jpg') ball = pi3d.Sphere(sides=24, slices=24) # Imperial Logo isdlogo = pi3d.Texture('imperialseal-100px.png') logo = pi3d.ImageSprite(isdlogo, shader) logo.position(4.0, 2.0, backplaneZ) # Title mytext = "UNOBTANIUM MINING COMMAND CONSOLE" title = pi3d.FixedString(fontfile, mytext, font_size=48, camera=CAM2D, shader=flatshader, f_type='SMOOTH', justify='L') tx = topleftx + title.sprite.width / 2 ty = toplefty - title.sprite.height / 2 title.sprite.position(tx, ty, backplaneZ) # Collection Amount collamt = pi3d.String(font=font, string=coll_amount_string(), x=-1.45, y=1.00, z=-3) collamt.set_material((1.0, 1.0, 1.0)) collamt.set_shader(shader)
def __make_text(self, pic, paused, side=0, pair=False): # if side 0 and pair False then this is a full width text and put into # __textblocks[0] otherwise it is half width and put into __textblocks[position] info_strings = [] if pic is not None and (self.__show_text > 0 or paused): #was SHOW_TEXT_TM > 0.0 if (self.__show_text & 1) == 1 and pic.title is not None: # title info_strings.append(pic.title) if (self.__show_text & 2) == 2 and pic.caption is not None: # caption info_strings.append(pic.caption) if (self.__show_text & 4) == 4: # name info_strings.append(os.path.basename(pic.fname)) if (self.__show_text & 8) == 8 and pic.exif_datetime > 0: # date fdt = time.strftime(self.__show_text_fm, time.localtime(pic.exif_datetime)) info_strings.append(fdt) if (self.__show_text & 16) == 16 and pic.location is not None: # location location = pic.location # search for and remove substrings from the location text if self.__geo_suppress_list is not None: for part in self.__geo_suppress_list: location = location.replace(part, "") # remove any redundant concatination strings once the substrings have been removed location = location.replace(" ,", "") # remove any trailing commas or spaces from the location location = location.strip(", ") info_strings.append( location ) #TODO need to sanitize and check longer than 0 for real if (self.__show_text & 32) == 32: # folder info_strings.append( os.path.basename(os.path.dirname(pic.fname))) if paused: info_strings.append("PAUSED") final_string = " • ".join(info_strings) block = None if len(final_string) > 0: if side == 0 and not pair: c_rng = self.__display.width - 100 # range for x loc from L to R justified else: c_rng = self.__display.width * 0.5 - 100 # range for x loc from L to R justified block = pi3d.FixedString( self.__font_file, final_string, shadow_radius=3, font_size=self.__show_text_sz, shader=self.__flat_shader, justify=self.__text_justify, width=c_rng, color=(255, 255, 255, int(255 * float(self.__text_opacity)))) adj_x = (c_rng - block.sprite.width ) // 2 # half amount of space outside sprite if self.__text_justify == "L": adj_x *= -1 elif self.__text_justify == "C": adj_x = 0 if side == 0 and not pair: # i.e. full width x = adj_x else: x = adj_x + int(self.__display.width * 0.25 * (-1.0 if side == 0 else 1.0)) y = (block.sprite.height - self.__display.height + self.__show_text_sz) // 2 block.sprite.position(x, y, 0.1) block.sprite.set_alpha(0.0) if side == 0: self.__textblocks[1] = None self.__textblocks[side] = block
#!/usr/bin/env python # -*- coding: utf-8 -*- import os, sys import pi3d sys.path.insert(1, os.path.join(sys.path[0], '..')) import core.peripherals as peripherals import config import core.graphics as graphics str1 = pi3d.FixedString(config.installpath + 'fonts/opensans.ttf', 'ALERT!', font_size=72, color=(255, 0, 0, 255), background_color=(0, 0, 0, 0), camera=graphics.CAMERA, shader=graphics.SHADER) str1.sprite.position(0, 0, 0.1) def inloop(textchange=False, activity=False): str1.draw() if peripherals.touch_pressed: peripherals.touch_pressed = False config.subslide = None peripherals.eg_object.alert = 0 peripherals.alert(0)
#!/usr/bin/env python # -*- coding: utf-8 -*- import os, sys import pi3d from pkg_resources import resource_filename from .. import config from ..core import peripherals from ..core import graphics #sys.path.insert(1, os.path.join(sys.path[0], '..')) str1 = pi3d.FixedString(resource_filename("shpi", "fonts/opensans.ttf"), 'ALERT!', font_size=72, color=(255, 0, 0, 255), background_color=(0, 0, 0, 0), camera=graphics.CAMERA, shader=graphics.SHADER) str1.sprite.position(0, 0, 0.1) def inloop(textchange=False, activity=False): str1.draw() if peripherals.check_touch_pressed(): config.subslide = None peripherals.eg_object.alert = 0 peripherals.alert(0) return activity
from .. import config from ..core import peripherals from ..core import graphics #sys.path.insert(1, os.path.join(sys.path[0], '..')) try: unichr except NameError: unichr = chr font_path = resource_filename("shpi", "fonts/opensans.ttf") str1 = pi3d.FixedString(font_path, 'Loading stream', font_size=32, background_color=(0, 0, 0, 0), camera=graphics.CAMERA, shader=graphics.SHADER) str1.sprite.position(0, 0, 0.1) str2 = pi3d.FixedString(font_path, 'Touch to close stream.', font_size=22, background_color=(0, 0, 0, 0), camera=graphics.CAMERA, shader=graphics.SHADER) str2.sprite.position(0, -225, 0.1) str3 = pi3d.FixedString(font_path, unichr(0xE017), font_size=200,
from .. import config from ..core import peripherals from ..core import graphics from ..core import iwlist #sys.path.insert(1, os.path.join(sys.path[0], '..')) try: unichr except NameError: unichr = chr font_path = resource_filename("shpi", "fonts/opensans.ttf") controlx= pi3d.FixedString(font_path, unichr(0xE01E), font_size=65,shadow_radius=4, background_color=(0,0,0,0), color= (255,255,255,255), camera=graphics.CAMERA, shader=graphics.SHADER, f_type='SMOOTH') controlx.sprite.position(335, 196, 1) wifinetworkstext = pi3d.FixedString(font_path, 'Choose your WIFI-network:' , font_size=42, shadow_radius=4,justify='L', background_color=(0,0,0,30), color= (255,255,255,255),camera=graphics.CAMERA, shader=graphics.SHADER, f_type='SMOOTH') wifinetworkstext.sprite.position(0, 200, 1) wifinetworks = None selectednetwork = None def inloop(textchange=False, activity=False, x=0, y=0, touch_pressed=False): global wifinetworks, selectednetwork wifinetworkstext.draw() controlx.draw() if wifinetworks is None: # only runs once as this block creates actnetwork = 0 wifinetworks = iwlist.scan()
# 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() if k != -1: lastKeyRead = k if k == 97: # A key pressed previousXPosition = cylinder.x() cylinder.positionX(previousXPosition - delta) elif k == 100: # D key pressed