ColorAnimationLib — Color Animation Library

Smoothly animates color properties of visual controls — fill colors, stroke colors, and text colors. Essential for hover effects, state transitions, visual feedback, and decorative color cycling. Includes 4 color utility functions for converting between named colors, hex strings, and numeric ARGB values. 50 functions.

CategoryCountDescription
Error Handling4colorani_error, errormsg$, strerror$, clearerror
Color Utilities4colortoalphacolor, alphacolortostring$, rgb, rgba
Creation & Destruction3colorani# (2 overloads), colorani_free
Playback Control3start, stop, stopatcurrent
Core Properties10propertyname, startvalue, stopvalue, duration, delay (get/set)
Behavior — Easing4animationtype, interpolation (get/set)
Behavior — Flags10autoreverse, inverse, loop, enabled, startfromcurrent (get/set)
State Queries3running, normalizedtime, name$
Triggers4trigger, triggerinverse (get/set)
Events5onfinish, onprocess (get/set), clearcallbacks#

Cross-Platform Support

PlatformStatusNotes
Windows✅ Full SupportWin32/Win64
Linux✅ Full SupportGTK-based
Android✅ Full SupportHardware-accelerated

Error Handling

FunctionSignatureDescription
colorani_error()colorani_error@Last error code (0 = no error)
colorani_errormsg$()colorani_errormsg$@Last error message as string
colorani_strerror$(code)colorani_strerror$@nDescription for a given error code
colorani_clearerror()colorani_clearerror@Clear the error state

Error Codes

CodeConstantDescription
0ERR_NONENo error
1ERR_NIL_ANIMATIONAnimation pointer is nil
2ERR_INVALID_PROPERTYInvalid property name or object
3ERR_INVALID_VALUEInvalid color value
4ERR_ANIMATION_RUNNINGCannot modify while animation is running

How It Works

A color animation smoothly interpolates between two colors over time. It targets a color property on its parent control (such as Fill.Color or Stroke.Color) and transitions from a start color to a stop color. Color values are specified as numeric integers (ARGB format), using the provided utility functions to convert from named colors or RGB components:

╯ basic pattern
' 1. Create the animation on a shape
let ani# = colorani#(myRect#)

' 2. Set which color property to animate
colorani_propertyname#(ani#, "Fill.Color")

' 3. Set start and stop colors (as numeric values)
colorani_startvalue#(ani#, colortoalphacolor("Blue"))
colorani_stopvalue#(ani#, colortoalphacolor("Red"))

' 4. Set timing
colorani_duration#(ani#, 2.0)

' 5. Start!
colorani_start(ani#)
⚠ Important — String vs Numeric colors: Shape functions like rectangle_fill# take string color names ("Red", "#FF0000"). Animation functions colorani_startvalue# and colorani_stopvalue# take numeric color values. Use colortoalphacolor() or rgb() to convert.

Color Values

Color animation works with numeric ARGB values (32-bit integers where Alpha, Red, Green, Blue each occupy 8 bits). You can specify colors three ways:

Named Colors

Pass a color name to colortoalphacolor():

Color NameSampleColor NameSample
BlackWhite
RedGreen
BlueYellow
CyanMagenta
OrangePurple
PinkLime
NavyMaroon
TealOlive
Gray / GreySilver
AquaFuchsia

Hex Strings

Also supported by colortoalphacolor():

╯ hex formats
' 6-digit hex (opaque)
let coral = colortoalphacolor("#FF7F50")

' 8-digit hex with alpha (AARRGGBB)
let semiBlue = colortoalphacolor("#800000FF")

RGB / RGBA Components

╯ component colors
' Opaque coral (R=255, G=127, B=80)
let coral = rgb(255, 127, 80)

' Semi-transparent blue (A=128)
let ghostBlue = rgba(0, 0, 255, 128)

Color Utility Functions

FunctionSignatureDescription
colortoalphacolor(name$)colortoalphacolor@$Convert color name or hex string to numeric ARGB value
alphacolortostring$(color)alphacolortostring$@nConvert numeric ARGB to hex string
rgb(r, g, b)rgb@nnnCreate opaque color from R, G, B components (0–255)
rgba(r, g, b, a)rgba@nnnnCreate color with alpha from R, G, B, A components (0–255)
ⓘ Note: These are general-purpose color utilities registered by ColorAnimationLib but usable anywhere in your program. Use colortoalphacolor for named colors and hex strings; use rgb/rgba for computed or custom colors.

Animatable Color Properties

Property NameApplies ToDescription
Fill.ColorShapes (rectangle, circle, ellipse, pie, arc, path)Background fill color
Stroke.ColorShapesBorder/outline color
TextSettings.FontColorLabels, Edit, MemoText color

Interpolation & Easing

Color interpolation blends the R, G, B, and A channels independently using the selected curve. The same 11 interpolation types and 3 easing modes available in FloatAnimationLib apply here:

Interpolation Curves

InterpolationCharacterBest For
"Linear"Constant speedSmooth, even color transitions
"Quadratic"Gentle curveSubtle hover effects
"Cubic"Moderate curveUI state changes
"Quartic"Pronounced curveDramatic color shifts
"Quintic"Very pronouncedEmphatic feedback
"Sinusoidal"Sine-wave smoothPulsing glow effects
"Exponential"Sharp curveFlash-then-settle effects
"Circular"Arc-basedOrganic color blending
"Elastic"Springy overshootBouncy color flicker
"Back"Overshoots then settlesColor “snap” effects
"Bounce"Bouncing ballPlayful color pulsing

Easing Types (AnimationType)

TypeEffectDescription
"In"Slow start → fast endColor change accelerates
"Out"Fast start → slow endColor change decelerates
"InOut"Slow → fast → slowSmooth start and end

Creation & Destruction

FunctionSignatureDescription
colorani#(parent#)colorani#@#Create animation attached to parent control
colorani#(parent#, name$)colorani#@#$Create named animation attached to parent
colorani_free(ani#)colorani_free@#Destroy animation object

Playback Control

FunctionSignatureDescription
colorani_start(ani#)colorani_start@#Start the animation
colorani_stop(ani#)colorani_stop@#Stop and reset to start color
colorani_stopatcurrent(ani#)colorani_stopatcurrent@#Stop at current blended color

Core Properties

Property Name

FunctionSignatureDescription
colorani_propertyname#(ani#, name$)colorani_propertyname#@#$Set which color property to animate
colorani_propertyname$(ani#)colorani_propertyname$@#Get the property name

Color Range

FunctionSignatureDescription
colorani_startvalue#(ani#, color)colorani_startvalue#@#nSet start color (numeric ARGB)
colorani_startvalue(ani#)colorani_startvalue@#Get start color
colorani_stopvalue#(ani#, color)colorani_stopvalue#@#nSet end color (numeric ARGB)
colorani_stopvalue(ani#)colorani_stopvalue@#Get end color

Timing

FunctionSignatureDescription
colorani_duration#(ani#, seconds)colorani_duration#@#nSet duration in seconds
colorani_duration(ani#)colorani_duration@#Get duration
colorani_delay#(ani#, seconds)colorani_delay#@#nSet delay before animation starts
colorani_delay(ani#)colorani_delay@#Get delay

Behavior Flags

Easing & Interpolation

FunctionSignatureDescription
colorani_animationtype#(ani#, type$)colorani_animationtype#@#$Set easing: "In", "Out", "InOut"
colorani_animationtype$(ani#)colorani_animationtype$@#Get easing type
colorani_interpolation#(ani#, type$)colorani_interpolation#@#$Set interpolation curve
colorani_interpolation$(ani#)colorani_interpolation$@#Get interpolation type

Boolean Flags

FunctionSignatureDescription
colorani_autoreverse#(ani#, flag)colorani_autoreverse#@#nIf 1, plays forward then backward
colorani_autoreverse(ani#)colorani_autoreverse@#Get autoreverse flag
colorani_inverse#(ani#, flag)colorani_inverse#@#nIf 1, plays in reverse direction
colorani_inverse(ani#)colorani_inverse@#Get inverse flag
colorani_loop#(ani#, flag)colorani_loop#@#nIf 1, loops indefinitely
colorani_loop(ani#)colorani_loop@#Get loop flag
colorani_enabled#(ani#, flag)colorani_enabled#@#nEnable or disable the animation
colorani_enabled(ani#)colorani_enabled@#Get enabled state
colorani_startfromcurrent#(ani#, flag)colorani_startfromcurrent#@#nIf 1, begins from current color
colorani_startfromcurrent(ani#)colorani_startfromcurrent@#Get startfromcurrent flag

State Queries

FunctionSignatureDescription
colorani_running(ani#)colorani_running@#Returns 1 if currently animating
colorani_normalizedtime(ani#)colorani_normalizedtime@#Returns progress from 0.0 to 1.0
colorani_name$(ani#)colorani_name$@#Get the animation’s name

Triggers

Triggers let a color animation start or reverse automatically when a parent property changes:

FunctionSignatureDescription
colorani_trigger#(ani#, expr$)colorani_trigger#@#$Set trigger expression (starts animation)
colorani_trigger$(ani#)colorani_trigger$@#Get trigger expression
colorani_triggerinverse#(ani#, expr$)colorani_triggerinverse#@#$Set inverse trigger (reverses animation)
colorani_triggerinverse$(ani#)colorani_triggerinverse$@#Get inverse trigger expression
╯ trigger example
' Auto-highlight on hover: normal color → highlight
colorani_trigger#(ani#, "IsMouseOver=true")
colorani_triggerinverse#(ani#, "IsMouseOver=false")

Events

Event SetterGetterCallback SignatureDescription
colorani_onfinish#(ani#, func$)colorani_onfinish$(ani#)function name(sender#)Fired when animation completes
colorani_onprocess#(ani#, func$)colorani_onprocess$(ani#)function name(sender#)Fired on every animation frame
colorani_clearcallbacks#(ani#)Disconnect all callbacks

Complete Examples

Fill Color Transition

╯ color-transition.bas
let frm# = form#("Color Demo", 400, 300)
form_position#(frm#, 4)

let rect# = rectangle#(frm#, 100, 100, 200, 100)
rectangle_fill#(rect#, "Blue")

' Smoothly transition Blue → Red and back
let colorAni# = colorani#(rect#)
colorani_propertyname#(colorAni#, "Fill.Color")
colorani_startvalue#(colorAni#, colortoalphacolor("Blue"))
colorani_stopvalue#(colorAni#, colortoalphacolor("Red"))
colorani_duration#(colorAni#, 2.0)
colorani_autoreverse#(colorAni#, 1)
colorani_loop#(colorAni#, 1)
colorani_start(colorAni#)

form_show(frm#)

while form_visible(frm#) = 1
    processmessages()
end while

Custom RGB Colors

╯ rgb-colors.bas
let frm# = form#("RGB Demo", 400, 300)
form_position#(frm#, 4)

let rect# = rectangle#(frm#, 100, 100, 200, 100)
rectangle_fill#(rect#, "#FF7F50")

' Coral (255,127,80) → Teal (0,128,128)
let coral = rgb(255, 127, 80)
let teal = rgb(0, 128, 128)

let colorAni# = colorani#(rect#)
colorani_propertyname#(colorAni#, "Fill.Color")
colorani_startvalue#(colorAni#, coral)
colorani_stopvalue#(colorAni#, teal)
colorani_duration#(colorAni#, 2.0)
colorani_autoreverse#(colorAni#, 1)
colorani_loop#(colorAni#, 1)
colorani_start(colorAni#)

form_show(frm#)

while form_visible(frm#) = 1
    processmessages()
end while

Text Color Animation

╯ text-color.bas
let frm# = form#("Text Color Demo", 400, 200)
form_position#(frm#, 4)

let lbl# = label#(frm#, "Hello World!")
label_move#(lbl#, 100, 80)
label_fontsize#(lbl#, 24)

' Animate text color: Grey → Red and back
let colorAni# = colorani#(lbl#)
colorani_propertyname#(colorAni#, "TextSettings.FontColor")
colorani_startvalue#(colorAni#, colortoalphacolor("Grey"))
colorani_stopvalue#(colorAni#, colortoalphacolor("Red"))
colorani_duration#(colorAni#, 1.5)
colorani_autoreverse#(colorAni#, 1)
colorani_loop#(colorAni#, 1)
colorani_start(colorAni#)

form_show(frm#)

while form_visible(frm#) = 1
    processmessages()
end while

Stroke Color Animation

╯ border-color.bas
let frm# = form#("Border Demo", 400, 300)
form_position#(frm#, 4)

let rect# = rectangle#(frm#, 100, 75, 200, 150)
rectangle_fill#(rect#, "White")
rectangle_stroke#(rect#, "Blue")
rectangle_strokethickness#(rect#, 4)

' Animate border: Blue → Orange
let colorAni# = colorani#(rect#)
colorani_propertyname#(colorAni#, "Stroke.Color")
colorani_startvalue#(colorAni#, colortoalphacolor("Blue"))
colorani_stopvalue#(colorAni#, colortoalphacolor("Orange"))
colorani_duration#(colorAni#, 1.0)
colorani_autoreverse#(colorAni#, 1)
colorani_loop#(colorAni#, 1)
colorani_start(colorAni#)

form_show(frm#)

while form_visible(frm#) = 1
    processmessages()
end while

Multi-Property Color Animation

╯ multi-color.bas
let frm# = form#("Multi-Color Demo", 400, 300)
form_position#(frm#, 4)

let rect# = rectangle#(frm#, 100, 75, 200, 150)
rectangle_fill#(rect#, "Red")
rectangle_stroke#(rect#, "White")
rectangle_strokethickness#(rect#, 3)

' Animate fill: Red → Purple
let fillAni# = colorani#(rect#, "FillAni")
colorani_propertyname#(fillAni#, "Fill.Color")
colorani_startvalue#(fillAni#, colortoalphacolor("Red"))
colorani_stopvalue#(fillAni#, colortoalphacolor("Purple"))
colorani_duration#(fillAni#, 2.0)
colorani_autoreverse#(fillAni#, 1)
colorani_loop#(fillAni#, 1)

' Animate stroke: White → Yellow (different duration)
let strokeAni# = colorani#(rect#, "StrokeAni")
colorani_propertyname#(strokeAni#, "Stroke.Color")
colorani_startvalue#(strokeAni#, colortoalphacolor("White"))
colorani_stopvalue#(strokeAni#, colortoalphacolor("Yellow"))
colorani_duration#(strokeAni#, 1.5)
colorani_autoreverse#(strokeAni#, 1)
colorani_loop#(strokeAni#, 1)

' Start both animations
colorani_start(fillAni#)
colorani_start(strokeAni#)

form_show(frm#)

while form_visible(frm#) = 1
    processmessages()
end while

Best Practices

PracticeWhy
Use colortoalphacolor() for named and hex colorsConverts strings to the numeric format the animation needs
Use rgb() / rgba() for computed custom colorsWhen R, G, B values come from variables or calculations
Use "Linear" for smooth even transitionsOther curves can create unexpected color jumps in the middle
Use autoreverse + loop for continuous cyclingCreates a smooth back-and-forth color oscillation
Use startfromcurrent = 1 for interruptionsAvoids color jumps when restarting mid-transition
Animate Fill.Color for background transitionsMost common use case for shape color changes
Animate Stroke.Color for border highlightsUse with thicker strokes (3–4px) for visible effect
Animate TextSettings.FontColor for text emphasisWorks on labels and text input controls
Name animations when stacking multiple on one controlUse colorani#(parent#, name$) for clarity
Use delay for staggered color effectsDifferent delays create cascading color wave effects

Quick Reference

FunctionSignatureDescription
colorani_error / errormsg$ / strerror$ / clearerrorvariousError handling (4)
colortoalphacolor / alphacolortostring$ / rgb / rgbavariousColor utilities (4)
colorani#(parent#[, name$])colorani#@# / colorani#@#$Create (2 overloads)
colorani_free(ani#)colorani_free@#Destroy
colorani_start / stop / stopatcurrentvariousPlayback control (3)
colorani_propertyname# / propertyname$variousTarget property (2)
colorani_startvalue / stopvaluevariousColor range (4)
colorani_duration / delayvariousTiming (4)
colorani_animationtype / interpolationvariousEasing & curves (4)
colorani_autoreverse / inverse / loop / enabled / startfromcurrentvariousBehavior flags (10)
colorani_running / normalizedtime / name$variousState queries (3)
colorani_trigger / triggerinversevariousAutomatic triggers (4)
colorani_onfinish / onprocess / clearcallbacks#variousEvents (5)

50 functions (46 animation + 4 color utilities). Part of the Plan9Basic Animation library system.