def __init__(self, sleep, blink): #Create canvas shader = pi3d.Shader("2d_flat") self.canvas = pi3d.Canvas() self.canvas.set_shader(shader) self.sleepTimer = sleep self.blinkTimer = blink self.sleeping = False self.blinkCount = 0
def __init__(self): self.canvas = pi3d.Canvas() self.canvas.set_shader(shader[0]) self.fade = 0.0 self.slides = [None] * nSli half = 0 for i in range(nSli): self.slides[i] = Slide() for i in range(nSli): item = [iFiles[i % nFi], self.slides[i % nSli]] fileQ.put(item) self.focus = nSli - 1 self.focus_fi = nFi - 1
def __init__(self): # Start the image dictionary self.imagedict = {} self.process = "Carousel" # Load the last image used try: # If there is a settings file, load most recent image # Load the settings file settings = read_settings(self.process) # Add the image to the queue logging.info("Last image: %s" % settings["lastimage"]) starting_image = settings["lastimage"] except: logging.exception("Failed to load settings file") logging.info("Loading default image") # Write new image to settings settings = read_settings(self.process) settings["lastimage"] = "static/images/logo.jpg" write_settings(self.process, settings) settings = read_settings(self.process) # Load default image into queue starting_image = settings["lastimage"] # Set up image one texture_one = pi3d.Texture(starting_image, blend=True, mipmap=True) image_one = pi3d.Canvas() image_one.set_texture(texture_one) width, height, x_position, y_position = fit_image(texture_one) image_one.set_2d_size(w=width, h=height, x=x_position, y=y_position) image_one.set_alpha(1) image_one.set_shader(SHADER) image_one.positionZ(0.1) self.imagedict[starting_image] = { "canvas": image_one, "visible": True, "fading": True } self.focus = starting_image
) # don't need this for picture frame but useful for testing shader = [ pi3d.Shader("shaders/blend_star"), pi3d.Shader("shaders/blend_holes"), pi3d.Shader("shaders/blend_false"), pi3d.Shader("shaders/blend_burn"), pi3d.Shader("shaders/blend_bump") ] num_sh = len(shader) iFiles, nFi = get_files() fade = 0.0 pic_num = nFi - 1 canvas = pi3d.Canvas() canvas.set_shader(shader[0]) CAMERA = pi3d.Camera.instance() CAMERA.was_moved = False #to save a tiny bit of work each loop pictr = 0 # to allow shader changing every PPS slides shnum = 0 # shader number nexttm = 0.0 # force next on first loop fade_step = 1.0 / (FPS * FADE_TM) sbg = tex_load(iFiles[pic_num]) # initially load a background slide while DISPLAY.loop_running(): tm = time.time() if tm > nexttm: # load next image nexttm = tm + TMDELAY
def pick(self, new_image): """ Pick an image by URL """ if self.focus != new_image: # Check to see if image already in dictionary # Might be worth pre-preparing # a dictionary with null canvas objects? # If image is already loaded, make it visible if new_image in self.imagedict: # print("Image exists") # New focus image is visible self.imagedict[new_image]["visible"] = True # New focus image is the active fader self.imagedict[new_image]["fading"] = True # Otherwise load it as a new image else: # print("Load new image") new_canvas = pi3d.Canvas() # print("Pick an image: %s" % new_image) new_texture = pi3d.Texture(new_image, blend=True, mipmap=True) # print("Texture loaded") new_canvas.set_texture(new_texture) # print("Texture set") # Fit image width, height, x_position, y_position = fit_image(new_texture) new_canvas.set_2d_size(w=width, h=height, x=x_position, y=y_position) new_canvas.set_alpha(0) new_canvas.set_shader(SHADER) new_canvas.positionZ(0.2) # print("New image prepared") self.imagedict[new_image] = { "canvas": new_canvas, "visible": True, "fading": True } # Move old focused image back if self.imagedict[self.focus]["canvas"].z() > 0.1: self.imagedict[self.focus]["canvas"].positionZ(0.1) # Bring new focused image forward self.imagedict[new_image]["canvas"].positionZ(0.2) # Old focus image not the active fader self.imagedict[self.focus]["fading"] = False self.focus = new_image # Change the focused image # Write new image to settings settings = read_settings(self.process) settings["lastimage"] = new_image write_settings(self.process, settings) settings = read_settings(self.process) else: logging.warning("Image already projected")
import pi3d from pi3d.sprite.Ball_2d import Ball_2d MAX_BALLS = 15 MIN_BALL_SIZE = 5 MAX_BALL_SIZE = 100 MAX_BALL_VELOCITY = 10.0 KEYBOARD = pi3d.Keyboard() BACKGROUND_COLOR = (1.0, 1.0, 1.0, 0.0) DISPLAY = pi3d.Display.create(background=BACKGROUND_COLOR) WIDTH, HEIGHT = DISPLAY.width, DISPLAY.height SHADER = pi3d.Shader('shaders/2d_flat') CANVAS = pi3d.Canvas() CANVAS.set_shader(SHADER) TEXTURE_NAMES = [ 'textures/red_ball.png', 'textures/grn_ball.png', 'textures/blu_ball.png' ] TEXTURES = [pi3d.Texture(t) for t in TEXTURE_NAMES] def random_ball(): """Return a ball with a random color, position and velocity.""" return Ball_2d(canvas=CANVAS, texture=random.choice(TEXTURES), radius=random.uniform(MIN_BALL_SIZE, MAX_BALL_SIZE), x=random.uniform(0.0, WIDTH), y=random.uniform(0.0, HEIGHT),