颜色效果
概述
颜色效果 API 提供生成动态灯光效果的实用函数,如彩虹、呼吸、闪烁等基于时间和相位偏移的颜色调制效果。通过 ColorEffects 访问这些函数。
Python 颜色效果 API 实现位于 Applications/Python/PikaPython/MatrixOS_ColorEffects.py,类型提示位于 Applications/Python/PikaPython/_MatrixOS_ColorEffects.pyi。
颜色生成效果
ColorEffects.Rainbow
def Rainbow(period: int = 1000, offset: int = 0) -> Color
生成彩虹色效果,在指定周期内循环遍历色相光谱。
参数:
period(int, 可选):完整颜色循环的持续时间(毫秒),默认为1000msoffset(int, 可选):调整起始色相的偏移量,默认为0
返 回值:
Color:彩虹循环中的当前颜色
示例:
# 基础彩虹效果
rainbow_color = ColorEffects.Rainbow()
MatrixOS.LED.Fill(rainbow_color)
MatrixOS.LED.Update()
# 更快的彩虹,带偏移
fast_rainbow = ColorEffects.Rainbow(500, 100)
MatrixOS.LED.SetColor(Point(0, 0), fast_rainbow)