|
| 1 | +""" |
| 2 | +Custom RGB colors: shows that Color() accepts arbitrary r/g/b values (0–255). |
| 3 | +
|
| 4 | +Two drones cycle through a warm sunset palette built from custom colors that |
| 5 | +have no named preset in flaight — demonstrating that the LED is not limited |
| 6 | +to the built-in constants. |
| 7 | +
|
| 8 | +Usage: |
| 9 | + python examples/custom_color.py # dry-run (instant) |
| 10 | + python examples/custom_color.py --realtime # dry-run, real-time pacing |
| 11 | + python examples/custom_color.py --fly # real hardware |
| 12 | +""" |
| 13 | +from flaight import Color, FadeColor, Hover, Land, SetColor, Show, Takeoff |
| 14 | + |
| 15 | +URIS = [ |
| 16 | + "radio://0/80/2M/E7E7E7E7E7", |
| 17 | + "radio://0/81/2M/E7E7E7E7E7", |
| 18 | +] |
| 19 | + |
| 20 | +# Custom palette — none of these are named presets |
| 21 | +SUNSET = [ |
| 22 | + Color(r=255, g=20, b=0), # deep red |
| 23 | + Color(r=255, g=80, b=10), # burnt orange |
| 24 | + Color(r=255, g=140, b=0), # dark amber |
| 25 | + Color(r=255, g=200, b=30), # golden yellow |
| 26 | + Color(r=255, g=120, b=60), # peach |
| 27 | + Color(r=200, g=40, b=80), # crimson rose |
| 28 | + Color(r=120, g=0, b=60), # deep violet |
| 29 | +] |
| 30 | + |
| 31 | +FADE = 1.8 # seconds per color transition |
| 32 | +HOLD = 0.4 # seconds to hold between fades |
| 33 | + |
| 34 | +show = Show() |
| 35 | +d1 = show.add_drone("cf1", uri=URIS[0]) |
| 36 | +d2 = show.add_drone("cf2", uri=URIS[1]) |
| 37 | + |
| 38 | +for drone, offset in ((d1, 0.0), (d2, FADE + HOLD)): |
| 39 | + drone.at(0.0, Takeoff(height=1.0, duration=2.0)) |
| 40 | + drone.at(0.0, SetColor(Color.OFF)) |
| 41 | + |
| 42 | + total = FADE * len(SUNSET) + HOLD * (len(SUNSET) - 1) |
| 43 | + drone.at(2.5, Hover(duration=total + offset)) |
| 44 | + |
| 45 | + t = 2.5 + offset |
| 46 | + for color in SUNSET: |
| 47 | + drone.at(t, FadeColor(color=color, duration=FADE)) |
| 48 | + t += FADE + HOLD |
| 49 | + |
| 50 | + drone.at(t, FadeColor(color=Color.OFF, duration=FADE)) |
| 51 | + drone.at(t + FADE, Land(duration=2.0)) |
| 52 | + |
| 53 | +if __name__ == "__main__": |
| 54 | + import sys |
| 55 | + if "--fly" in sys.argv: |
| 56 | + from flaight import FlightRunner |
| 57 | + FlightRunner(show).run() |
| 58 | + else: |
| 59 | + from flaight import DryRunRunner |
| 60 | + DryRunRunner(show, realtime="--realtime" in sys.argv).run() |
0 commit comments