예제 #1
0
    def __init__(self):
        wd = DISPLAY.width
        ht = DISPLAY.height
        asi_tex = pi3d.Texture("textures/airspeed_indicator.png")
        alt_tex = pi3d.Texture("textures/altimeter.png")
        #rad_tex = pi3d.Texture("textures/radar.png")
        #dot_tex = pi3d.Texture("textures/radar_dot.png")
        ndl_tex = pi3d.Texture("textures/instrument_needle.png")
        self.asi = pi3d.ImageSprite(asi_tex,
                                    FLATSH,
                                    camera=CAMERA2D,
                                    w=128,
                                    h=128,
                                    x=-128,
                                    y=-ht / 2 + 64,
                                    z=2)
        self.alt = pi3d.ImageSprite(alt_tex,
                                    FLATSH,
                                    camera=CAMERA2D,
                                    w=128,
                                    h=128,
                                    x=0,
                                    y=-ht / 2 + 64,
                                    z=2)
        #self.rad = pi3d.ImageSprite(rad_tex, FLATSH, camera=CAMERA2D,
        #      w=128, h=128, x=128, y=-ht/2+64, z=2)
        #self.dot = pi3d.ImageSprite(dot_tex, FLATSH, camera=CAMERA2D,
        #      w=16, h=16, z=1)
        self.ndl1 = pi3d.ImageSprite(ndl_tex,
                                     FLATSH,
                                     camera=CAMERA2D,
                                     w=128,
                                     h=128,
                                     x=-128,
                                     y=-ht / 2 + 64,
                                     z=1)
        self.ndl2 = pi3d.ImageSprite(ndl_tex,
                                     FLATSH,
                                     camera=CAMERA2D,
                                     w=128,
                                     h=128,
                                     x=0,
                                     y=-ht / 2 + 64,
                                     z=1)
        #self.ndl3 = pi3d.ImageSprite(ndl_tex, FLATSH, camera=CAMERA2D,
        #      w=128, h=128, x=128, y=-ht/2+64, z=1)
        #self.dot_list = []

        #tex = pi3d.Texture(image) not in this thread
        vidw = W * 0.7
        vidh = H * 0.7
        self.vid = pi3d.ImageSprite(vplayer.get_tex(),
                                    FLATSH,
                                    camera=CAMERA2D,
                                    w=vidw,
                                    h=vidh,
                                    x=((wd / 2) - (vidw / 2)),
                                    y=(-ht / 2) + (vidh / 2),
                                    z=2)
        self.update_time = 0.0
예제 #2
0
파일: viewer.py 프로젝트: NadavK/JPresenter
 def select_image_file(self, z_order=1.0):
     files = []
     for folder in self.image_folders:
         # make sure path has file wildcard
         if not folder.endswith('*'):
             folder += '*' if folder.endswith('/') else '/*'
         logging.debug('folder: "%s"', folder)
         files += glob.glob(folder)
     if len(files) == 0:
         logging.error('No files found in paths: "%s"', self.image_folders)
         return
     logging.debug('Number of files: "%d"', len(files))
     while True:
         # TODO: ensure its different from prev
         file = files[randrange(len(files))]
         if os.path.splitext(file)[1].lower() not in SUPPORTED_FILE_TYPES:
             logging.error('Unsupported file format: "%s"', file)
         else:
             try:
                 logging.debug('Selected file: "%s"', file)
                 return pi3d.ImageSprite(file,
                                         shader=self.shader,
                                         w=self.display.width,
                                         h=self.display.height,
                                         z=z_order)
                 # TODO: Do we need to load image with texture for mipmap?
             except Exception as e:
                 logging.exception('Failed loading image "%s"', file)
예제 #3
0
    def get_image(self, lat, long, level):
        got_image = False
        lat = int(lat)
        long = int(long)
        level = int(level)
        level_dir = join(cachedir, str(level))
        ensure_dir(level_dir)
        filename = join(level_dir, "{0}-{1}.png".format(lat, long))
        try:
            image = open(filename)
            image.close()
            got_image = True
        except Exception as e:
            #print e
            pass

        if not got_image:
            image_url = self.address.format(lat, long, level)
            print("miss, loading image from ", image_url)
            temp_file = open(filename, 'wb')
            temp_file.write(urllib.urlopen(image_url).read())
            temp_file.close()
        image = pi3d.ImageSprite(filename,
                                 self.shader,
                                 w=256.0,
                                 h=256.0,
                                 z=5.0)
        #print image , type(image)
        return image
예제 #4
0
def tex_load(fname):
    slide = pi3d.ImageSprite(fname,
                             shader=SHADER,
                             camera=CAMERA,
                             w=800,
                             h=480,
                             z=4)
    slide.set_alpha(0)
    return slide
예제 #5
0
 def __get_navigation_areas(
     self,
 ) -> typing.Tuple["pi3d.util.Gui.Widget", "pi3d.util.Gui.Widget"]:
     array = np.array([[[0, 0, 255, 0]]], dtype=np.uint8)
     texture = pi3d.Texture(array,
                            blend=True,
                            mipmap=False,
                            free_after_load=True)
     back_sprite = pi3d.ImageSprite(
         texture,
         self.__gui.shader,
         w=self.__viewer.display_width // 2,
         h=self.__viewer.display_height,
         x=0,
         y=0,
         z=4.0,
     )
     next_sprite = pi3d.ImageSprite(
         texture,
         self.__gui.shader,
         w=self.__viewer.display_width // 2,
         h=self.__viewer.display_height,
         x=0,
         y=0,
         z=4.0,
     )
     # Move left and down by 1 px to register clicks on the screen edges
     back_area = pi3d.util.Gui.Widget(
         self.__gui,
         back_sprite,
         x=-self.__viewer.display_width // 2 - 1,
         y=self.__viewer.display_height // 2 - 1,
         callback=self.__go_back,
         shortcut="a",
     )
     next_area = pi3d.util.Gui.Widget(
         self.__gui,
         next_sprite,
         x=0,
         y=self.__viewer.display_height // 2 - 1,
         callback=self.__go_next,
         shortcut="d",
     )
     return back_area, next_area
예제 #6
0
    def __init__(self, image_filename):
        # Create a sprite from the image file
        self.bg = pi3d.ImageSprite(image_filename,
                                   shader=shader_uv_flat,
                                   w=1.6,
                                   h=1)

        # Position the openinig screen graphics
        self.bg.position(0, 0, 4)
        self.bg.scale(3.7, 3.7, 1)
예제 #7
0
def tex_load(fname):
    tex = pi3d.Texture(fname, blend=True, m_repeat=True)
    slide = pi3d.ImageSprite(tex,
                             shader=shader,
                             camera=CAMERA,
                             w=DISPLAY.width,
                             h=DISPLAY.height,
                             z=5.0)
    slide.set_alpha(0.0)
    return slide
예제 #8
0
    def __init__(self,
                 element,
                 loops=1,
                 position=(0, 0),
                 rotation=(0, 0, 0),
                 size=1,
                 duration=None,
                 z=DEFAULT_Z,
                 shader=None,
                 **kwds):
        super(ImageSprite, self).__init__()
        import pi3d

        self.element = element
        self.imagename = IMAGE_DIRECTORY.expand(kwds.pop('file', None))
        del kwds['type']
        if kwds:
            s = '' if len(kwds) == 1 else 's'
            LOGGER.error('Unknown keyword%s: %s', s, ', '.join(kwds))

        self._loops = loops
        self._loop_number = 0
        self._position = Expression.expression(position, element)
        self._rotation = Expression.expression(rotation, element)
        self._size = Expression.expression(size, element)
        self._z = Expression.expression(z, element)
        self.element.time = 0  # elapsed time.
        self._time = 0  # start time.
        if duration is None:
            for env in [self._position, self._rotation, self._size, self._z]:
                if env.is_constant():
                    duration = max(duration, env.length)
            if duration is None:
                duration = INFINITY
        else:
            self._duration = Expression.convert(duration)

        if not self._duration:
            LOGGER.warning('An image sprite had a zero duration.')
        if not ImageSprite.CACHE:
            ImageSprite.CACHE = pi3d.TextureCache()

        texture = ImageSprite.CACHE.create(self.imagename)
        x, y, z = self.coords()
        self.sprite = pi3d.ImageSprite(texture,
                                       w=texture.ix,
                                       h=texture.iy,
                                       shader=Shader.shader(shader),
                                       x=x,
                                       y=y,
                                       z=z)
        self.sprite.repaint = self.repaint
예제 #9
0
 def __init__(self, value, shader, color, **kwargs):
     if Counter.textures is None:
         logger.debug("Loading numbers")
         Counter.textures = [load_icon("numbers/%d.png" % (i))
                             for i in range(0, 11)]
     self.value = value
     self.disk = FlatDisk(radius=(kwargs['w'] - 10) / 2, sides=6, rx=90)
     self.disk.set_material(color)
     self.number = Wiggle(pi3d.ImageSprite(Counter.textures[value], shader, **kwargs),
                          5, 10, 0.8)
     self.override = None
     self.last_shown = None
     super().__init__(self.number)
예제 #10
0
 def __get_menu_bg(self) -> "pi3d.ImageSprite":
     array = np.zeros((self.__menu_height, 1, 4), dtype=np.uint8)
     array[:, :, 3] = np.linspace(120, 0, self.__menu_height).reshape(-1, 1)
     texture = pi3d.Texture(array,
                            blend=True,
                            mipmap=False,
                            free_after_load=True)
     return pi3d.ImageSprite(
         texture,
         self.__gui.shader,
         w=self.__viewer.display_width,
         h=self.__menu_height,
         x=0,
         y=int(self.__viewer.display_height // 2 - self.__menu_height // 2),
         z=4.0,
     )
예제 #11
0
def load_sprites():
    sprite_filenames = [
        'sight', 'radar_panel', 'radar_target', 'life_full', 'life_empty',
        'trans'
    ]
    sprites = {}
    sh = shader_uv_flat

    for fn in sprite_filenames:
        s = pi3d.ImageSprite('../media/bitmaps/' + fn + '.png',
                             shader=sh,
                             w=1,
                             h=1)
        sprites[fn] = s

    return sprites
예제 #12
0
def update_graph():
    global graph
    rrdtool.graph("/dev/shm/graph1.png", "--full-size-mode", "--font", "DEFAULT:13:", "--color", "BACK#ffffffC0", "--color", "CANVAS#ffffff00",
                  "--color", "SHADEA#ffffff00", "--color", "SHADEB#ffffff00", "--width", "800", "--height", "480",
                        #"--rigid", "--upper-limit" ,"40",
                        "--start","-2h", "--title","", "--vertical-label",'° C',
                        "DEF:act_temp=temperatures.rrd:act_temp:AVERAGE",
                        "DEF:heat=temperatures.rrd:heating:MAX",
                        "DEF:cool=temperatures.rrd:cooling:MAX",
                        "DEF:cpu=temperatures.rrd:cpu:AVERAGE",
                        "DEF:gpu=temperatures.rrd:gpu:AVERAGE",
                        "DEF:atmega=temperatures.rrd:atmega:AVERAGE",
                        "DEF:sht=temperatures.rrd:sht:AVERAGE",
                        "DEF:bmp280=temperatures.rrd:bmp280:AVERAGE",
                        "DEF:mlxamb=temperatures.rrd:mlxamb:AVERAGE",
                        "DEF:mlxobj=temperatures.rrd:mlxobj:AVERAGE",
                        "DEF:movement=temperatures.rrd:movement:MAX",
                        "CDEF:motion=movement,.5,+,FLOOR,INF,0,IF",
                        "CDEF:heating=heat,.5,+,FLOOR,1,-,UNKN,act_temp,IF",
                        "CDEF:cooling=cool,.5,+,FLOOR,1,-,UNKN,act_temp,IF",
                        #"LINE1:cpu#ff0000:CPU",
                        #"LINE1:gpu#ff0000:GPU",
                        #"LINE1:atmega#00ff00:AVR",
                        "LINE1:sht#d0d000:SHT",
                        #"LINE1:mlxamb#ff00ff:MLX_A",
                        "LINE1:mlxobj#00ffff:MLX",
                        "LINE1:bmp280#888800:BMP",
                        "AREA:act_temp#ffffcc",
                        "LINE2:act_temp#999999:Room",
                        "AREA:heating#ffcccc",
                        "LINE1:heating#ff5555:Heating",
                        "AREA:cooling#ccccff",
                        "LINE1:cooling#5555ff:Cooling",
                        "AREA:motion#00AA0070:Motion")

    graph = pi3d.ImageSprite('/dev/shm/graph1.png',
                             shader=graphics.SHADER, camera=graphics.CAMERA, w=800, h=480, z=1)
예제 #13
0
파일: rrdgraph.py 프로젝트: schit/mySHPI
def inloop(textchange=False, activity=False, offset=0):

    global graphupdated, graph

    if graphupdated < time.time():
        graphupdated = time.time() + 60
        activity = True
        rrdtool.graph(
            "/media/ramdisk/graph1.png", "--full-size-mode", "--font",
            "DEFAULT:13:", "--color", "BACK#ffffffC0", "--color",
            "CANVAS#ffffff00", "--color", "SHADEA#ffffff00", "--color",
            "SHADEB#ffffff00", "--width", "800", "--height", "480", "--start",
            "-1h", "--title", "temperature overview", "--vertical-label", "°C",
            "DEF:act_temp=temperatures.rrd:act_temp:AVERAGE",
            "DEF:cpu=temperatures.rrd:cpu:AVERAGE",
            "DEF:gpu=temperatures.rrd:gpu:AVERAGE",
            "DEF:atmega=temperatures.rrd:atmega:AVERAGE",
            "DEF:sht=temperatures.rrd:sht:AVERAGE",
            "DEF:bmp280=temperatures.rrd:bmp280:AVERAGE",
            "DEF:mlxamb=temperatures.rrd:mlxamb:AVERAGE",
            "DEF:mlxobj=temperatures.rrd:mlxobj:AVERAGE",
            "LINE4:act_temp#ff0000:ROOM", "LINE2:cpu#ff0000:CPU",
            "LINE2:gpu#ff0000:GPU", "LINE2:atmega#00ff00:AVR",
            "LINE2:sht#0000ff:SHT30", "LINE2:mlxamb#ff00ff:MLX_A",
            "LINE2:mlxobj#00ffff:MLX_O", "LINE2:bmp280#888800:BMP280")

        graph = pi3d.ImageSprite('/media/ramdisk/graph1.png',
                                 shader=graphics.SHADER,
                                 camera=graphics.CAMERA,
                                 w=800,
                                 h=480,
                                 z=1)
    if offset != 0:
        offset = graphics.slider_change(graph, offset)
    graph.draw()

    return activity, offset
예제 #14
0
 def __get_menu_bg_widget(self) -> "pi3d.util.Gui.Widget":
     """This widget lies between navigation areas and menu buttons.
     It intercepts clicks into the empty menu area which would otherwise trigger navigation.
     """
     array = np.zeros((1, 1, 4), dtype=np.uint8)
     texture = pi3d.Texture(array,
                            blend=True,
                            mipmap=False,
                            free_after_load=True)
     sprite = pi3d.ImageSprite(
         texture,
         self.__gui.shader,
         w=self.__viewer.display_width,
         h=self.__menu_height,
         x=0,
         y=0,
         z=4.0,
     )
     return pi3d.util.Gui.Widget(
         self.__gui,
         sprite,
         x=-self.__viewer.display_width // 2,
         y=self.__viewer.display_height // 2,
     )
예제 #15
0
 def getCache(self):
     filename = join(WHERE_AM_I, "loading.png")
     return pi3d.ImageSprite(filename, self.shader, w=256.0, h=256.0, z=5.0)
예제 #16
0
def init():
    global seplines, degwind, weathericon, text, line, baroneedle, windneedle, linemin, linemax, acttemp, text, error
    try:
        owm = pyowm.OWM(API_key=config.owmkey, language=config.owmlanguage)
        place = owm.weather_at_place(config.owmcity)
        weather = place.get_weather()

        text.text_blocks = []
        text._first_free_char = 0

        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(-220,
                              80,
                              0.1,
                              0.0,
                              30,
                              justify=0.5,
                              text_format=weather.get_detailed_status(),
                              size=0.3,
                              spacing="F",
                              space=0.05,
                              colour=(1.0, 1.0, 1.0, 1.0))
        text.add_text_block(city)

        acttemp = pi3d.TextBlock(
            -350,
            -50,
            0.1,
            0.0,
            10,
            text_format=str(weather.get_temperature(unit='celsius')['temp']) +
            u'°C',
            size=0.9,
            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=unichr(0xE041) + " %s:%02d" %
                                (sunriset.hour, sunriset.minute) + ' ' +
                                unichr(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=unichr(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=unichr(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=unichr(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)) + u'°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)) + u'°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)

    except:

        error = pi3d.TextBlock(-390,
                               180,
                               0.1,
                               0.0,
                               150,
                               text_format="OWM ERROR",
                               size=0.7,
                               spacing="F",
                               space=0.05,
                               colour=(1.0, 1.0, 1.0, 1.0))
        text.add_text_block(error)
        error = True
예제 #17
0
           lightcol=(0.8, 0.8, 0.8),
           lightamb=(0.30, 0.30, 0.32))

win = DISPLAY.tkwin

shader = pi3d.Shader('uv_bump')
mapshader = pi3d.Shader("uv_elev_map")
flatsh = pi3d.Shader('uv_flat')
matsh = pi3d.Shader('mat_light')
shade2d = pi3d.Shader('2d_flat')

#========================================
# create splash screen and draw it
splash = pi3d.ImageSprite("textures/tiger_splash.jpg",
                          shade2d,
                          w=10,
                          h=10,
                          z=0.2)
splash.draw()
DISPLAY.swap_buffers()

# create environment cube
ectex = pi3d.loadECfiles('textures/ecubes/Miramar',
                         'miramar_256',
                         suffix='png')
myecube = pi3d.EnvironmentCube(size=1800.0, maptype='FACES')
myecube.set_draw_details(flatsh, ectex)

# Create elevation map
mapwidth = 2000.0
mapdepth = 2000.0
예제 #18
0
                     lightcol=(0.8, 0.8, 0.8),
                     lightamb=(0.10, 0.10, 0.12))

win = DISPLAY.tkwin

shader = pi3d.Shader('shadow_uv_bump')
flatsh = pi3d.Shader('uv_flat')
shade2d = pi3d.Shader('2d_flat')

CAMERA = pi3d.Camera()

#========================================
# create splash screen and draw it
splash = pi3d.ImageSprite("textures/tiger_splash.jpg",
                          shade2d,
                          w=10,
                          h=10,
                          z=0.2)
splash.draw()
DISPLAY.swap_buffers()

# create environment cube
ectex = pi3d.loadECfiles('textures/ecubes/Miramar',
                         'miramar_256',
                         suffix='png')
myecube = pi3d.EnvironmentCube(size=1800.0, maptype='FACES')
myecube.set_draw_details(flatsh, ectex)

# Create elevation map
mapwidth = 1800.0
mapdepth = 1800.0
예제 #19
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()
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')

shape = []
shape.append((0, 0))

for x in range(0, 270):
예제 #20
0
def init():
    global snowline, rainline, seplines, degwind, weathericon, text, line
    global windneedle, acttemp, text, error
    #global baroneedle, linemin, linemax
    from pyowm.commons.enums import SubscriptionTypeEnum
    languagedict = {
        'subscription_type': SubscriptionTypeEnum.FREE,
        'language': config.OWMLANGUAGE,
        'connection': {
            'use_ssl': True,
            'verify_ssl_certs': True,
            'use_proxy': False,
            'timeout_secs': 5
        },
        'proxies': {
            'http': 'http://*****:*****@host:port',
            'https': 'socks5://user:pass@host:port'
        }
    }

    owm = pyowm.OWM(config.OWMKEY, config=languagedict)
    mgr = owm.weather_manager()
    place = mgr.weather_at_place(config.OWMCITY)
    weather = place.weather

    text.text_blocks = []
    text._first_free_char = 0

    if config.OWMLANGUAGE == 'de':  # TODO this needs untangling from stuff in config
        weekdays = [
            'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag',
            'Samstag', 'Sonntag'
        ]
    else:
        weekdays = [
            'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday',
            'sunday'
        ]

    file_path = resource_filename(
        "shpi", "sprites/{}.png".format(weather.weather_icon_name))
    if os.path.exists(file_path):
        weathericon = pi3d.ImageSprite(file_path,
                                       shader=graphics.SHADER,
                                       camera=graphics.CAMERA,
                                       w=150,
                                       h=150,
                                       z=2,
                                       x=-220)

    # else:
    #    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")
    city = pi3d.TextBlock(-390,
                          180,
                          0.1,
                          0.0,
                          150,
                          text_format=place.location.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(-220,
                          80,
                          0.1,
                          0.0,
                          30,
                          justify=0.5,
                          text_format=weather.detailed_status,
                          size=0.3,
                          spacing="F",
                          space=0.05,
                          colour=(1.0, 1.0, 1.0, 1.0))
    text.add_text_block(city)

    acttemp = pi3d.TextBlock(
        -350,
        -50,
        0.1,
        0.0,
        10,
        text_format=str(weather.temperature('celsius')['temp']) + u'°C',
        size=0.9,
        spacing="F",
        space=0.05,
        colour=(1.0, 1.0, 1.0, 1.0))
    text.add_text_block(acttemp)

    sunriset = weather.sunrise_time(timeformat='date') + datetime.timedelta(
        hours=2)
    sunsett = weather.sunset_time(timeformat='date') + datetime.timedelta(
        hours=2)
    sunset = pi3d.TextBlock(50,
                            100,
                            0.1,
                            0.0,
                            20,
                            text_format="{} {}:{:02d} {} {}:{:02d}".format(
                                unichr(0xE041), sunriset.hour, sunriset.minute,
                                unichr(0xE042), 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=unichr(0xE00B) + ' ' +
                               str(weather.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.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=unichr(0xE003) + ' ' +
                              str(weather.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.wind():
        wind = pi3d.TextBlock(50,
                              50,
                              0.1,
                              0.0,
                              10,
                              text_format=unichr(0xE040) + ' ' +
                              str(weather.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.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.wind()['deg'])
    else:
        degwind = False

    #fc = owm.three_hours_forecast(config.OWMCITY)
    f = mgr.forecast_at_place(config.OWMCITY, '3h').forecast

    step = 780 / (len(f))
    actualy = -400 + step
    temp_max = []
    temp_min = []
    temp = []
    seplinesarr = []
    icons = []
    rainarr = []
    snowarr = []
    maxdaytemp = -100
    mindaytemp = 100

    for weather in f:
        file_path = resource_filename(
            "shpi", "sprites/{}.png".format(weather.weather_icon_name))
        if not os.path.exists(file_path):
            import urllib.request  # TODO py2 py3 fix
            urllib.request.urlretrieve(
                "http://openweathermap.org/img/wn/" +
                weather.get_weather_icon_name() + "@2x.png", file_path)

        icons.append(
            pi3d.ImageSprite(file_path,
                             shader=graphics.SHADER,
                             camera=graphics.CAMERA,
                             w=20,
                             h=20,
                             z=1,
                             x=actualy,
                             y=-220))

        if weather.reference_time('iso')[11:16] == '00:00':
            seplinesarr.append([actualy, -50, 2])
            seplinesarr.append([actualy, 50, 2])
            seplinesarr.append([actualy, -50, 2])

            # if weather.get_reference_time('iso')[11:16] == '12:00':
            day = weather.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)) +
                                      u'°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)) +
                                      u'°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.snow:
            snowarr.append([actualy, (-50 + weather.snow['3h'] * 30), 2])
        else:
            snowarr.append([actualy, -50, 2])

        if '3h' in weather.rain:
            rainarr.append([actualy, (-50 + weather.rain['3h'] * 30), 2])
        else:
            rainarr.append([actualy, -50, 2])

        temperatures = weather.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

    snowline = pi3d.Lines(vertices=snowarr, line_width=3, y=-180, strip=True)
    snowline.set_shader(graphics.MATSH)
    snowline.set_material((0.5, 0.5, 1))
    snowline.set_alpha(0.7)

    rainline = pi3d.Lines(vertices=rainarr, line_width=3, y=-180, strip=True)
    rainline.set_shader(graphics.MATSH)
    rainline.set_material((0, 0, 1))
    rainline.set_alpha(0.7)

    seplines = pi3d.Lines(vertices=seplinesarr,
                          line_width=1,
                          y=-180,
                          strip=True)
    seplines.set_shader(graphics.MATSH)
    seplines.set_material((0, 0, 0))
    seplines.set_alpha(0.9)

    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)
예제 #21
0
def weather_obj_create(width, height):
    icon_shader = pi3d.Shader("uv_flat")
    weatherobj = {}

    # This screen is optimized for a display size of FullHD 1920 x 1080
    # So the ranges are ==> x +/-960 ; y +/-540
    # You might need to adjust for other display dimensions
    y_top = height * 0.5 - cfg['W_MARGIN_TOP']
    x_sunrise = -width * 0.5 + cfg['W_POINT_SIZE'] * 10
    x_sunset = x_sunrise + cfg['W_STATIC_SIZE'] * 3
    x_uvi = x_sunset + cfg['W_STATIC_SIZE'] * 3.5
    x_cases7 = x_uvi + cfg['W_STATIC_SIZE'] * 5
    weatherobj['static'] = {}
    weatherobj['static']['sunrise'] = pi3d.ImageSprite(os.path.join(
        cfg['W_ICON_DIR'], 'sunrise.png'),
                                                       icon_shader,
                                                       w=cfg['W_STATIC_SIZE'],
                                                       h=cfg['W_STATIC_SIZE'],
                                                       x=x_sunrise,
                                                       y=y_top,
                                                       z=1.0)
    weatherobj['static']['sunset'] = pi3d.ImageSprite(os.path.join(
        cfg['W_ICON_DIR'], 'sunset.png'),
                                                      icon_shader,
                                                      w=cfg['W_STATIC_SIZE'],
                                                      h=cfg['W_STATIC_SIZE'],
                                                      x=x_sunset,
                                                      y=y_top,
                                                      z=1.0)
    weatherobj['static']['uvidx'] = pi3d.ImageSprite(os.path.join(
        cfg['W_ICON_DIR'], 'uvidx.png'),
                                                     icon_shader,
                                                     w=cfg['W_STATIC_SIZE'],
                                                     h=cfg['W_STATIC_SIZE'],
                                                     x=x_uvi,
                                                     y=y_top,
                                                     z=1.0)
    weatherobj['static']['corona'] = pi3d.ImageSprite(os.path.join(
        cfg['W_ICON_DIR'], 'corona_g.png'),
                                                      icon_shader,
                                                      w=cfg['W_STATIC_SIZE'],
                                                      h=cfg['W_STATIC_SIZE'],
                                                      x=x_cases7,
                                                      y=y_top,
                                                      z=1.0)
    weatherobj['static']['hospitalization'] = pi3d.ImageSprite(
        os.path.join(cfg['W_ICON_DIR'], 'hospitalization_g.png'),
        icon_shader,
        w=cfg['W_STATIC_SIZE'] * 0.7,
        h=cfg['W_STATIC_SIZE'] * 0.7,
        x=x_cases7,
        y=y_top - cfg['W_STATIC_SIZE'],
        z=1.0)

    x = -width * 0.5 + cfg['W_MARGIN_LEFT'] + cfg['W_STATIC_SIZE'] * 0.5
    x_dt = -width * 0.5 + cfg['W_MARGIN_LEFT']
    y_date = y_top - cfg['W_STATIC_SIZE'] * 2.5  #1.5
    y_icon = y_date - cfg['W_ICON_SIZE'] * 0.9
    y_temp = 0 - cfg['W_STATIC_SIZE'] * 1.1  #0
    y_pop = y_temp - cfg['W_STATIC_SIZE'] * 1.5
    y_wind = y_pop - cfg['W_STATIC_SIZE'] * 1.1
    y_humidity = y_wind - cfg['W_STATIC_SIZE'] * 1.1
    y_pressure = y_humidity - cfg['W_STATIC_SIZE'] * 1.1

    weatherobj['static']['temp'] = pi3d.ImageSprite(
        os.path.join(cfg['W_ICON_DIR'], 'temp.png'),
        icon_shader,
        w=cfg['W_STATIC_SIZE'] * 1.5,
        h=cfg['W_STATIC_SIZE'] * 1.5,
        x=x,
        y=y_temp,
        z=1.0)
    weatherobj['static']['pop'] = pi3d.ImageSprite(os.path.join(
        cfg['W_ICON_DIR'], 'rainprop.png'),
                                                   icon_shader,
                                                   w=cfg['W_STATIC_SIZE'],
                                                   h=cfg['W_STATIC_SIZE'],
                                                   x=x,
                                                   y=y_pop,
                                                   z=1.0)
    weatherobj['static']['wind'] = pi3d.ImageSprite(os.path.join(
        cfg['W_ICON_DIR'], 'wind.png'),
                                                    icon_shader,
                                                    w=cfg['W_STATIC_SIZE'],
                                                    h=cfg['W_STATIC_SIZE'],
                                                    x=x,
                                                    y=y_wind,
                                                    z=1.0)
    weatherobj['static']['humidity'] = pi3d.ImageSprite(os.path.join(
        cfg['W_ICON_DIR'], 'humidity.png'),
                                                        icon_shader,
                                                        w=cfg['W_STATIC_SIZE'],
                                                        h=cfg['W_STATIC_SIZE'],
                                                        x=x,
                                                        y=y_humidity,
                                                        z=1.0)
    weatherobj['static']['pressure'] = pi3d.ImageSprite(os.path.join(
        cfg['W_ICON_DIR'], 'pressure.png'),
                                                        icon_shader,
                                                        w=cfg['W_STATIC_SIZE'],
                                                        h=cfg['W_STATIC_SIZE'],
                                                        x=x,
                                                        y=y_pressure,
                                                        z=1.0)

    weatherobj['current'] = {}
    weatherobj['current']['dt'] = pi3d.TextBlock(x=x_dt,
                                                 y=y_top,
                                                 text_format=" ",
                                                 z=0.0,
                                                 rot=0.0,
                                                 char_count=20,
                                                 size=0.99,
                                                 spacing="F",
                                                 space=0.0,
                                                 colour=(1.0, 1.0, 1.0, 1.0))
    weatherobj['current']['sunrise'] = pi3d.TextBlock(
        x=x_sunrise + cfg['W_STATIC_SIZE'] * 0.7,
        y=y_top,
        text_format=" ",
        z=0.0,
        rot=0.0,
        char_count=10,
        size=0.6,
        spacing="F",
        space=0.0,
        colour=(1.0, 1.0, 1.0, 1.0))
    weatherobj['current']['sunset'] = pi3d.TextBlock(
        x=x_sunset + cfg['W_STATIC_SIZE'] * 0.7,
        y=y_top,
        text_format=" ",
        z=0.0,
        rot=0.0,
        char_count=10,
        size=0.6,
        spacing="F",
        space=0.0,
        colour=(1.0, 1.0, 1.0, 1.0))
    weatherobj['current']['uvi'] = pi3d.TextBlock(x=x_uvi +
                                                  cfg['W_STATIC_SIZE'] * 0.7,
                                                  y=y_top,
                                                  text_format=" ",
                                                  z=0.0,
                                                  rot=0.0,
                                                  char_count=20,
                                                  size=0.6,
                                                  spacing="F",
                                                  space=0.0,
                                                  colour=(1.0, 1.0, 1.0, 1.0))
    weatherobj['current']['cases7_per_100k'] = pi3d.TextBlock(
        x=x_cases7 + cfg['W_STATIC_SIZE'] * 0.7,
        y=y_top,
        text_format=" ",
        z=0.0,
        rot=0.0,
        char_count=20,
        size=0.99,
        spacing="F",
        space=0.0,
        colour=(1.0, 1.0, 1.0, 1.0))
    weatherobj['current']['hospitalization_idx'] = pi3d.TextBlock(
        x=x_cases7 + cfg['W_STATIC_SIZE'] * 0.7,
        y=y_top - cfg['W_STATIC_SIZE'],
        text_format=" ",
        z=0.0,
        rot=0.0,
        char_count=20,
        size=0.99,
        spacing="F",
        space=0.0,
        colour=(1.0, 1.0, 1.0, 1.0))

    w_item_cnt = int((width - cfg['W_MARGIN_LEFT']) /
                     (cfg['W_ICON_SIZE'] + cfg['W_SPACING']))
    weatherobj['forecast'] = []
    for i in range(w_item_cnt):
        item = {}
        x = -width * 0.5 + cfg['W_MARGIN_LEFT'] + 2 * cfg[
            'W_STATIC_SIZE'] + i * (cfg['W_ICON_SIZE'] + cfg['W_SPACING'])
        item['date'] = pi3d.TextBlock(x=x,
                                      y=y_date,
                                      text_format=" ",
                                      z=0.1,
                                      rot=0.0,
                                      char_count=20,
                                      size=0.8,
                                      spacing="F",
                                      space=0.0,
                                      colour=(1.0, 1.0, 1.0, 1.0))
        item['daytime'] = pi3d.TextBlock(x=x,
                                         y=y_date - cfg['W_STATIC_SIZE'] * 0.7,
                                         text_format=" ",
                                         z=0.1,
                                         rot=0.0,
                                         char_count=15,
                                         size=0.6,
                                         spacing="F",
                                         space=0.0,
                                         colour=(1.0, 1.0, 1.0, 1.0))
        item['temp'] = pi3d.TextBlock(x=x,
                                      y=y_temp + cfg['W_STATIC_SIZE'] * 0.4,
                                      text_format=" ",
                                      z=0.1,
                                      rot=0.0,
                                      char_count=10,
                                      size=0.99,
                                      spacing="F",
                                      space=0.0,
                                      colour=(1.0, 1.0, 1.0, 1.0))
        item['feels_like'] = pi3d.TextBlock(x=x,
                                            y=y_temp -
                                            cfg['W_STATIC_SIZE'] * 0.4,
                                            text_format=" ",
                                            z=0.1,
                                            rot=0.0,
                                            char_count=10,
                                            size=0.6,
                                            spacing="F",
                                            space=0.0,
                                            colour=(1.0, 1.0, 1.0, 1.0))
        item['pop'] = pi3d.TextBlock(x=x,
                                     y=y_pop,
                                     text_format=" ",
                                     z=0.1,
                                     rot=0.0,
                                     char_count=10,
                                     size=0.6,
                                     spacing="F",
                                     space=0.0,
                                     colour=(1.0, 1.0, 1.0, 1.0))
        item['wind'] = pi3d.TextBlock(x=x,
                                      y=y_wind,
                                      text_format=" ",
                                      z=0.1,
                                      rot=0.0,
                                      char_count=10,
                                      size=0.6,
                                      spacing="F",
                                      space=0.0,
                                      colour=(1.0, 1.0, 1.0, 1.0))
        item['humidity'] = pi3d.TextBlock(x=x,
                                          y=y_humidity,
                                          text_format=" ",
                                          z=0.1,
                                          rot=0.0,
                                          char_count=10,
                                          size=0.6,
                                          spacing="F",
                                          space=0.0,
                                          colour=(1.0, 1.0, 1.0, 1.0))
        item['pressure'] = pi3d.TextBlock(x=x,
                                          y=y_pressure,
                                          text_format=" ",
                                          z=0.1,
                                          rot=0.0,
                                          char_count=10,
                                          size=0.6,
                                          spacing="F",
                                          space=0.0,
                                          colour=(1.0, 1.0, 1.0, 1.0))

        item['icon'] = pi3d.ImageSprite(os.path.join(cfg['W_ICON_DIR'],
                                                     '01d.png'),
                                        icon_shader,
                                        w=cfg['W_ICON_SIZE'],
                                        h=cfg['W_ICON_SIZE'],
                                        x=x + cfg['W_ICON_SIZE'] * 0.5,
                                        y=y_icon,
                                        z=1.0)
        weatherobj['forecast'].append(item)
    return weatherobj
예제 #22
0
import sys
import os

import pi3d


sys.path.insert(1, os.path.join(sys.path[0], '..'))


text5 = pi3d.PointText(graphics.pointFont, graphics.CAMERA,
                       max_chars=20, point_size=64)  # slider5 Ammeter
currents = pi3d.TextBlock(-350, 100, 0.1, 0.0, 15, data_obj=peripherals.eg_object, attr="relais1current", text_format="{:2.1f}A", size=0.99, spacing="F",
                          space=0.05, colour=(1.0, 1.0, 1.0, 1.0))
text5.add_text_block(currents)

amperemeter = pi3d.ImageSprite(config.installpath + 'sprites/amperemeter.png',
                               shader=graphics.SHADER, camera=graphics.CAMERA, w=400, h=400, x=0, y=0, z=2.0)
ampereneedle = pi3d.Lines(camera=graphics.CAMERA, vertices=(
    (0, 0, 0), (0, 160, 0)), material=(1.0, 0.3, 0.0), line_width=5, x=0.0, y=-70.0, z=1.0)
ampereneedle.set_shader(graphics.MATSH)


def inloop(textchange=False, activity=False, offset=0):

    if offset != 0:
        offset = graphics.slider_change(amperemeter, offset)
    else:
        ampereneedle.rotateToZ(
            50 - (peripherals.eg_object.relais1current * 20))
        ampereneedle.draw()

    amperemeter.draw()
            (0, x), int(255 * (1 - gradient_magnitude * float(x) / size)))
        gradient.putpixel(
            (1, x), int(255 * (1 - gradient_magnitude * float(x) / size)))
    #alpha = gradient.resize(im.size)
    black_im = Image.new('RGBA', (2, size), color=0)  # i.e. black
    black_im.putalpha(gradient)
    return black_im


tex = pi3d.Texture(blackgradient())
rect = pi3d.Sprite(camera=graphics.CAMERA, x=300, y=0, w=100, h=440, z=0.2)
rect.set_material((1.0, 1.0, 1.0))
sprite = pi3d.ImageSprite(tex,
                          graphics.SHADER,
                          x=300,
                          y=0,
                          w=100.0,
                          h=440.0,
                          z=0.1)

imgsize = (32, 32)  #The size of the image
image = Image.new('RGB', imgsize)  #Create the image

convertRadiansToDegrees = 180.0 / 3.14159265359

for y in range(imgsize[1]):

    for x in range(imgsize[0]):

        x1 = (x - imgsize[0] / 2)
        y1 = (imgsize[1] / 2 - y)
hog = np.zeros((16, 128, 3), dtype=np.uint8)
hidden = np.zeros((8, 8, 3), dtype=np.uint8)

########################################################################
DISPLAY = pi3d.Display.create(x=100, y=100, background=(0.1, 0.1, 0.1, 0.9))
CAM = pi3d.Camera()
shader = pi3d.Shader('uv_flat')
lgtshd = pi3d.Shader('mat_light')
pi3d.opengles.glDisable(pi3d.GL_CULL_FACE)

grey_tex = pi3d.Texture(grey, mipmap=False)
sobel_tex = pi3d.Texture(sobel, mipmap=False)
hog_tex = pi3d.Texture(hog, mipmap=False)
hidden_tex = pi3d.Texture(hidden, mipmap=True)

grey_sprite = pi3d.ImageSprite(grey_tex, shader, w=2.5, h=2.5, x=-1.2, y=1.0, z=10.0)
sobel_sprite = pi3d.ImageSprite(sobel_tex, shader, w=2.5, h=2.5, x=-0.0, y=0.5, z=8.0)
hog_sprite = pi3d.ImageSprite(hog_tex, shader, w=2.5, h=2.5, x=1.0, y=0.0, z=6.0)
hidden_sprite = pi3d.ImageSprite(hidden_tex, shader, w=2.0, h=2.0, x=1.4, y=-0.5, z=4.0)

sobel_sprite.set_alpha(0.85)
hog_sprite.set_alpha(0.85)
hidden_sprite.set_alpha(0.85)

font = pi3d.Font('fonts/FreeSans.ttf', (150, 150, 150, 255))
str_list = [pi3d.String(font=font, string='1.Border Terrier', x=-1.0, y=1.0, z=3.0),
            pi3d.String(font=font, string='2.Flat Cap', x=-1.0, y=0.5, z=3.0),
            pi3d.String(font=font, string='3.Labrador', x=-1.0, y=0.0, z=3.0),
            pi3d.String(font=font, string='4.Top Hat', x=-1.0, y=-0.5, z=3.0),
            pi3d.String(font=font, string='5.Whippet', x=-1.0, y=-1.0, z=3.0)]
for st in str_list:
예제 #25
0
 def __init__(self):
     wd = DISPLAY.width
     ht = DISPLAY.height
     asi_tex = pi3d.Texture("textures/airspeed_indicator.png")
     alt_tex = pi3d.Texture("textures/altimeter.png")
     rad_tex = pi3d.Texture("textures/radar.png")
     dot_tex = pi3d.Texture("textures/radar_dot.png")
     ndl_tex = pi3d.Texture("textures/instrument_needle.png")
     self.asi = pi3d.ImageSprite(asi_tex,
                                 FLATSH,
                                 camera=CAMERA2D,
                                 w=128,
                                 h=128,
                                 x=-128,
                                 y=-ht / 2 + 64,
                                 z=2)
     self.alt = pi3d.ImageSprite(alt_tex,
                                 FLATSH,
                                 camera=CAMERA2D,
                                 w=128,
                                 h=128,
                                 x=0,
                                 y=-ht / 2 + 64,
                                 z=2)
     self.rad = pi3d.ImageSprite(rad_tex,
                                 FLATSH,
                                 camera=CAMERA2D,
                                 w=128,
                                 h=128,
                                 x=128,
                                 y=-ht / 2 + 64,
                                 z=2)
     self.dot = pi3d.ImageSprite(dot_tex,
                                 FLATSH,
                                 camera=CAMERA2D,
                                 w=16,
                                 h=16,
                                 z=1)
     self.ndl1 = pi3d.ImageSprite(ndl_tex,
                                  FLATSH,
                                  camera=CAMERA2D,
                                  w=128,
                                  h=128,
                                  x=-128,
                                  y=-ht / 2 + 64,
                                  z=1)
     self.ndl2 = pi3d.ImageSprite(ndl_tex,
                                  FLATSH,
                                  camera=CAMERA2D,
                                  w=128,
                                  h=128,
                                  x=0,
                                  y=-ht / 2 + 64,
                                  z=1)
     self.ndl3 = pi3d.ImageSprite(ndl_tex,
                                  FLATSH,
                                  camera=CAMERA2D,
                                  w=128,
                                  h=128,
                                  x=128,
                                  y=-ht / 2 + 64,
                                  z=1)
     self.dot_list = []
     self.update_time = 0.0
예제 #26
0
파일: ui.py 프로젝트: danpillay87/foosball
    def __setup_sprites(self):
        flat = pi3d.Shader("uv_flat")

        bg = pi3d.Sprite(w=1920, h=1080, z=100)
        bg.set_shader(flat)
        self.bg = Flashing(
            ChangingTextures(bg, self.__get_bg_textures(),
                             self.bg_change_interval))

        logger.info("Loading other images")
        logo_d = (80, 80)
        self.logo = pi3d.ImageSprite(load_icon(
            "icons/logo.png", fallback="icons/logo_fallback.png"),
                                     flat,
                                     w=logo_d[0],
                                     h=logo_d[1],
                                     x=(1920 - logo_d[0]) / 2 - 40,
                                     y=(-1080 + logo_d[1]) / 2 + 40,
                                     z=50)
        self.people = Disappear(pi3d.ImageSprite(
            load_icon("icons/people.png"),
            flat,
            w=logo_d[0],
            h=logo_d[1],
            x=(1920 - logo_d[0]) / 2 - 40 - logo_d[0] - 20,
            y=(-1080 + logo_d[1]) / 2 + 40,
            z=50),
                                duration=config.md_ev_interval + 1,
                                fade=0.5)

        in_d = (512 * 0.75, 185 * 0.75)
        self.instructions = pi3d.ImageSprite(
            load_icon("icons/instructions.png"),
            flat,
            w=in_d[0],
            h=in_d[1],
            x=(-1920 + in_d[0]) / 2 + 40,
            y=(-1080 + in_d[1]) / 2 + 40,
            z=50)
        self.instructions = LazyTrigger(
            Disappear(self.instructions, duration=5))

        logger.info("Loading font")
        printable_cps = list(
            itertools.chain(
                range(ord(' '), ord('~')), range(161, 255),
                [ord("○"), ord("●"),
                 ord("◌"), ord("◉"),
                 ord('Ω')]))
        fontfile = img("UbuntuMono-B_circle.ttf")
        font = OutlineFont(fontfile,
                           font_size=80,
                           image_size=1024,
                           outline_size=2,
                           codepoints=printable_cps,
                           mipmap=False,
                           filter=GL_LINEAR)
        self.goal_time = ChangingText(flat,
                                      font=font,
                                      string=self.__get_time_since_last_goal(),
                                      is_3d=False,
                                      justify='C',
                                      x=0,
                                      y=-450,
                                      z=50)

        self.game_mode_ui = ChangingText(flat,
                                         font=font,
                                         string=self.__get_mode_string(None),
                                         is_3d=False,
                                         justify='R',
                                         x=920,
                                         y=480,
                                         z=50)

        self.feedback = KeysFeedback(flat)

        s = 512
        self.yCounter = Move(Counter(0, flat, (10, 7, 0), w=s, h=s, z=50))
        self.bCounter = Move(Counter(0, flat, (0, 0, 0), w=s, h=s, z=50))
        playerfont = OutlineFont(fontfile,
                                 font_size=50,
                                 image_size=768,
                                 outline_size=2,
                                 codepoints=printable_cps,
                                 mipmap=False,
                                 filter=GL_LINEAR)
        self.yPlayers = Multiline(flat,
                                  font=playerfont,
                                  string=self.getPlayers(left=True),
                                  x=-380,
                                  y=-250,
                                  z=50,
                                  justify='C')
        self.bPlayers = Multiline(flat,
                                  font=playerfont,
                                  string=self.getPlayers(left=False),
                                  x=380,
                                  y=-250,
                                  z=50,
                                  justify='C')

        menufont = OutlineFont(fontfile, (255, 255, 255, 255),
                               font_size=50,
                               image_size=768,
                               codepoints=printable_cps,
                               mipmap=False,
                               filter=GL_LINEAR)
        arrow = load_icon("icons/arrow.png")
        menu = Menu(menufont, arrow, wchar=60, n=12, z=10)
        self.menu = MenuTree(self.main_menu, menu, rootTitle="Game mode")

        self.ledShapes = {
            "YD":
            pi3d.shape.Disk.Disk(radius=20,
                                 sides=12,
                                 x=-100,
                                 y=-430,
                                 z=0,
                                 rx=90),
            "YI":
            pi3d.shape.Disk.Disk(radius=20,
                                 sides=12,
                                 x=-100,
                                 y=-370,
                                 z=0,
                                 rx=90),
            "OK":
            pi3d.shape.Disk.Disk(radius=50, sides=12, x=0, y=-400, z=0, rx=90),
            "BD":
            pi3d.shape.Disk.Disk(radius=20,
                                 sides=12,
                                 x=100,
                                 y=-430,
                                 z=0,
                                 rx=90),
            "BI":
            pi3d.shape.Disk.Disk(radius=20,
                                 sides=12,
                                 x=100,
                                 y=-370,
                                 z=0,
                                 rx=90),
        }
        red = (10, 0, 0, 0)
        green = (0, 10, 0, 0)
        self.blackColor = (0, 0, 0, 0)
        self.ledColors = {
            "YD": red,
            "YI": green,
            "OK": green,
            "BD": red,
            "BI": green
        }
        self.leds = []

        self.winner = WinnerString(flat)
        # move immediately to position
        self.__move_sprites()
예제 #27
0
                        background=(0.4, 0.8, 0.8, 1), frames_per_second=16)

#inputs = InputEvents()
#inputs.get_mouse_movement()

pi3d.Light(lightpos=(-1, -1, 1), lightcol =(0.8, 0.8, 0.8), lightamb=(0.30, 0.30, 0.32))

win = DISPLAY.tkwin

shader = pi3d.Shader('uv_bump')
flatsh = pi3d.Shader('uv_flat')
shade2d = pi3d.Shader('2d_flat')

#========================================
# create splash screen and draw it
splash = pi3d.ImageSprite("textures/tiger_splash.jpg", shade2d, w=10, h=10, z=0.2)
splash.draw()
DISPLAY.swap_buffers()

# create environment cube
ectex = pi3d.loadECfiles('textures/ecubes/Miramar', 'miramar_256',
                                    suffix='png')
myecube = pi3d.EnvironmentCube(size=1800.0, maptype='FACES')
myecube.set_draw_details(flatsh, ectex)

# Create elevation map
mapwidth = 2000.0
mapdepth = 2000.0
mapheight = 100.0
mountimg1 = pi3d.Texture('textures/mountains3_512.jpg')
bumpimg = pi3d.Texture('textures/grasstile_n.jpg')
예제 #28
0
#!/usr/bin/python
from __future__ import absolute_import, division, print_function, unicode_literals

""" Example showing what can be left out. ESC to quit"""
import demo
import 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("textures/PATRN.PNG", shader, w=100.0, h=100.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
  
  if mykeys.read() == 27:
예제 #29
0
#Create a Tkinter window in Display
winw,winh = 800, 600   	#64MB GPU memory setting
#winw,winh = 1920,1180	#128MB GPU memory setting

DISPLAY = pi3d.Display.create(tk=True, window_title='ConferenceHall demo in Pi3D',
                        w=winw, h=winh, far=2200.0, fov = 60,
                        background=(0.4, 0.8, 0.8, 1), frames_per_second=20)
win = DISPLAY.tkwin

#Setup shaders
flatsh = pi3d.Shader("shaders/uv_flat")
shade2d = pi3d.Shader('shaders/2d_flat')

# create splash screen and draw it
splash = pi3d.ImageSprite("textures/pi3d_splash.jpg", shade2d, w=10, h=10, z=0.2)
splash.draw()
DISPLAY.swap_buffers()

#Setup environment cube
ectex = pi3d.loadECfiles("textures/ecubes/Miramar", "miramar_256", "png", nobottom = True)
myecube = pi3d.EnvironmentCube(size=1800.0, maptype="FACES", nobottom=True)
myecube.set_draw_details(flatsh, ectex)

#Load Hall model
hall = pi3d.Model(file_string="models/ConferenceHall/conferencehall.egg", name="Hall", sx=0.1, sy=0.1, sz=0.1)
hall.set_shader(flatsh)

#key presses
mymouse = pi3d.Mouse(restrict = False)
mymouse.start()
예제 #30
0
BACKGROUND = (0.0, 0.0, 0.0, 0.0)

# Setup display and initialise pi3d and a shader.
DISPLAY = pi3d.Display.create(background=BACKGROUND)
SHADER = pi3d.Shader('shaders/uv_flat')

TEXTURE = pi3d.Texture('textures/Raspi256x256.png')
BERRY_COUNT = 15

# Setup array of random x,y,z coords and initial rotation
RASPBERRIES = []

for b in range(BERRY_COUNT):
    # Select size as a random number 0.2 and 2.5.
    size = random.uniform(0.5, 2.5)
    rasp = pi3d.ImageSprite(texture=TEXTURE, shader=SHADER, w=size, h=size)

    # distance from the camera.
    dist = random.uniform(2.0, 10.0)
    rasp.position(
        random.uniform(-1.0, 1.0) * dist,
        random.uniform(0.0, 4.0) * dist, dist)
    rasp.rotateToZ(random.uniform(0.0, 360.0))

    RASPBERRIES.append(rasp)
    DISPLAY.add_sprites(rasp)

# Fetch key presses
KEYBOARD = pi3d.Keyboard()

while DISPLAY.loop_running():