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


Python Color.rainbow_colors方法代码示例

本文整理汇总了Python中color.Color.rainbow_colors方法的典型用法代码示例。如果您正苦于以下问题:Python Color.rainbow_colors方法的具体用法?Python Color.rainbow_colors怎么用?Python Color.rainbow_colors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在color.Color的用法示例。


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

示例1: rainbow_moving

# 需要导入模块: from color import Color [as 别名]
# 或者: from color.Color import rainbow_colors [as 别名]
 def rainbow_moving(self, groups=None, freq=0.5):
     if groups is None:
         groups = self.groups
     """Display rainbow colors using strip-groups, colors are moved."""
     colors = Color.rainbow_colors(2000, freq)
     for i in range(len(colors)):
         state = self.state_factory.state_off()
         for g in range(len(groups)):
             state = self.state_factory.set_strips(state, groups[g], colors[i + g])
         self.network.send(state)
         time.sleep(.03)
开发者ID:jowlo,项目名称:esp8266-pwm,代码行数:13,代码来源:ledctrl.py

示例2: rainbow_moving_state

# 需要导入模块: from color import Color [as 别名]
# 或者: from color.Color import rainbow_colors [as 别名]
    def rainbow_moving_state(self, groups=None, freq=0.5):
        if groups is None:
            groups = self.groups
        """
        Return a state of rainbow colors moving through strip groups.

        i is used as counter.

        """
        colors = Color.rainbow_colors(2000, freq)
        i = 0
        state = self.state_factory.state_off()
        while True:
            i = (i + 1) % (len(colors) - len(groups))
            for g in range(len(groups)):
                state = self.state_factory.set_strips(state, groups[g], colors[i + g])
            yield state
开发者ID:jowlo,项目名称:esp8266-pwm,代码行数:19,代码来源:ledctrl.py

示例3: rainbow_full

# 需要导入模块: from color import Color [as 别名]
# 或者: from color.Color import rainbow_colors [as 别名]
 def rainbow_full(self):
     """Directly display rainbow fade with all strips in single color."""
     colors = Color.rainbow_colors()
     for color in colors:
         self.network.send(self.state_factory.full_color(color))
         time.sleep(.03)
开发者ID:jowlo,项目名称:esp8266-pwm,代码行数:8,代码来源:ledctrl.py

示例4: __init__

# 需要导入模块: from color import Color [as 别名]
# 或者: from color.Color import rainbow_colors [as 别名]
class LED_Controller:
    def __init__(self, strips, udp_address, udp_port):
        self.strips = strips
        self.network = Net(udp_address, udp_port)
        self.fft = None
        self.state_factory = State(strips)
        self.color = Color()
        self.groups = [[a] for a in list(range(strips))]

    def full_color(self, color):
        """Send a color to all strips."""
        self.network.send(self.state_factory.full_color(color))

    def rainbow_full_state(self, state, i, freq=.03):
        """Return a state with all strips in single color of rainbow, i is used as counter."""
        return self.full_color([math.sin(freq * i + offset) * 0.5 + 0.5 for offset in range(0, 6, 2)])

    def rainbow_full(self):
        """Directly display rainbow fade with all strips in single color."""
        colors = Color.rainbow_colors()
        for color in colors:
            self.network.send(self.state_factory.full_color(color))
            time.sleep(.03)

    def rainbow_moving(self, groups=None, freq=0.5):
        if groups is None:
            groups = self.groups
        """Display rainbow colors using strip-groups, colors are moved."""
        colors = Color.rainbow_colors(2000, freq)
        for i in range(len(colors)):
            state = self.state_factory.state_off()
            for g in range(len(groups)):
                state = self.state_factory.set_strips(state, groups[g], colors[i + g])
            self.network.send(state)
            time.sleep(.03)

    def rainbow_moving_state(self, groups=None, freq=0.5):
        if groups is None:
            groups = self.groups
        """
        Return a state of rainbow colors moving through strip groups.

        i is used as counter.

        """
        colors = Color.rainbow_colors(2000, freq)
        i = 0
        state = self.state_factory.state_off()
        while True:
            i = (i + 1) % (len(colors) - len(groups))
            for g in range(len(groups)):
                state = self.state_factory.set_strips(state, groups[g], colors[i + g])
            yield state

    def sine_map_state(self, state, i, groups=GROUPS, freq=0.5):
        """Use a sine-function to set the brightness of strip groups of a given state, cycles with i."""
        a_map = [math.sin(freq * i + offset) * 0.5 + 0.5 for offset in range(len(groups))]
        for g in range(len(groups)):
            state = self.state_factory.set_strips(state, groups[g], [a_map[g] * c for c in state[groups[g][0]]])
        return state

    def move_color_state(self, color, groups=GROUPS, base=None):
        if base is None:
            base=self.state_factory.state_off()
        """Yield states with one color moving through strips."""
        i = 0;
        while True:
            i = (i + 1) % len(groups)
            yield self.state_factory.set_strips(base, groups[i], color)

    def alpha_state(self, state, i, freq=0.3):
        """Return a state in which all strips brightness is set, cycling with i."""
        for s in range(self.strips):
            state = self.state_factory.set_strips(state, [s], Color.alpha(state[s], math.sin(freq * i) * 0.5 + 0.5))
            if DEBUG:
                print(state)
        return state

    def alpha_pulse_colors(self, color, freq=0.5):
        """Return a list colors where color is the base and alpha is cycled."""
        colors = []
        for i in range(2000):
            colors.append([(math.sin(freq * i) * 0.5 + 0.5) * c for c in color])
        return colors

    def pulse_color(self, color, freq=0.5):
        """Display alpha-pulsing color."""
        colors = self.alpha_pulse_colors(color, freq)
        for color in colors:
            self.full_color(color)
            time.sleep(.03)

    def led_funct(self, base, steps, *functions):
        """
        Yield steps-many states based on base, applying functions.

        The supplied functions have to take a state and a counter variable as
        parameters.  Functions are applied in given order.

        """
#.........这里部分代码省略.........
开发者ID:jowlo,项目名称:esp8266-pwm,代码行数:103,代码来源:ledctrl.py


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