to aaa ; ; defines gshow ; an alternative to show that will display the value graphically ; experiment with ; gshow "word ; gshow [list of words] ; gshow {array of words} ; gshow {[array] [of] [lists]} ; gshow [{list} {of} {arrays}] ; end to gshow :item local [sz oldpos] make "oldpos pos make "sz gshow.int gshow.size :item cs seth 0 pu ht setpos gshow.int gshow.grow :oldpos gshow.mult :sz [-0.5 0.5] ifelse (0=count :item) [gshow.rect :sz] [gshow.print :item :sz] pu setpos :oldpos pd ht end to gshow.grow :l1 :l2 localmake "newl [] (foreach :l1 :l2 [push "newl (?1+?2)]) output reverse :newl end to gshow.int :l1 localmake "newl [] (foreach :l1 [push "newl int (?+0.5)]) output reverse :newl end to gshow.max :l1 :l2 localmake "newl [] (foreach :l1 :l2 [push "newl (ifelse (?1>?2) [?1] [?2])]) output reverse :newl end to gshow.mult :l1 :l2 localmake "newl [] (foreach :l1 :l2 [push "newl (?1*?2)]) output reverse :newl end to gshow.print :item :sz ifelse (arrayp :item) [ gshow.print.array :item :sz 0 ] [ ifelse (listp :item) [ gshow.print.list :item :sz ] [ gshow.print.default :item :sz ] ] end to gshow.print.array :item :sz :g ; ; :g = 0 - top to bottom (y extra large) ; :g = 1 - left to right (x extra large) ; local [box oldpos newpos incpos button] if (not 0=count :item) [ ifelse (:g=0) [ make "box gshow.int (list (item 1 :sz) ((item 2 :sz) / count :item)) make "incpos gshow.mult :box [0 -1] ] [ make "box gshow.int (list ((item 1 :sz) / count :item) (item 2 :sz)) make "incpos gshow.mult :box [1 0] ] make "oldpos pos make "newpos pos make "button gshow.int gshow.grow gshow.mult :box [0.5 0] [0 -3] foreach (arraytolist :item) [ seth 0 pu ht setpos :newpos gshow.rect :box ; ; handle arrays within arrays as special ; ifelse (arrayp ?) [ pu setpos gshow.grow :newpos [1 -1] gshow.print.array ? (gshow.grow :box [-2 -2]) (1-:g) ] [ pu setpos gshow.grow :newpos [3 -7] gshow.print ? (gshow.grow :box [-6 -9]) seth 0 pu ht setpos gshow.grow :newpos :button pd circle 2 pu ] make "newpos gshow.grow :newpos :incpos ] pu setpos :oldpos pd ] end to gshow.print.default :item :sz localmake "mysz labelsize :item localmake "mypos pos localmake "dx (int (((item 1 :sz)-(item 1 :mysz))/2+(item 1 :mypos))) localmake "dy (int (((item 2 :mysz)-(item 2 :sz))/2+(item 2 :mypos))) ht pu setpos (list :dx :dy) rt 90 pd label :item pu lt 90 setpos :mypos pd end to gshow.print.list :item :sz local [box oldpos] if (not 0=count :item) [ make "box gshow.int (list ((item 1 :sz) / count :item) (item 2 :sz)) make "oldpos pos foreach :item [ gshow.rect :box pu ht rt 90 fd 3 rt 90 fd 2 rt 180 gshow.print ? (gshow.grow :box [-6 -4]) pu ht fd 2 rt 90 fd (item 1 :box)-3 lt 90 ] pu setpos :oldpos pd ] end to gshow.rect :sz ht pd repeat 2 [rt 90 fd (item 1 :sz) rt 90 fd (item 2 :sz)] end to gshow.size :item ifelse (0=count :item) [ output gshow.size.empty ] [ ifelse (arrayp :item) [ output gshow.size.array :item 0 ] [ ifelse (listp :item) [ output gshow.size.list :item ] [ output gshow.size.default :item ] ] ] end to gshow.size.array :item :g ; ; enumerate through list ; local [sz mxsz] make "mxsz [10 5] foreach (arraytolist :item) [ ifelse (arrayp ?) [ make "sz gshow.size.array ? (1-:g) make "sz gshow.grow :sz [2 2] ] [ make "sz gshow.size ? make "sz gshow.grow :sz [6 9] ] make "mxsz gshow.max :mxsz :sz ] output gshow.mult :mxsz (ifelse (:g=0) [(list 1 (count :item))] [(list (count :item) 1)]) end to gshow.size.default :item output labelsize :item end to gshow.size.empty output [10 5] end to gshow.size.list :item ; ; enumerate through list ; local [mxsz] make "mxsz [10 5] foreach :item [make "mxsz gshow.max :mxsz gshow.size ?] output gshow.mult (gshow.grow :mxsz [6 4]) (list (count :item) 1) end