From 84a77837bb4ab989d86703e802c1542f0933ce14 Mon Sep 17 00:00:00 2001 From: thirdr Date: Tue, 1 Oct 2024 14:07:43 +0100 Subject: [PATCH] Examples: added bounce to rainbow.py --- examples/rainbow.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/rainbow.py b/examples/rainbow.py index 1195a14..aaedeee 100644 --- a/examples/rainbow.py +++ b/examples/rainbow.py @@ -2,6 +2,7 @@ # We're using a RAM intensive 64K colour palette here to get a nice smooth colour transition. import time +import math from picographics import PicoGraphics, DISPLAY_EXPLORER, PEN_RGB565 display = PicoGraphics(display=DISPLAY_EXPLORER, pen_type=PEN_RGB565) @@ -39,13 +40,16 @@ def hsv_to_rgb(h, s, v): while True: h += 1 + t = time.ticks_ms() / (5 * 1000) + bounce_y = int(120 + math.sin(t * 2 + h) * 3) + r, g, b = [int(255 * c) for c in hsv_to_rgb(h / 360.0, 1.0, 1.0)] # rainbow magic RAINBOW = display.create_pen(r, g, b) # Create pen with converted HSV value display.set_pen(RAINBOW) # Set pen display.clear() # Fill the screen with the colour display.set_pen(BLACK) # Set pen to black - display.text("pico disco!", 10, 10, 240, 6) # Add some text - display.text("\\o/ \\o/ \\o/ \\o/ \\o/ \\o/ \\o/ \\o/ \\o/", 25, 120, 240, 4) # and some more text - display.text("oontz oontz oontz", 25, 220, 240, 2) # and a bit more tiny text + display.text("pico disco!", 60, 10, 240, 6) # Add some text + display.text("\\o/ \\o/ \\o/ \\o/ \\o/ \\o/ \\o/ \\o/ \\o/", 55, bounce_y, 240, 4) # and some more text + display.text("oontz oontz oontz", 60, 220, 240, 2) # and a bit more tiny text display.update() # Update the display time.sleep(1.0 / 60)