set scriptDir [file normalize [file join [file dirname [info script]] ".."]]
set auto_path [linsert $auto_path 0 $scriptDir]

package require poFti

# Create icon object.
set iconObj [poFti Icon new]

# Spiral parameters.
set cx 50
set cy 50
set turns 5
set pointsPerTurn 20
set totalPoints [expr {$turns * $pointsPerTurn}]
set maxRadius 40

set colorInc [expr {255.0 / $totalPoints}]

puts "Creating colored spiral"

# Generate spiral points.
set ox 50.0
set oy 50.0
for {set i 1} {$i <= $totalPoints} {incr i} {
    # Create item and set draw type and color.
    set itemObj [poFti Item new "Spiral_$i"]

    $itemObj SetType "line"
    set r [expr {int ($i * $colorInc)}]
    set g 0
    set b [expr {255 - int ($i * $colorInc)}]
    $itemObj SetColorRgb $r $g $b

    set angle [expr {2.0 * 3.14159 * $i / $pointsPerTurn}]
    set radius [expr {double($i) / $totalPoints * $maxRadius}]
    
    set x [format "%.2f" [expr {$cx + $radius * cos($angle)}]]
    set y [format "%.2f" [expr {$cy + $radius * sin($angle)}]]
    
    $itemObj AddVertex $ox $oy
    $itemObj AddVertex $x $y
    set ox $x
    set oy $y

    $iconObj AddItem $itemObj
}

# Add item to icon and write icon as FTI file.
puts "Writing file spiralColored.fti ([$iconObj GetNumItems] items)"
$iconObj Write "spiralColored.fti"

exit 0
