Okay, I think I now understand what you were trying to do, and I think that your proc would have worked for any number of rows after some fixing:
set output [open "output.txt" w]
proc getPointList {rect_boundary rowOffset colOffset plist} {
global output
set cordlist $rect_boundary
set xl [lindex $cordlist 0]
set yl [lindex $cordlist 1]
set xh [lindex $cordlist 2]
set yh [lindex $cordlist 3]
set xpoints [llength [lindex $plist 0]]
set ypoints [llength $plist]
set rowIncr [expr {($xh-$xl-2*$rowOffset)/($xpoints-1)}]
set colIncr [expr {($yh-$yl-2*$colOffset)/($ypoints-1)}]
set count 0
set list ""
for {set y [expr {$yh - $colOffset}]} {$y >= [expr {$yl + $colOffset}]} {incr y -$colIncr} {
for {set x [expr {$xl + $rowOffset}]} {$x <= [expr {$xh - $rowOffset}]} {incr x $rowIncr} {
lappend list "($x,$y)"
}
incr count
puts $output "R$count: [join $list " "]"
set list ""
}
}
set plist {{A B C D E} {A B C D E} {A B C D E} {A B C D E} {A B C D E}}
set rect_boundary {0 0 100 100}
set rowOffset 0
set colOffset 0
getPointList $rect_boundary $rowOffset $colOffset $plist
close $output
I changed the colIncr
to put more rows.
In the first loop, I used incr y -$colIncr
because this is actually a decrement if you start with the higher y
coordinate.
I also changed the output structure to match the one you were looking for. The above snippet returns the coordinates:
R1: (0,100) (25,100) (50,100) (75,100) (100,100)
R2: (0,75) (25,75) (50,75) (75,75) (100,75)
R3: (0,50) (25,50) (50,50) (75,50) (100,50)
R4: (0,25) (25,25) (50,25) (75,25) (100,25)
R5: (0,0) (25,0) (50,0) (75,0) (100,0)
EDIT: Added variable offsets, blank final row and variable columns per row.
proc getPointList {rect_boundary uRowOffset lRowOffset uColOffset lColOffset plist} {
set cordlist $rect_boundary
set xl [lindex $cordlist 0]
set yl [lindex $cordlist 1]
set xh [lindex $cordlist 2]
set yh [lindex $cordlist 3]
set xpoints 0
foreach r $plist {
if {[llength $r] > $xpoints} {set xpoints [llength $r]}
}
set ypoints [llength $plist]
set rowIncr [expr {($xh-$xl-$lRowOffset-$uRowOffset)/($xpoints-1)}]
set colIncr [expr {($yh-$yl-$lColOffset-$uColOffset)/$ypoints}]
set count 0
set list ""
for {set y [expr {$yh - $uColOffset}]} {$y >= [expr {$yl + $lColOffset}]} {incr y -$colIncr} {
set x [expr {$xl + $lRowOffset}]
foreach n [lindex $plist $count] {
lappend list $x $y
incr x $rowIncr
}
incr count
if {$count == $ypoints} {return $list}
}
}
set plist {{A B C D X} {E F G H} {I K L} {M N}}
set qlist 1
foreach n $plist {
set pattern$plist $n
incr qlist
}
set rect_boundary {0 0 100 100}
set upperRowOffset 0
set lowerRowOffset 0
set upperColOffset 0
set lowerColOffset 0
set pointList [getPointList $rect_boundary $upperRowOffset $lowerRowOffset $upperColOffset $lowerColOffset $plist]
set count 1
foreach sub_list $plist {
foreach n $sub_list {
set pattern$count $n
incr count
}
}
set count 1
foreach {a b} $pointList {
set text "pattern$count"
puts "command -point $a,$b -text [set $text]"
incr count
}