Esempio n. 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
Esempio n. 2
0
#DISPLAY = pi3d.Display.create(x=0, y=0, frames_per_second=30) #default screen for Pi
#DISPLAY = pi3d.Display.create(0, 0, 640,480,32, frames_per_second=30,window_title='Space Pi-rates',mouse=False) ## For testing on desktop (set to 640x480)
DISPLAY = pi3d.Display.create(
    0,
    0,
    screenwidth,
    screenheight,
    32,
    frames_per_second=30,
    window_title='Space Pi-rates',
    mouse=False)  ## For testing on desktop (set to 640x480)

#a default camera is created automatically but we might need a 2nd 2D camera
#for displaying the instruments etc. Also, because the landscape is large
#we need to set the far plane to 10,000
CAMERA = pi3d.Camera(lens=(1.0, 10000.0, 55.0, 1.33))  #4:3 res
#CAMERA = pi3d.Camera(lens=(1.0, 10000.0, 55.0, 1.77)) #16:9 res
#CAMERA = pi3d.Camera(lens=(1.0, 10000.0, 55.0, 2.0))
CAMERA2D = pi3d.Camera(is_3d=False)

print("""===================================
== W increase power, S reduce power
== V view mode, C control mode
== B brakes
== X jumps to location of 1st enemy in list
== P Fires beams
== Q to turn left, E to turn right
== I to climb, K to desend
== 1 Toggle Instruments
================================""")
Esempio n. 3
0
    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))
Esempio n. 4
0
# onscreen.  eyePosition, also pixels, is the offset (left or right) from
# the center point of the screen to the center of each eye.  This geometry
# is explained more in-depth in fbx2.c.
if DISPLAY.width <= (DISPLAY.height * 2):
	eyeRadius   = DISPLAY.width / 5
	eyePosition = DISPLAY.width / 4
else:
	eyeRadius   = DISPLAY.height * 2 / 5
	eyePosition = DISPLAY.height / 2

# A 2D camera is used, mostly to allow for pixel-accurate eye placement,
# but also because perspective isn't really helpful or needed here, and
# also this allows eyelids to be handled somewhat easily as 2D planes.
# Line of sight is down Z axis, allowing conventional X/Y cartesion
# coords for 2D positions.
cam    = pi3d.Camera(is_3d=False, at=(0,0,0), eye=(0,0,-1000))
shader = pi3d.Shader("uv_light")
light  = pi3d.Light(lightpos=(0, -500, -500), lightamb=(0.2, 0.2, 0.2))


# Load texture maps --------------------------------------------------------

irisMap   = pi3d.Texture("graphics/iris.jpg"  , mipmap=False,
              filter=pi3d.GL_LINEAR)
scleraMap = pi3d.Texture("graphics/sclera.png", mipmap=False,
              filter=pi3d.GL_LINEAR, blend=True)
lidMap    = pi3d.Texture("graphics/lid.png"   , mipmap=False,
              filter=pi3d.GL_LINEAR, blend=True)
# U/V map may be useful for debugging texture placement; not normally used
#uvMap     = pi3d.Texture("graphics/uv.png"    , mipmap=False,
#              filter=pi3d.GL_LINEAR, blend=False, m_repeat=True)
Esempio n. 5
0
x = json_data['coords'][0]['conformers'][0]['x']
y = json_data['coords'][0]['conformers'][0]['y']
z = json_data['coords'][0]['conformers'][0]['z']
n = len(element)
'''NB if you download different molecules you might need to add to alter this.
 atomic number: name, radius, (r,g,b) tuple '''
atoms = {
    1: ['hydrogen', 0.5, (1.0, 0.0, 0.0)],
    6: ['carbon', 0.8, (0.1, 0.1, 0.1)],
    7: ['nitrogen', 0.9, (0.1, 0.9, 1.0)],
    8: ['oxygen', 0.9, (1.0, 1.0, 1.0)],
    15: ['phosphorus', 1.5, (1.0, 0.0, 1.0)]
}

display = pi3d.Display.create(frames_per_second=30)
camera = pi3d.Camera()

ball = pi3d.Sphere(radius=atoms[6][1])
carbon = pi3d.MergeShape(z=10)
for i in range(n):
    if element[i] == 6:
        carbon.add(ball, x[i], y[i], z[i])
carbon.set_material(atoms[6][2])
carbon.set_fog((0.3, 0.2, 0.6, 0.1), 18)

for e in atoms:
    if e != 6:  # don't do carbon again
        ball = pi3d.Sphere(radius=atoms[e][1])
        elem = pi3d.MergeShape()
        for i in range(n):
            if element[i] == e:
Esempio n. 6
0
    def get_value(self):
        return self.value

    def set_value(self, value):
        self.value = value
        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))
        self.set_flag = True


DISPLAY = pi3d.Display.create(layer=0,
                              w=800,
                              h=480,
                              background=(0.0, 0.0, 0.0, 1.0),
                              frames_per_second=60,
                              tk=False,
                              samples=4)
CAMERA = pi3d.Camera(is_3d=False)  # will create its own cam if one not passed

dial = Dial(camera=CAMERA)

i = 0
while DISPLAY.loop_running():
    dial.check_touch()
    dial.draw()

DISPLAY.destroy()
                              | pi3d.DISPLAY_CONFIG_MAXIMIZED,
                              use_glx=True)

print(display.opengl.gl_id)  # the type of glsl your pi is running

if W is None or H is None:
    (W, H) = (display.width, display.height)
print('setting display size to ' + str(W) + ' ' + str(H))

## shadertoy shader stuff ##
sprite = pi3d.Triangle(corners=((-1.0, -1.0), (-1.0, 3.0), (3.0, -1.0)))
shader = pi3d.Shader('cloud')  # cloud shader
sprite.set_shader(shader)

## offscreen texture stuff ##
cam = pi3d.Camera(is_3d=False)
postsh = pi3d.Shader('post_pixelize')
post = pi3d.PostProcess(camera=cam, shader=postsh, scale=SCALE)

## interactive inputs ##
kbd = pi3d.Keyboard()
mouse = pi3d.Mouse()  # pi3d.Mouse(restrict = True) # changes input coordinates
mouse.start()
MX, MY = mouse.position()
MXC, MYC = mouse.position()
MC = mouse.button_status(
)  # 8 = hover, 9 = right Click down, 10 = left C, 12 = middle C
MouseClicked = False

## set up time ##
iTIME = 0
Esempio n. 8
0
#!/usr/bin/python
from __future__ import absolute_import, division, print_function, unicode_literals
from math import sin, cos, radians
import pi3d
DISPLAY = pi3d.Display.create(w=800,
                              h=480,
                              background=(1.0, 1.0, 1.0, 1.0),
                              frames_per_second=60)

shaderflat = pi3d.Shader("uv_flat")
CAMERA = pi3d.Camera(is_3d=False)
CAMERA3D = pi3d.Camera(eye=(0, 0, -0.1))
slide = pi3d.ImageSprite('backgrounds/IMG-20160924-WA0008.jpg',
                         shader=shaderflat,
                         camera=CAMERA,
                         w=800,
                         h=480,
                         z=7500)

shader = pi3d.Shader("uv_light")
shinesh = pi3d.Shader("uv_reflect")
flatsh = pi3d.Shader("uv_flat")
matsh = pi3d.Shader("mat_reflect")
matl = pi3d.Shader("mat_light")

test = pi3d.Texture('backgrounds/IMG-20160924-WA0008.jpg')

mydoor = pi3d.Cuboid(CAMERA3D,
                     w=0.5,
                     h=1,
                     d=0.08,
Esempio n. 9
0
rot = 0.0
tilt = 0.0
avhgt = 3.5
xm = 0.0
zm = 0.0
ym = mymap.calcHeight(xm, zm) + avhgt
step = [0.0, 0.0, 0.0]
norm = None
crab = False

# Fetch key presses
mykeys = pi3d.Keyboard()
mymouse = pi3d.Mouse(restrict=False)
mymouse.start()

CAMERA = pi3d.Camera(absolute=False)
roll = 0.0
# Display scene and rotate cuboid
while DISPLAY.loop_running():
    xm, ym, zm = CAMERA.relocate(rot,
                                 tilt,
                                 point=[xm, ym, zm],
                                 distance=step,
                                 normal=norm,
                                 crab=crab,
                                 slope_factor=1.5)
    if step != [0.0, 0.0, 0.0]:  #i.e. previous loop set movmement
        ym, norm = mymap.calcHeight(xm, zm, True)
        ym += avhgt
        step = [0.0, 0.0, 0.0]
    myecube.position(xm, ym, zm)
Esempio n. 10
0
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()
Esempio n. 11
0
import sys
sys.path.insert(1,'/home/pi/pi3d') # to use local 'develop' branch version
import pi3d
import numpy as np
import math
import random

RANGE = 100.0
HIT_DIST = 5.0
MODEL_PATH = '{}'
display = pi3d.Display.create(background=(0.0, 0.0, 0.0, 0.0))
# option 1 move near plane away (default is 1.0)
#_di = display.INSTANCE
camera = pi3d.Camera()#lens=(15.0, display.far, display.fov, display.width/float(display.height)))
shader = pi3d.Shader('uv_light_nearfade')
laser_shader = pi3d.Shader('mat_flat')

# pod, base and gun
pod = pi3d.Model(file_string=MODEL_PATH.format('pod_2.obj'), z=20.0)
laser_base = pi3d.Model(file_string=MODEL_PATH.format('laser_base_2.obj'), y=3.15)
laser_gun = pi3d.Model(file_string=MODEL_PATH.format('laser_gun_2.obj'), y=0.4, z=-0.4)
laser_base.add_child(laser_gun)
pod.add_child(laser_base)
pod.set_shader(shader) # all use uv_light shader

# laser beam itself not a child
laser_tip = pi3d.Cuboid(w=0.05, h=0.05, d=5.0)
laser_tip.set_material((1.0, 0.0, 0.0))
laser_tip.set_alpha(0.8)
laser_tip.set_shader(laser_shader)
Esempio n. 12
0
#!/usr/bin/python
from __future__ import absolute_import, division, print_function, unicode_literals

import pi3d
from picamera import PiCamera

DISPLAY = pi3d.Display.create(x=0, y=0, background=(0.0,0.0,0.0,0.0), layer=3)

CAMERA = pi3d.Camera(at=(0, 0, 1), eye=(0, 0, 0))
TEXT_CAMERA = pi3d.Camera(is_3d=False)
piCamera = PiCamera()
piCamera.start_preview()
# Shaders
shader = pi3d.Shader("uv_light")
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
Esempio n. 13
0
avhgt = 11.0
xm = random.random() * MSIZE * NX
zm = random.random() * MSIZE * NZ
dx = -math.sin(math.radians(rot))
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)
Esempio n. 14
0
unicode æ ö ¼
Strings """ + unichr(255) + ' ' + unichr(256) + ' ' + unichr(257)

# character 255 should appear, character 256 should not.

# Setup display and initialise pi3d
DISPLAY = pi3d.Display.create(x=10,
                              y=10,
                              w=900,
                              h=600,
                              frames_per_second=25,
                              window_title='Blur demo')
DISPLAY.set_background(0.4, 0.6, 0.8, 1.0)  # r,g,b,alpha

persp_cam = pi3d.Camera.instance()  # default instance camera perspecive view
ortho_cam = pi3d.Camera(is_3d=False)  # 2d orthographic view camera

#setup textures, light position and initial model position
pi3d.Light((0, 5, 0))
#create shaders
shader = pi3d.Shader("uv_reflect")
flatsh = pi3d.Shader("uv_flat")
defocus = pi3d.Defocus()

#Create textures
shapeimg = pi3d.Texture("textures/straw1.jpg")
shapebump = pi3d.Texture("textures/floor_nm.jpg")
shapeshine = pi3d.Texture("textures/pong3.png")

#Create shape
myshape = pi3d.MergeShape(camera=persp_cam)  #specify perspective view
Esempio n. 15
0
GPIO.setup(chamberPin, GPIO.OUT)

button1_pressed = False
button2_pressed = False
button3_pressed = False
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
Esempio n. 16
0
#import demo
import pi3d
#import sys
#sys.path.insert(1, '/home/pi/pi3d')
DISPLAY = pi3d.Display.create(x=50,
                              y=50,
                              frames_per_second=30,
                              display_config=pi3d.DISPLAY_CONFIG_FULLSCREEN)
shader = pi3d.Shader("uv_flat")
CAMERA = pi3d.Camera(is_3d=False)
sprite = pi3d.ImageSprite("x.png", shader, w=320.0, h=240.0, z=5.0)
mykeys = pi3d.Keyboard()
xloc = 100.0
dx = 2.1
yloc = 100.0
dy = 1.13
while DISPLAY.loop_running():
    sprite.draw()
    sprite.rotateIncZ(1)
    sprite.position(xloc, yloc, 5.0)
    if xloc > 300.0:
        dx = -2.1
    elif xloc < -300.0:
        dx = 2.1
    if yloc > 300.0:
        dy = -1.13
    elif yloc < -300.0:
        dy = 1.13
    xloc += dx
    yloc += dy
Esempio n. 17
0
                              h=DEFAULT_SCREEN_HEIGHT,
                              use_pygame=True)
DISPLAY.set_background(0.0, 0.0, 0.0, 1)
DISPLAY.frames_per_second = 30
pi3d.Light(lightpos=(1, -1, -3),
           lightcol=(1.0, 1.0, 0.8),
           lightamb=(0.25, 0.2, 0.3))

# Initialize Camera
if (USE_STEREO):
    shader_name = "barrel" if USE_TUNNEL else "uv_flat"
    CAMERA = pi3d.StereoCam(separation=DEFAULT_EYE_SEPERATION,
                            interlace=0,
                            shader=shader_name)
else:
    CAMERA = pi3d.Camera(absolute=True)

# initialize inputs
handler = inputs.handlers()

# Implement Threading to read Serial
if (USE_SERIAL):
    handler.serial()
#========================================

# Create Hero & map, Select your avatars here
if AVATAR_1 == 'Link':
    avatar = avatars.link()
    avatarstereo = avatars.linkstereo()
    avatar1_3 = avatars.goombaD()
elif AVATAR_1 == 'Cloud':