aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormescalinum <mescalinum@users.sourceforge.net>2009-09-03 17:15:10 +0000
committermescalinum <mescalinum@users.sourceforge.net>2009-09-03 17:15:10 +0000
commitdfee02038903ae696be4ad55dc87a2f59461e097 (patch)
treef8009d9c68fa1fc969fb81b5070b95bb8f6d7957
parent129cfacb39fba0644bf5f56a67c73cee6999f0b5 (diff)
add more getters/setters (row,col,cell)
svn path=/trunk/externals/tclpd/; revision=12229
-rw-r--r--bitmap-help.pd85
-rw-r--r--bitmap.tcl50
-rw-r--r--pdlib.tcl10
3 files changed, 127 insertions, 18 deletions
diff --git a/bitmap-help.pd b/bitmap-help.pd
index 307df30..3433eec 100644
--- a/bitmap-help.pd
+++ b/bitmap-help.pd
@@ -1,24 +1,75 @@
-#N canvas 572 379 463 455 10;
-#X obj 133 174 bitmap 15 8 8 1 0 0 1 1 0 0 1 0 1 1 0 0 1 0 1 0 1 1
-0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 0 1 1 1 0 0 0 1 0 1 1 1 0 0 0 0 1 0 0
-0 1 0 1 1 0 0 0 0 0 1;
-#X obj 133 311 print out;
-#X msg 133 146 getrow \$1;
-#X obj 112 175 vradio 15 1 0 8 empty empty empty 0 -8 0 10 -262144
--1 -1 0;
-#X obj 112 341 s \$0r;
-#X obj 133 118 r \$0r;
+#N canvas 625 330 742 518 10;
+#X obj 63 244 bitmap 15 8 8 1 0 0 0 0 0 0 1 1 0 0 0 0 0 1 0 1 0 0 0
+0 1 0 1 1 0 0 0 1 0 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 1 0 1 0 1
+0 1 1 0 1 0 1 0 1 0;
+#X obj 87 410 print out;
+#X msg 39 117 getrow \$1;
+#X obj 42 245 vradio 15 1 0 8 empty empty empty 0 -8 0 10 -228856 -162280
+-1 0;
+#X obj 42 410 s \$0r;
+#X obj 39 89 r \$0r;
#X text 36 19 [bitmap] - a two dimensional array of bits (toggles)
;
#X text 38 49 creation arguments [cellsize] [width] [height] ?[data
...];
-#X obj 262 174 bitmap 15 8 1 1 0 0 1 1 0 1 0;
-#X obj 277 208 bitmap 8 11 11 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1
-1 0 0 0 0 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
-0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1
-0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
-;
+#X msg 111 117 getcol \$1;
+#X obj 111 89 r \$0c;
+#X obj 63 213 r \$0b;
+#X obj 39 157 s \$0b;
+#X obj 63 372 hradio 15 1 0 8 empty empty empty 0 -8 0 10 -228856 -162280
+-1 0;
+#X obj 157 410 s \$0c;
+#X obj 227 157 s \$0b;
+#X msg 227 117 getcell 0 1;
+#X msg 317 117 getcell 1 1;
+#X text 226 88 getcell <row> <col>;
+#X obj 247 243 bitmap 4 16 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
+1 0 1 1 1 1 0 1 1 1 1 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 0 1 0 0 1 1 1 0
+1 0 0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 1 1 1 0 1 0 0 0 1 0 0 1 1 1 1 0 0
+0 0 0 1 1 1 1 1 0 0 1 0 0 1 0 1 1 1 1 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0
+1 0 1 1 1 1 0 0 1 1 1 1 0 1 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 1 1 1 1 0
+1 0 0 1 0 0 1 1 1 1 1 0 0 0 0 0 1 1 1 1 0 0 1 0 0 0 1 0 1 1 1 1 0 0
+0 0 0 0 1 0 0 0 1 0 1 0 0 1 0 1 1 1 0 0 1 0 0 0 1 0 1 0 0 1 0 1 0 1
+0 0 1 1 1 1 1 0 1 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
+#X msg 447 200 setcell \$1 \$2 \$3;
+#N canvas 4 117 450 300 randomdata 0;
+#X obj 220 136 random 2;
+#X obj 62 89 t b b b;
+#X obj 62 35 inlet;
+#X obj 62 187 pack f f f;
+#X obj 62 222 outlet;
+#X obj 62 62 metro 10;
+#X obj 62 136 random 4;
+#X obj 141 136 random 4;
+#X connect 0 0 3 2;
+#X connect 1 0 6 0;
+#X connect 1 1 7 0;
+#X connect 1 2 0 0;
+#X connect 2 0 5 0;
+#X connect 3 0 4 0;
+#X connect 5 0 1 0;
+#X connect 6 0 3 0;
+#X connect 7 0 3 1;
+#X restore 447 175 pd randomdata;
+#X obj 447 151 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1
+1;
+#X obj 447 331 bitmap 16 4 4 1 0 0 0 1 0 0 1 1 0 1 1 1 1 1 0;
+#X msg 465 231 setcol 1 0 0 0 0 \, setcol 2 0 0 0 0;
+#X msg 481 292 setrow \$1 \$2 \$2 \$3 \$3;
+#X msg 481 265 0 1 0 \, 1 1 0 \, 2 0 1 \, 3 0 1;
#X connect 0 0 1 0;
-#X connect 2 0 0 0;
+#X connect 2 0 11 0;
#X connect 3 0 4 0;
#X connect 5 0 2 0;
+#X connect 8 0 11 0;
+#X connect 9 0 8 0;
+#X connect 10 0 0 0;
+#X connect 12 0 13 0;
+#X connect 15 0 14 0;
+#X connect 16 0 14 0;
+#X connect 19 0 22 0;
+#X connect 20 0 19 0;
+#X connect 21 0 20 0;
+#X connect 23 0 22 0;
+#X connect 24 0 22 0;
+#X connect 25 0 24 0;
diff --git a/bitmap.tcl b/bitmap.tcl
index cf5800a..7554e52 100644
--- a/bitmap.tcl
+++ b/bitmap.tcl
@@ -22,6 +22,7 @@ pd::guiclass bitmap {
pd::add_outlet $self float
set @sz [pd::default_arg 0 int 15]
+ if {$@sz < 4} {set @sz 4}
set @w [pd::default_arg 1 int 8]
set @h [pd::default_arg 2 int 8]
@@ -43,6 +44,55 @@ pd::guiclass bitmap {
pd::outlet $self 0 list $r
}
+ 0_getcol {
+ set r [list]
+ set n [pd::arg 0 int]
+ for {set i [expr {$n}]} {$i < [expr {$@w*$@h}]} {incr i $@w} {
+ lappend r [list float [lindex $@data $i]]
+ }
+ pd::outlet $self 0 list $r
+ }
+
+ 0_getcell {
+ set r [pd::arg 0 int]
+ set c [pd::arg 1 int]
+ pd::outlet $self 0 float [lindex $@data [expr {$r*$@w+$c}]]
+ }
+
+ 0_setrow {
+ set row [pd::arg 0 int]
+ set z 1
+ set col 0
+ for {set i [expr {$row*$@w}]} {$i < [expr {($row+1)*$@w}]} {incr i} {
+ set d [expr {0!=[pd::arg $z int]}]
+ lset @data $i $d
+ sys_gui [list $@c itemconfigure cell_${col}_${row}_$self -fill [lindex {white black} $d]]\n
+ incr z
+ incr col
+ }
+ }
+
+ 0_setcol {
+ set col [pd::arg 0 int]
+ set z 1
+ set row 0
+ for {set i [expr {$col}]} {$i < [expr {$@w*$@h}]} {incr i $@w} {
+ set d [expr {0!=[pd::arg $z int]}]
+ lset @data $i $d
+ sys_gui [list $@c itemconfigure cell_${col}_${row}_$self -fill [lindex {white black} $d]]\n
+ incr z
+ incr row
+ }
+ }
+
+ 0_setcell {
+ set r [pd::arg 0 int]
+ set c [pd::arg 1 int]
+ set d [expr {0!=[pd::arg 2 int]}]
+ lset @data [expr {$r*$@w+$c}] $d
+ sys_gui [list $@c itemconfigure cell_${r}_${c}_$self -fill [lindex {white black} $d]]\n
+ }
+
object_save {
return [list #X obj $@x $@y bitmap $@sz $@w $@h {*}$@data \;]
}
diff --git a/pdlib.tcl b/pdlib.tcl
index 2f97b03..a854e04 100644
--- a/pdlib.tcl
+++ b/pdlib.tcl
@@ -152,8 +152,16 @@ namespace eval ::pd {
}
proc arg {n {assertion any}} {
- set v [uplevel 1 "lindex \$args $n"]
+ upvar 1 args up_args
+ set up_args_len [llength $up_args]
+ if {$n < 0 || $n >= $up_args_len} {
+ return -code error "fatal: argument $n out of range"
+ }
+ set v [lindex $up_args $n]
set i 0
+ if {[llength $v] != 2} {
+ return -code error "fatal: malformed atom: $v (full args: $up_args)"
+ }
foreach {selector value} $v {break}
if {$assertion == {int}} {
set assertion {float}