Skip to content

Commit badb58b

Browse files
authored
Berry animation update tutorials (#24255)
1 parent b92cbf2 commit badb58b

31 files changed

+138
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# @desc Static beacon
2+
3+
# Simple beacon starting at pixel 6 with size of 7 pixels, no border
4+
animation back = beacon_animation(back_color = blue, color = red,
5+
pos = 5, beacon_size = 7)
6+
run back
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# @desc Static beacon with slew
2+
3+
# Simple beacon starting at pixel 6 with size of 7 pixels, no border
4+
animation back = beacon_animation(back_color = blue, color = red,
5+
pos = 5, beacon_size = 7, slew_size = 3)
6+
run back
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# @desc Static beacon with oscillating slew
2+
3+
# Define an oscillating value from 0 to 4 and back to 0 in 2 seconds
4+
set slew = cosine_osc(min_value = 0, max_value = 4, duration = 2s)
5+
6+
# Simple beacon starting at pixel 6 with size of 7 pixels, no border
7+
animation back = beacon_animation(back_color = blue, color = red,
8+
pos = 5, beacon_size = 7, slew_size = slew)
9+
run back
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# @desc Moving red beacon - Cylon style
2+
3+
# Because strip_length is dynamic, we need to map it to a variable and can't use the function directly in formulas
4+
set strip_len = strip_length()
5+
6+
# In this example, the 'cosine_osc' is created within the call
7+
animation back = beacon_animation(
8+
color = red
9+
pos = cosine_osc(min_value = -1, max_value = strip_len - 2, duration = 5s)
10+
beacon_size = 3 # small 3 pixels eye
11+
slew_size = 2 # with 2 pixel shading around
12+
)
13+
run back
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# @desc Moving rainbow beacon and stars
2+
# In this example we combine a Twinkle star as background,
3+
# a moving beacon with a dynamic color using the rainbow palette
4+
5+
# Because strip_length is dynamic, we need to map it to a variable and can't use the function directly in formulas
6+
set strip_len = strip_length()
7+
8+
animation stars = twinkle_animation(
9+
color=0xFFFFAA # Light yellow sparkles
10+
density=2 # density (moderate sparkles)
11+
twinkle_speed=100ms # twinkle speed
12+
fade_speed=100 # when no unit, time unit is 'ms'
13+
# priority = 10 # this is the implicit priority
14+
)
15+
run stars
16+
17+
# We can combine a dynamic 'pos' value with a dynamic 'color'
18+
animation back = beacon_animation(
19+
color = rich_palette(palette=PALETTE_RAINBOW_W2, cycle_period=5s)
20+
pos = cosine_osc(min_value = -1, max_value = strip_len - 2, duration = 5s)
21+
beacon_size = 3 # small 3 pixels eye
22+
slew_size = 2 # with 2 pixel shading around
23+
priority = 5 # priority below 10 so it's on top of twinkle
24+
)
25+
run back
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# @desc Moving beacon used as opacity filter on pattern
2+
# In this example we use the moving beacon as an opacity mask
3+
# on top of a pattern
4+
5+
# Define 'strip_len' to make calculations
6+
set strip_len = strip_length()
7+
8+
# Define a pattern that goes from red to blue to red across the strip
9+
palette red_blue_red_palette = [ red, 0x3333FF, red ]
10+
# Embed this raw palette into a rich_palette color provider
11+
color red_blue_red_color = rich_palette(palette=red_blue_red_palette)
12+
13+
# Define a moving beacon to be used as an opacity mask
14+
animation moving_eye = beacon_animation(
15+
color = white # the color is not important, only the opacity counts here
16+
pos = cosine_osc(min_value = -1, max_value = strip_len - 2, duration = 5s)
17+
beacon_size = 3 # small 3 pixels eye
18+
slew_size = 2 # with 2 pixel shading around
19+
)
20+
21+
# The palette gradient animation is used with an animation as opacity
22+
animation eye_pattern = palette_gradient_animation(
23+
color_source = red_blue_red_color # the beacon animation used as opacity
24+
# spatial_period = strip_len # implicit
25+
opacity = moving_eye
26+
)
27+
run eye_pattern
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# @desc Shutter left to right using beacon
2+
3+
# Define 'strip_len' to make calculations
4+
set strip_len = strip_length()
5+
6+
# Define shutter_size as a sawtootgh from 0 to strip_len
7+
set shutter_size = sawtooth(min_value = 0, max_value = strip_len,
8+
duration = 1.5s)
9+
10+
# Using beacon_animation to move a shutter from left to right
11+
animation shutter_lr_animation = beacon_animation(
12+
color = red
13+
back_color = blue
14+
pos = 0 # Start from position 0 (left)
15+
beacon_size = shutter_size # Oscillating size from 0 to strip_len
16+
)
17+
run shutter_lr_animation
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# @desc Shutter left to right with rotating colors, using sequence
2+
3+
# Define 'strip_len' to make calculations
4+
set strip_len = strip_length()
5+
6+
# Set a global variable for 'period'
7+
set period = 1.5s
8+
9+
# Define shutter_size as a sawtootgh from 0 to strip_len
10+
set shutter_size = sawtooth(min_value = 0, max_value = strip_len,
11+
duration = period)
12+
13+
# Define 2 color providers cycling through palette rainbow with white
14+
# 'col2' is shifted by 1 color from 'col1'
15+
color col1 = color_cycle(palette=PALETTE_RAINBOW_W, cycle_period=0)
16+
color col2 = color_cycle(palette=PALETTE_RAINBOW_W, cycle_period=0)
17+
col2.next = 1 # Writing 1 to 'next' actually advances the color
18+
19+
# Using beacon_animation to move a shutter from left to right
20+
animation shutter_lr_animation = beacon_animation(
21+
color = col2 # Use two rotating colors
22+
back_color = col1 # Use two rotating colors
23+
pos = 0 # Start from position 0 (left)
24+
beacon_size = shutter_size
25+
# Oscillating size from 0 to strip_len
26+
)
27+
28+
# Define a sequence running forever
29+
sequence shutter_seq repeat forever {
30+
restart shutter_size # Make sure that shutter_size is synced with the sequence
31+
play shutter_lr_animation for period # Play animation
32+
col1.next = 1 # set 'col1' to next color
33+
col2.next = 1 # set 'col2' to next color
34+
}
35+
run shutter_seq
1.89 KB
Loading
1.93 KB
Loading

0 commit comments

Comments
 (0)