#!/usr/bin/wish -f
package require vtk
package require vtkinteraction

proc generateOrigamiStrip {n} {
    origamiStripPoints SetNumberOfPoints [expr $n + 2]
    origamiStripPoints InsertPoint 0 0 0 0
    origamiStripPoints InsertPoint 1 0 2 0
    for {set i 0} {$i < $n} {incr i} {
        if {[expr 1 + $i % 4] > 1} {set depth 0} {set depth 0.5}
        origamiStripPoints InsertPoint [expr $i + 2] [expr 1 + floor($i / 2)] [expr 2 * ($i%2)] $depth
    }

    [origamiStrip GetPointIds] SetNumberOfIds [expr $n + 2]
    for {set i 0} {$i < [expr $n + 2]} {incr i} {
        [origamiStrip GetPointIds] SetId $i $i
    }
    origamiStripGrid Initialize
    origamiStripGrid Allocate 1 1
    origamiStripGrid InsertNextCell [origamiStrip GetCellType] [origamiStrip GetPointIds]
    origamiStripGrid SetPoints origamiStripPoints
}

# Rendering Workflow

vtkPoints origamiStripPoints
vtkTriangleStrip origamiStrip
vtkUnstructuredGrid origamiStripGrid
vtkDataSetMapper origamiMapper
vtkActor origamiActor
vtkRenderer renderer
vtkRenderWindow renWin

generateOrigamiStrip 10;                # for correct zoom

origamiMapper SetInput origamiStripGrid
origamiActor SetMapper origamiMapper
renderer AddActor origamiActor
renderer SetBackground 0.7 0.2 1
renWin AddRenderer renderer    

vtkTkRenderWidget .ren -width 300 -height 300 -rw renWin
::vtk::bind_tk_render_widget .ren

# Parameters

frame .params

# Option 1

scale .params.length \
    -from 5 -to 20 -res 1 \
    -orient horizontal \
    -label "Strip Length:" \
    -command setOrigamiStripLength

.params.length set 10

proc setOrigamiStripLength {val} {
    generateOrigamiStrip $val
    renWin Render
}

# Option 2
# ...

# Finalize the GUI

pack .params.length -side top -anchor nw -fill both
pack .ren .params -side top -fill both -expand yes

wm protocol . WM_DELETE_WINDOW ::vtk::cb_exit
tkwait window .