Berry animation new tutorials (#24249)
* Remove tab from json * Berry animation new tutorials
This commit is contained in:
parent
a9d32dc979
commit
0f084eedcc
@ -1,20 +0,0 @@
|
||||
# @desc Rainbow colors cycling through the entire strip over time
|
||||
|
||||
# define a palette of rainbow colors including white with constant brightness
|
||||
palette rainbow_with_white = [
|
||||
0xFC0000 # Red
|
||||
0xFF8000 # Orange
|
||||
0xFFFF00 # Yellow
|
||||
0x00FF00 # Green
|
||||
0x00FFFF # Cyan
|
||||
0x0080FF # Blue
|
||||
0x8000FF # Violet
|
||||
0xCCCCCC # White
|
||||
]
|
||||
|
||||
# define a color attribute that cycles over time, cycle is 5 seconds
|
||||
color eye_color = color_cycle(palette=rainbow_with_white, cycle_period=5s)
|
||||
|
||||
animation back = solid(color=eye_color)
|
||||
|
||||
run back
|
||||
@ -1,22 +0,0 @@
|
||||
# @desc Smooth color transitions using rich_palette with sine interpolation
|
||||
|
||||
# define a palette of rainbow colors including white with constant brightness
|
||||
palette rainbow_with_white = [
|
||||
0xFC0000 # Red
|
||||
0xFF8000 # Orange
|
||||
0xFFFF00 # Yellow
|
||||
0x00FF00 # Green
|
||||
0x00FFFF # Cyan
|
||||
0x0080FF # Blue
|
||||
0x8000FF # Violet
|
||||
0xCCCCCC # White
|
||||
0xFC0000 # Red - need to add the first color at last position to ensure roll-over
|
||||
]
|
||||
|
||||
# define a color attribute that cycles over time, cycle is 10 seconds
|
||||
color rainbow_rich_color = rich_palette(palette=rainbow_with_white, cycle_period=10s, transition_type=SINE)
|
||||
|
||||
animation back = solid(color=rainbow_rich_color)
|
||||
|
||||
run back
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
# @desc Solid dark clue - using a custom color
|
||||
|
||||
color space_blue = 0x000066 # Note: opaque 0xFF alpha channel is implicitly added
|
||||
animation back = solid(color=space_blue)
|
||||
run back
|
||||
@ -1,21 +0,0 @@
|
||||
# @desc Rainbow gradient pattern across the LED strip
|
||||
|
||||
# define a palette of rainbow colors including white with constant brightness
|
||||
palette rainbow_with_white = [
|
||||
0xFC0000 # Red
|
||||
0xFF8000 # Orange
|
||||
0xFFFF00 # Yellow
|
||||
0x00FF00 # Green
|
||||
0x00FFFF # Cyan
|
||||
0x0080FF # Blue
|
||||
0x8000FF # Violet
|
||||
0xCCCCCC # White
|
||||
]
|
||||
|
||||
# define a color attribute that cycles over time, cycle is 10 seconds
|
||||
color rainbow_rich_color = rich_palette(palette=rainbow_with_white, cycle_period=10s, transition_type=SINE)
|
||||
|
||||
# define a gradient across the whole strip
|
||||
animation back_pattern = palette_gradient_animation(color_source = rainbow_rich_color)
|
||||
|
||||
run back_pattern
|
||||
@ -0,0 +1,4 @@
|
||||
# @desc Twinkle stars - using predefined animations
|
||||
|
||||
animation stars = twinkle_animation()
|
||||
run stars
|
||||
@ -1,25 +0,0 @@
|
||||
# @desc Rainbow gradient with 2 repetitions across the strip
|
||||
|
||||
# define a palette of rainbow colors including white with constant brightness
|
||||
palette rainbow_with_white = [
|
||||
0xFC0000 # Red
|
||||
0xFF8000 # Orange
|
||||
0xFFFF00 # Yellow
|
||||
0x00FF00 # Green
|
||||
0x00FFFF # Cyan
|
||||
0x0080FF # Blue
|
||||
0x8000FF # Violet
|
||||
0xCCCCCC # White
|
||||
0xFC0000 # Red - need to add the first color at last position to ensure roll-over
|
||||
]
|
||||
|
||||
# define a color attribute that cycles over time, cycle is 10 seconds
|
||||
color rainbow_rich_color = rich_palette(palette=rainbow_with_white, cycle_period=10s, transition_type=SINE)
|
||||
|
||||
# since strip_length is dynamic, we need to map it to a variable
|
||||
set strip_len = strip_length()
|
||||
|
||||
# define a gradient across the whole strip
|
||||
animation back_pattern = palette_gradient_animation(color_source = rainbow_rich_color, spatial_period = strip_len / 2)
|
||||
|
||||
run back_pattern
|
||||
@ -1,28 +0,0 @@
|
||||
# @desc Rainbow gradient with oscillating spatial period (breathing effect)
|
||||
|
||||
# define a palette of rainbow colors including white with constant brightness
|
||||
palette rainbow_with_white = [
|
||||
0xFC0000 # Red
|
||||
0xFF8000 # Orange
|
||||
0xFFFF00 # Yellow
|
||||
0x00FF00 # Green
|
||||
0x00FFFF # Cyan
|
||||
0x0080FF # Blue
|
||||
0x8000FF # Violet
|
||||
0xCCCCCC # White
|
||||
0xFC0000 # Red - need to add the first color at last position to ensure roll-over
|
||||
]
|
||||
|
||||
# define a color attribute that cycles over time, cycle is 10 seconds
|
||||
color rainbow_rich_color = rich_palette(palette=rainbow_with_white, cycle_period=0, transition_type=SINE)
|
||||
|
||||
# since strip_length is dynamic, we need to map it to a variable
|
||||
set strip_len = strip_length()
|
||||
|
||||
# define the oscillator for spatial period between 1/2 strip_len and 3/2
|
||||
set period = sine_osc(min_value = strip_len / 2, max_value = (3 * strip_len) / 2, duration = 5s)
|
||||
|
||||
# define a gradient across the whole strip
|
||||
animation back_pattern = palette_gradient_animation(color_source = rainbow_rich_color, spatial_period = period)
|
||||
|
||||
run back_pattern
|
||||
@ -1,22 +0,0 @@
|
||||
# @desc Rainbow gradient rotating along the strip over 5 seconds
|
||||
|
||||
# define a palette of rainbow colors including white with constant brightness
|
||||
palette rainbow_with_white = [
|
||||
0xFC0000 # Red
|
||||
0xFF8000 # Orange
|
||||
0xFFFF00 # Yellow
|
||||
0x00FF00 # Green
|
||||
0x00FFFF # Cyan
|
||||
0x0080FF # Blue
|
||||
0x8000FF # Violet
|
||||
0xCCCCCC # White
|
||||
0xFC0000 # Red - need to add the first color at last position to ensure roll-over
|
||||
]
|
||||
|
||||
# define a color attribute cycles color in space
|
||||
color rainbow_rich_color = rich_palette(palette=rainbow_with_white, cycle_period=0, transition_type=SINE)
|
||||
|
||||
# define a gradient across the whole strip
|
||||
animation back_pattern = palette_gradient_animation(color_source = rainbow_rich_color, shift_period = 5s)
|
||||
|
||||
run back_pattern
|
||||
@ -1,21 +0,0 @@
|
||||
# @desc VU-meter style animation with green-yellow-red gradient at 85%
|
||||
|
||||
# define a palette of rainbow colors including white with constant brightness
|
||||
palette vue_meter_palette = [
|
||||
( 0, 0x00FF00) # Green
|
||||
(143, 0x00FF00)
|
||||
|
||||
(164, 0xFFFF00) # Yellow
|
||||
(207, 0xFFFF00)
|
||||
|
||||
(228, 0xFF0000) # Red
|
||||
(255, 0xFF0000)
|
||||
]
|
||||
|
||||
# define a color palette pattern for 'vue_meter_palette'
|
||||
color rainbow_rich_color = rich_palette(palette=vue_meter_palette, cycle_period=0, transition_type=LINEAR)
|
||||
|
||||
# define a vue-meter based on all elements above
|
||||
animation back_pattern = palette_meter_animation(color_source = rainbow_rich_color, level = 85%)
|
||||
|
||||
run back_pattern
|
||||
@ -0,0 +1,10 @@
|
||||
# @desc Twinkle stars with parameters - using animation parameters
|
||||
|
||||
# Note: when parameters are in separate lines, you don't need a comma ','
|
||||
animation stars = twinkle_animation(
|
||||
color=0xFFFFAA # Light yellow sparkles
|
||||
density=8 # density (moderate sparkles)
|
||||
twinkle_speed=100ms # twinkle speed
|
||||
fade_speed=50 # when no unit, time unit is 'ms'
|
||||
)
|
||||
run stars
|
||||
@ -0,0 +1,16 @@
|
||||
# @desc Twinkle night - twinkle stars over a dark night
|
||||
|
||||
# Dark blue background
|
||||
color space_blue = 0x000066 # Note: opaque 0xFF alpha channel is implicitly added
|
||||
animation background = solid(color=space_blue)
|
||||
run background
|
||||
|
||||
# Note: when parameters are in separate lines, you don't need a comma ','
|
||||
animation stars = twinkle_animation(
|
||||
color=0xFFFFAA # Light yellow sparkles
|
||||
density=8 # density (moderate sparkles)
|
||||
twinkle_speed=100ms # twinkle speed
|
||||
fade_speed=50 # when no unit, time unit is 'ms'
|
||||
priority=8 # default priority is 10, so being lower than background puts it on top
|
||||
)
|
||||
run stars
|
||||
@ -0,0 +1,8 @@
|
||||
# @desc Rainbow colors cycling through the entire strip over time
|
||||
|
||||
# Define a color attribute that cycles over time, cycle is 5 seconds
|
||||
# PALETTE_RAINBOW defines 7 rainbow colors at roughly the same brightness
|
||||
# PALETTE_RAINBOW_W adds 8th color white
|
||||
color rainbow_color = color_cycle(palette=PALETTE_RAINBOW_W, cycle_period=5s)
|
||||
animation back = solid(color=rainbow_color)
|
||||
run back
|
||||
@ -1,17 +0,0 @@
|
||||
# @desc Night sky with twinkling stars on dark blue background
|
||||
|
||||
# Dark blue background
|
||||
color space_blue = 0x000066 # Note: opaque 0xFF alpha channel is implicitly added
|
||||
animation background = solid(color=space_blue)
|
||||
|
||||
# Add sparkle trail behind comets but on top of blue background
|
||||
animation stars = twinkle_animation(
|
||||
color=0xFFFFAA # Light blue sparkles
|
||||
density=8 # density (moderate sparkles)
|
||||
twinkle_speed=400ms # twinkle speed (quick sparkle)
|
||||
priority = 8
|
||||
)
|
||||
|
||||
# Start all animations
|
||||
run background
|
||||
run stars
|
||||
@ -0,0 +1,21 @@
|
||||
# @desc Rainbow colors cycling with custom palette
|
||||
|
||||
# Define a palette of rainbow colors including white with constant brightness
|
||||
# By default spacing in time is evenly spread over all colors
|
||||
palette rainbow_with_white = [
|
||||
0xFC0000 # Red
|
||||
0xFF8000 # Orange
|
||||
0xFFFF00 # Yellow
|
||||
0x00FF00 # Green
|
||||
0x00FFFF # Cyan
|
||||
0x0080FF # Blue
|
||||
0x8000FF # Violet
|
||||
0xCCCCCC # White
|
||||
]
|
||||
|
||||
# Define a color attribute that cycles over time, cycle is 5 seconds
|
||||
color rainbow_color = color_cycle(palette=rainbow_with_white, cycle_period=5s)
|
||||
|
||||
# Define a solid background with this dynamic color
|
||||
animation back = solid(color=rainbow_color)
|
||||
run back
|
||||
@ -0,0 +1,7 @@
|
||||
# @desc Smooth cycling through rainbow colors with custom palette
|
||||
|
||||
animation back = rich_palette_animation()
|
||||
# Equivalent to
|
||||
# animation back = rich_palette_animation(palette=PALETTE_PALETTE_RAINBOW, cycle_period=5s,
|
||||
# transition_type=SINE, brightness=100%)
|
||||
run back
|
||||
@ -0,0 +1,22 @@
|
||||
# @desc Smooth cycling through rainbow colors with custom palette
|
||||
|
||||
# This is the more explicit version
|
||||
# Define a palette of rainbow colors including white with constant brightness
|
||||
palette rainbow_with_white = [
|
||||
0xFC0000 # Red
|
||||
0xFF8000 # Orange
|
||||
0xFFFF00 # Yellow
|
||||
0x00FF00 # Green
|
||||
0x00FFFF # Cyan
|
||||
0x0080FF # Blue
|
||||
0x8000FF # Violet
|
||||
0xCCCCCC # White
|
||||
0xFC0000 # Red - need to add the first color at last position to ensure roll-over
|
||||
]
|
||||
|
||||
# Define a color attribute that cycles over time, cycle is 10 seconds
|
||||
color rainbow_color_rollover = rich_palette(cycle_period=10s)
|
||||
|
||||
# Use the dynamic color in a simple 'solid' animation
|
||||
animation back = solid(color=rainbow_color_rollover)
|
||||
run back
|
||||
@ -0,0 +1,9 @@
|
||||
# @desc Rainbow pattern
|
||||
|
||||
# Define a smooth palette using PALETTE_RAINBOW_W (7 colors + white)
|
||||
# 'cycle_period = 0' means that the colors don't change in time, only spatial change
|
||||
color rainbow_rich_color = rich_palette(palette=PALETTE_RAINBOW_W, cycle_period=0)
|
||||
|
||||
# Define a gradient across the whole strip
|
||||
animation back_pattern = palette_gradient_animation(color_source = rainbow_rich_color)
|
||||
run back_pattern
|
||||
@ -0,0 +1,14 @@
|
||||
# @desc Rainbow gradient with 2 repetitions across the strip
|
||||
|
||||
|
||||
# Define a smooth palette using PALETTE_RAINBOW_W (7 colors + white)
|
||||
# 'cycle_period = 0' means that the colors don't change in time, only spatial change
|
||||
color rainbow_rich_color = rich_palette(palette=PALETTE_RAINBOW_W, cycle_period=0)
|
||||
|
||||
# Because strip_length is dynamic, we need to map it to a variable and can't use the function directly in formulas
|
||||
set strip_len = strip_length()
|
||||
|
||||
# define a gradient across the whole strip
|
||||
animation back_pattern = palette_gradient_animation(color_source = rainbow_rich_color,
|
||||
spatial_period = strip_len / 2)
|
||||
run back_pattern
|
||||
@ -0,0 +1,15 @@
|
||||
# @desc Rainbow gradient with oscillating spatial period between 100% and 50%
|
||||
|
||||
# Define a smooth palette using PALETTE_RAINBOW_W (7 colors + white)
|
||||
# 'cycle_period = 0' means that the colors don't change in time, only spatial change
|
||||
color rainbow_rich_color = rich_palette(palette=PALETTE_RAINBOW_W, cycle_period=0)
|
||||
|
||||
# Because strip_length is dynamic, we need to map it to a variable and can't use the function directly in formulas
|
||||
set strip_len = strip_length()
|
||||
|
||||
# Define the sine oscillator for spatial period between 1/2 strip_len and 3/2
|
||||
set period = sine_osc(min_value = (strip_len - 1) / 2, max_value = (3 * strip_len) / 2, duration = 5s)
|
||||
|
||||
# Define a gradient across the whole strip with variable spatial_period
|
||||
animation back = palette_gradient_animation(color_source = rainbow_rich_color, spatial_period = period)
|
||||
run back
|
||||
@ -0,0 +1,9 @@
|
||||
# @desc Rainbow gradient rotating along the strip over 5 seconds
|
||||
|
||||
# Define a smooth palette using PALETTE_RAINBOW_W (7 colors + white)
|
||||
# 'cycle_period = 0' means that the colors don't change in time, only spatial change
|
||||
color rainbow_rich_color = rich_palette(palette=PALETTE_RAINBOW_W, cycle_period=0)
|
||||
|
||||
# define a gradient across the whole strip
|
||||
animation back = palette_gradient_animation(color_source = rainbow_rich_color, shift_period = 5s)
|
||||
run back
|
||||
@ -0,0 +1,23 @@
|
||||
# @desc VU-meter style animation with green-yellow-red gradient with sawtooth level
|
||||
|
||||
# Define a palette of rainbow colors including white with constant brightness
|
||||
palette vue_meter_palette = [
|
||||
( 0, 0x00FF00) # Green
|
||||
(143, 0x00FF00)
|
||||
|
||||
(164, 0xFFFF00) # Yellow
|
||||
(207, 0xFFFF00)
|
||||
|
||||
(228, 0xFF0000) # Red
|
||||
(255, 0xFF0000)
|
||||
]
|
||||
|
||||
# Define a color palette pattern for 'vue_meter_palette'
|
||||
color rainbow_rich_color = rich_palette(palette=vue_meter_palette, cycle_period=0, transition_type=LINEAR)
|
||||
|
||||
# Define a sawtooth value from 0% to 100%
|
||||
set level = sawtooth(min_value = 0%, max_value=100%, duration = 2s)
|
||||
|
||||
# Define a vue-meter based on all elements above
|
||||
animation back = palette_meter_animation(color_source = rainbow_rich_color, level = level)
|
||||
run back
|
||||
@ -1,5 +1,6 @@
|
||||
# @desc VU-meter with random level using custom Berry function
|
||||
|
||||
# Embed native Berry code to define a random generator function
|
||||
berry """
|
||||
# define a pseudo-random generator, returns value in range 0..255
|
||||
def rand_meter(engine)
|
||||
@ -7,9 +8,10 @@ def rand_meter(engine)
|
||||
end
|
||||
"""
|
||||
|
||||
extern function rand_meter # declare the external function
|
||||
# Declare the external function so it can be used in the animation
|
||||
extern function rand_meter
|
||||
|
||||
# define a palette of rainbow colors including white with constant brightness
|
||||
# Define a palette of rainbow colors including white with constant brightness
|
||||
palette vue_meter_palette = [
|
||||
( 0, 0x00FF00) # Green
|
||||
(143, 0x00FF00)
|
||||
@ -21,10 +23,9 @@ palette vue_meter_palette = [
|
||||
(255, 0xFF0000)
|
||||
]
|
||||
|
||||
# define a color palette pattern for 'vue_meter_palette'
|
||||
# Define a color palette pattern for 'vue_meter_palette'
|
||||
color rainbow_rich_color = rich_palette(palette=vue_meter_palette, cycle_period=0, transition_type=LINEAR)
|
||||
|
||||
# define a vue-meter based on all elements above
|
||||
animation back_pattern = palette_meter_animation(color_source = rainbow_rich_color, level = rand_meter())
|
||||
|
||||
run back_pattern
|
||||
# Define a vue-meter based on all elements above
|
||||
animation back = palette_meter_animation(color_source = rainbow_rich_color, level = rand_meter())
|
||||
run back
|
||||
@ -9,14 +9,14 @@
|
||||
|
||||
# Standard rainbow palette (7 colors with roughly constant brightness)
|
||||
var PALETTE_RAINBOW = bytes(
|
||||
"00FC0000" # Red (value 0)
|
||||
"24FF8000" # Orange (value 36)
|
||||
"49FFFF00" # Yellow (value 73)
|
||||
"6E00FF00" # Green (value 110)
|
||||
"9200FFFF" # Cyan (value 146)
|
||||
"B70080FF" # Blue (value 183)
|
||||
"DB8000FF" # Violet (value 219)
|
||||
"FFFF0000" # Red (value 255)
|
||||
"FFFC0000" # Red
|
||||
"FFFF8000" # Orange
|
||||
"FFFFFF00" # Yellow
|
||||
"FF00FF00" # Green
|
||||
"FF00FFFF" # Cyan
|
||||
"FF0080FF" # Blue
|
||||
"FF8000FF" # Violet
|
||||
"FFFC0000" # Red
|
||||
)
|
||||
|
||||
# Simple RGB palette (3 colors)
|
||||
|
||||
@ -16,9 +16,9 @@ class TwinkleAnimation : animation.animation
|
||||
|
||||
# Parameter definitions with constraints
|
||||
static var PARAMS = animation.enc_params({
|
||||
"color": {"default": 0xFFFFFFFF},
|
||||
"density": {"min": 0, "max": 255, "default": 128},
|
||||
"twinkle_speed": {"min": 1, "max": 5000, "default": 6},
|
||||
"color": {"default": 0xFFFFFFBB}, # slightly yellow stars
|
||||
"density": {"min": 0, "max": 255, "default": 64},
|
||||
"twinkle_speed": {"min": 1, "max": 5000, "default": 100},
|
||||
"fade_speed": {"min": 0, "max": 255, "default": 180},
|
||||
"min_brightness": {"min": 0, "max": 255, "default": 32},
|
||||
"max_brightness": {"min": 0, "max": 255, "default": 255}
|
||||
|
||||
@ -9505,11 +9505,11 @@ be_local_class(TwinkleAnimation,
|
||||
{ be_const_key_weak(PARAMS, -1), be_const_simple_instance(be_nested_simple_instance(&be_class_map, {
|
||||
be_const_map( * be_nested_map(6,
|
||||
( (struct bmapnode*) &(const bmapnode[]) {
|
||||
{ be_const_key_weak(twinkle_speed, 1), be_const_bytes_instance(0700010188130006) },
|
||||
{ be_const_key_weak(twinkle_speed, 1), be_const_bytes_instance(0700010188130064) },
|
||||
{ be_const_key_weak(min_brightness, -1), be_const_bytes_instance(07000001FF000020) },
|
||||
{ be_const_key_weak(density, -1), be_const_bytes_instance(07000001FF00018000) },
|
||||
{ be_const_key_weak(density, -1), be_const_bytes_instance(07000001FF000040) },
|
||||
{ be_const_key_weak(max_brightness, 2), be_const_bytes_instance(07000001FF0001FF00) },
|
||||
{ be_const_key_weak(color, -1), be_const_bytes_instance(0400FF) },
|
||||
{ be_const_key_weak(color, -1), be_const_bytes_instance(0400BB) },
|
||||
{ be_const_key_weak(fade_speed, 0), be_const_bytes_instance(07000001FF0001B400) },
|
||||
})) ) } )) },
|
||||
{ be_const_key_weak(update, -1), be_const_closure(class_TwinkleAnimation_update_closure) },
|
||||
|
||||
Loading…
Reference in New Issue
Block a user