当前位置: 首页>>代码示例>>Python>>正文


Python buffer_utils.BufferUtils类代码示例

本文整理汇总了Python中lib.buffer_utils.BufferUtils的典型用法代码示例。如果您正苦于以下问题:Python BufferUtils类的具体用法?Python BufferUtils怎么用?Python BufferUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BufferUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render_command_list

    def render_command_list(self, list, buffer):
        """
        Renders the output of a command list to the output buffer.
        Commands are rendered in FIFO overlap style.  Run the list through
        filter_and_sort_commands() beforehand.
        If the output buffer is not zero (black) at a command's target,
        the output will be additively blended according to the blend_state
        (0.0 = 100% original, 1.0 = 100% new)
        """
        for command in list:
            color = command.get_color()
            if isinstance(command, SetAll):
                buffer[:,:] = color

            elif isinstance(command, SetStrand):
                strand = command.get_strand()
                start, end = BufferUtils.get_strand_extents(strand)
                buffer[start:end] = color

            elif isinstance(command, SetFixture):
                pass
                # strand = command.get_strand()
                # fixture = command.get_address()
                # start = BufferUtils.logical_to_index((strand, fixture, 0))
                # end = start + self._scene.fixture(strand, fixture).pixels
                # buffer[start:end] = color

            elif isinstance(command, SetPixel):
                strand = command.get_strand()
                fixture = command.get_address()
                offset = command.get_pixel()
                pixel = BufferUtils.logical_to_index((strand, fixture, offset))
                buffer[pixel] = color
开发者ID:tibbon,项目名称:firemix,代码行数:33,代码来源:mixer.py

示例2: __init__

    def __init__(self, app, name):
        super(Layer, self).__init__()
        self._app = app
        self._mixer = app.mixer
        self._enable_profiling = self._app.args.profile
        self.name = name
        self._playlist = None
        self._scene = app.scene
        self._main_buffer = None
        self._secondary_buffer = None
        self._in_transition = False
        self._transition = None
        self.transition_progress = 0.0
        self._start_transition = False
        self._transition_list = []
        self._transition_duration = self._app.settings.get('mixer')['transition-duration']
        self._transition_slop = self._app.settings.get('mixer')['transition-slop']
        self._elapsed = 0
        self._duration = self._app.settings.get('mixer')['preset-duration']

        # Load transitions
        self.set_transition_mode(self._app.settings.get('mixer')['transition'])

        if not self._scene:
            pass
        else:
            self._main_buffer = BufferUtils.create_buffer()
            self._secondary_buffer = BufferUtils.create_buffer()
开发者ID:ikea-lisp-code,项目名称:firemix,代码行数:28,代码来源:layer.py

示例3: render_command_list

    def render_command_list(self, list, buffer):
        """
        Renders the output of a command list to the output buffer.
        Commands are rendered in FIFO overlap style.  Run the list through
        filter_and_sort_commands() beforehand.
        If the output buffer is not zero (black) at a command's target,
        the output will be additively blended according to the blend_state
        (0.0 = 100% original, 1.0 = 100% new)
        """
        for command in list:
            color = command.get_color()
            if isinstance(command, SetAll):
                buffer[:,:] = color

            elif isinstance(command, SetStrand):
                strand = command.get_strand()
                buffer[strand,:] = color

            elif isinstance(command, SetFixture):
                strand = command.get_strand()
                address = command.get_address()
                _, start = BufferUtils.get_buffer_address(self._app, (strand, address, 0))
                end = start + self._scene.fixture(strand, address).pixels
                buffer[strand,start:end] = color

            elif isinstance(command, SetPixel):
                strand = command.get_strand()
                address = command.get_address()
                pixel = command.get_pixel()
                (strand, pixel_offset) = BufferUtils.get_buffer_address(self._app, (strand, address, pixel))
                buffer[strand][pixel_offset] = color
开发者ID:underwatercolor,项目名称:firemix,代码行数:31,代码来源:mixer.py

示例4: get_pixel_neighbors

    def get_pixel_neighbors(self, index):
        """
        Returns a list of pixel addresses that are adjacent to the given address.
        """

        neighbors = self._pixel_neighbors_cache.get(index, None)

        if neighbors is None:
            neighbors = []
            strand, address, pixel = BufferUtils.index_to_logical(index)
            f = self.fixture(strand, address)
            neighbors = [BufferUtils.logical_to_index((strand, address, p)) for p in f.pixel_neighbors(pixel)]

            if (pixel == 0) or (pixel == f.pixels - 1):
                # If this pixel is on the end of a fixture, consider the neighboring fixtures
                loc = 'end'
                if pixel == 0:
                    loc = 'start'

                logical_neighbors = self.get_colliding_fixtures(strand, address, loc)
                neighbors += [BufferUtils.logical_to_index(n) for n in logical_neighbors]

            self._pixel_neighbors_cache[index] = neighbors

        return neighbors
开发者ID:tobywaite,项目名称:firemix,代码行数:25,代码来源:scene.py

示例5: __init__

    def __init__(self, app):
        super(Mixer, self).__init__()
        self._app = app
        self._net = app.net
        self._playlist = None
        self._scene = app.scene
        self._tick_rate = self._app.settings.get('mixer')['tick-rate']
        self._in_transition = False
        self._start_transition = False
        self._transition_duration = self._app.settings.get('mixer')['transition-duration']
        self._transition_slop = self._app.settings.get('mixer')['transition-slop']
        self._tick_timer = None
        self._duration = self._app.settings.get('mixer')['preset-duration']
        self._elapsed = 0.0
        self._running = False
        self._enable_rendering = True
        self._main_buffer = None
        self._max_fixtures = 0
        self._max_pixels = 0
        self._tick_time_data = dict()
        self._num_frames = 0
        self._last_frame_time = 0.0
        self._start_time = 0.0
        self._stop_time = 0.0
        self._strand_keys = list()
        self._enable_profiling = self._app.args.profile
        self._paused = self._app.settings.get('mixer').get('paused', False)
        self._frozen = False
        self._random_transition = False
        self._last_onset_time = 0.0
        self._onset_holdoff = self._app.settings.get('mixer')['onset-holdoff']
        self._onset = False
        self._reset_onset = False
        self._global_dimmer = 1.0
        self._global_speed = 1.0
        self._render_in_progress = False

        # Load transitions
        self.set_transition_mode(self._app.settings.get('mixer')['transition'])

        if not self._scene:
            log.warn("No scene assigned to mixer.  Preset rendering and transitions are disabled.")
            self._transition_duration = 0.0
            self._enable_rendering = False
        else:
            log.info("Initializing preset rendering buffer")
            fh = self._scene.fixture_hierarchy()
            for strand in fh:
                self._strand_keys.append(strand)

            (maxs, maxf, maxp) = self._scene.get_matrix_extents()

            self._main_buffer = BufferUtils.create_buffer(self._app)
            self._secondary_buffer = BufferUtils.create_buffer(self._app)
            self._max_fixtures = maxf
            self._max_pixels = maxp

            log.info("Warming up BufferUtils cache...")
            BufferUtils.warmup(self._app)
            log.info("Completed BufferUtils cache warmup")
开发者ID:bhitov,项目名称:firemix,代码行数:60,代码来源:mixer.py

示例6: setup

 def setup(self):
     self.add_parameter(StringParameter('first-preset', ""))
     self.add_parameter(StringParameter('second-preset', ""))
     self.add_parameter(FloatParameter('transition-progress', 0.5))
     self.add_parameter(FloatParameter('audio-transition', 0.0))
     self.add_parameter(StringParameter('transition-mode', "Additive Blend"))
     self._preset1_buffer = BufferUtils.create_buffer()
     self._preset2_buffer = BufferUtils.create_buffer()
开发者ID:tibbon,项目名称:firemix,代码行数:8,代码来源:combine.py

示例7: setup

    def setup(self):
        self.x, self.y = BufferUtils.get_buffer_size(self._app)

        self.pixel_locations = self._app.scene.get_all_pixel_locations()
        self.pixel_addr = {}
        for pixel, _ in self.pixel_locations:
            self.pixel_addr[pixel] = BufferUtils.get_buffer_address(self._app, pixel)

        self.reset()
开发者ID:underwatercolor,项目名称:firemix,代码行数:9,代码来源:additive_blend.py

示例8: setup

 def setup(self):
     self.add_parameter(StringParameter('first-preset', ""))
     self.add_parameter(StringParameter('second-preset', ""))
     self.add_parameter(FloatParameter('transition-progress', 0.5))
     self.add_parameter(StringParameter('transition-mode', "Additive Blend"))
     self.add_parameter(StringParameter('layer', 'default'))
     self.parameter_changed(None)
     self._preset1_buffer = BufferUtils.create_buffer()
     self._preset2_buffer = BufferUtils.create_buffer()
开发者ID:ikea-lisp-code,项目名称:firemix,代码行数:9,代码来源:combine.py

示例9: tick

    def tick(self):
        self._num_frames += 1
        if len(self._playlist) > 0:

            self._playlist.get_active_preset().clear_commands()
            self._playlist.get_active_preset().tick()
            transition_progress = 0.0

            # Handle transition by rendering both the active and the next preset, and blending them together
            if self._in_transition:
                if self._start_transition:
                    self._start_transition = False
                    if self._random_transition:
                        self.get_next_transition()
                    if self._transition:
                        self._transition.reset()
                    self._playlist.get_next_preset()._reset()
                    self._secondary_buffer = BufferUtils.create_buffer(self._app)
                if self._transition_duration > 0.0 and self._transition is not None:
                    transition_progress = self._elapsed / self._transition_duration
                else:
                    transition_progress = 1.0
                self._playlist.get_next_preset().clear_commands()
                self._playlist.get_next_preset().tick()

                # Exit from transition state after the transition duration has elapsed
                if transition_progress >= 1.0:
                    self._in_transition = False
                    # Reset the elapsed time counter so the preset runs for the full duration after the transition
                    self._elapsed = 0.0
                    self._playlist.advance()

            # If the scene tree is available, we can do efficient mixing of presets.
            # If not, a tree would need to be constructed on-the-fly.
            # TODO: Support mixing without a scene tree available
            if self._enable_rendering:
                if self._in_transition:
                    self.render_presets(self._playlist.get_active_index(), self._playlist.get_next_index(), transition_progress)
                else:
                    self.render_presets(self._playlist.get_active_index())
            else:
                if self._net is not None:
                    self._net.write(self._playlist.get_active_preset().get_commands_packed())

            if not self._paused and (self._elapsed >= self._duration) and self._playlist.get_active_preset().can_transition() and not self._in_transition:
                if (self._elapsed >= (self._duration + self._transition_slop)) or self._onset:
                    if len(self._playlist) > 1:
                        self.start_transition()
                    self._elapsed = 0.0

            if self._reset_onset:
                self._onset = False
                self._reset_onset = False

        if self._enable_profiling:
            tick_time = (time.time() - self._last_frame_time)
            self._last_frame_time = time.time()
            if tick_time > 0.0:
                index = int((1.0 / tick_time))
                self._tick_time_data[index] = self._tick_time_data.get(index, 0) + 1
开发者ID:underwatercolor,项目名称:firemix,代码行数:60,代码来源:mixer.py

示例10: get_fixture_bounding_box

    def get_fixture_bounding_box(self):
        """
        Returns the bounding box containing all fixtures in the scene
        Return value is a tuple of (xmin, ymin, xmax, ymax)
        """
        xmin = 999999
        xmax = -999999
        ymin = 999999
        ymax = -999999

        fh = self.fixture_hierarchy()
        for strand in fh:
            for fixture in fh[strand]:
                for pixel in range(self.fixture(strand, fixture).pixels):
                    x, y = self.get_pixel_location(BufferUtils.logical_to_index((strand, fixture, pixel)))
                    if x < xmin:
                        xmin = x
                    if x > xmax:
                        xmax = x
                    if y < ymin:
                        ymin = y
                    if y > ymax:
                        ymax = y

        return (xmin, ymin, xmax, ymax)
开发者ID:tobywaite,项目名称:firemix,代码行数:25,代码来源:scene.py

示例11: get_pixel_location

    def get_pixel_location(self, index):
        """
        Returns a given pixel's location in scene coordinates.
        """
        loc = self._pixel_locations_cache.get(index, None)

        if loc is None:

            strand, address, pixel = BufferUtils.index_to_logical(index)
            f = self.fixture(strand, address)

            if pixel == 0:
                loc = f.pos1
            elif pixel == (f.pixels - 1):
                loc = f.pos2
            else:
                x1, y1 = f.pos1
                x2, y2 = f.pos2
                scale = float(pixel) / f.pixels
                relx, rely = ((x2 - x1) * scale, (y2 - y1) * scale)
                loc = (x1 + relx, y1 + rely)

            self._pixel_locations_cache[index] = loc

        return loc
开发者ID:tobywaite,项目名称:firemix,代码行数:25,代码来源:scene.py

示例12: warmup

    def warmup(self):
        """
        Warms up caches
        """
        log.info("Warming up scene caches...")
        fh = self.fixture_hierarchy()
        for strand in fh:
            for fixture in fh[strand]:
                self.get_colliding_fixtures(strand, fixture)
                for pixel in range(self.fixture(strand, fixture).pixels):
                    index = BufferUtils.logical_to_index((strand, fixture, pixel))
                    neighbors = self.get_pixel_neighbors(index)
                    self.get_pixel_location(index)
                    for neighbor in neighbors:
                        self.get_pixel_distance(index, neighbor)
        self.get_fixture_bounding_box()
        self.get_intersection_points()
        self.get_all_pixels_logical()
        self._tree = spatial.KDTree(self.get_all_pixel_locations())

        locations = self.get_all_pixel_locations()
        self.pixelDistances = np.empty([len(locations), len(locations)])

        for pixel in range(len(locations)):
            cx, cy = locations[pixel]
            x,y = (locations - (cx, cy)).T
            pixel_distances = np.sqrt(np.square(x) + np.square(y))
            self.pixelDistances[pixel] = pixel_distances

        log.info("Done")
开发者ID:nyarasha,项目名称:firemix,代码行数:30,代码来源:scene.py

示例13: setup

    def setup(self):
        self.num_strands, self.num_pixels = BufferUtils.get_buffer_size(self._app)

        self.scene_bb = self._app.scene.get_fixture_bounding_box()
        self.scene_center = (self.scene_bb[0] + (self.scene_bb[2] - self.scene_bb[0]) / 2, self.scene_bb[1] + (self.scene_bb[3] - self.scene_bb[1]) / 2)
        dx = self.scene_bb[2] - self.scene_center[0]
        dy = self.scene_bb[3] - self.scene_center[1]
        self.radius = math.sqrt(math.pow(dx,2) + math.pow(dy, 2))
开发者ID:bhitov,项目名称:firemix,代码行数:8,代码来源:radial_wipe.py

示例14: setup

    def setup(self):
        self.num_strands, self.num_pixels = BufferUtils.get_buffer_size(self._app)

        bb = self._app.scene.get_fixture_bounding_box()
        self.scene_center = np.asarray([bb[0] + (bb[2] - bb[0]) / 2, bb[1] + (bb[3] - bb[1]) / 2])
        self.bb = bb

        self.reset()
开发者ID:bhitov,项目名称:firemix,代码行数:8,代码来源:wipe.py

示例15: __init__

    def __init__(self, app):
        super(Mixer, self).__init__()
        self._app = app
        self._net = app.net
        self._scene = app.scene
        self._tick_rate = self._app.settings.get('mixer')['tick-rate']
        self._tick_timer = None
        self._running = False
        self._enable_rendering = True
        self._main_buffer = None
        self._tick_time_data = dict()
        self._num_frames = 0
        self._last_frame_time = 0.0
        self._start_time = 0.0
        self._stop_time = 0.0
        self._enable_profiling = self._app.args.profile
        self._paused = self._app.settings.get('mixer').get('paused', False)
        self._frozen = False
        self._last_onset_time = 0.0
        self._onset_holdoff = self._app.settings.get('mixer')['onset-holdoff']
        self._onset = False
        self._reset_onset = False
        self._global_dimmer = 1.0
        self._global_speed = 1.0
        self._render_in_progress = False
        self._last_tick_time = time.time()
        self._audio_emitters_by_group = {}
        self._layers = []
        self._leap_controller = Leap.Controller()
                
        
        if self._app.args.yappi and USE_YAPPI:
            yappi.start()

        if not self._scene:
            log.warn("No scene assigned to mixer.  Preset rendering and transitions are disabled.")
            self._enable_rendering = False
        else:
            log.info("Warming up BufferUtils cache...")
            BufferUtils.init()
            log.info("Completed BufferUtils cache warmup")

            log.info("Initializing preset rendering buffer")
            fh = self._scene.fixture_hierarchy()

            self._main_buffer = BufferUtils.create_buffer()
开发者ID:jfslocum,项目名称:firemix,代码行数:46,代码来源:mixer.py


注:本文中的lib.buffer_utils.BufferUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。