; ShowGETPIXELS - Show How the GETPIXELS Operator Works
; -------------
; print the value of a pixel as three characters, space padded on left
to printPixelValue :pixVal
if less? :pixVal 100 [print "| |]
if less? :pixVal 10 [print "| |]
print :pixVal
end
; print a row of pixels
to printPixelRow :pixels :startIdx :rowWid
localmake "lastIdx sum :startIdx (difference :rowWid 1)
repeat (sentence :startIdx :lastIdx) ~
[printPixelValue (item repcount :pixels) print "| |]
println "||
end
to main
home clean cleartext
setbackground 1 ; set background color to be blue
setshape [2 11] ; set turtle's image to be a ball, diameter = 11 pixels
setpencolor 32 ; set pen color (inner pixels of the ball), to deep blue
stamp ; paint turtle's image onto the graphics canvas
; get pixels in rectangle with top-left corner at -7,8 and width & height = 15
make "pixels getpixels [-7 8 15 15]
; pretty print the values of the rectangle of pixels in the CommandCenter
repeat (sentence 1 (count :pixels) 15) [printPixelRow :pixels repcount 15]
end