;@GreyScale::Buffer is already created and the %p image is already drawn into it
;Prepare variables for looping
var %w = $pic(%p).width
var %h = $Pic(%p).height
var %y = 0
var %x
var %dot
var %rdot
;Start at the top of the image and work down:
while (%y < %h) {
%x = 0
;move from left to right
while (%x < %w) {
;get the current dots RGB value in the format of "RRR+GGG+BBB"
%dot = $getdot(@GreyScale::Buffer,%x,%y)
%rdot = $replace($rgb(%dot),$chr(44),+)
;Check to make sure the color isn't already a shade of grey
if (!$regex(%rdot,/^(\d+)\+\1\+\1$/)) {
;get the average of the R,G,B Values (R + G + B)/3
%n = $calc( ( %rdot )/ 3)
;Replace the current dot's color with the ave'ed rgb's
;why isn't this working:
drawfill -s @GreyScale::Buffer $rgb(%n,%n,%n) %dot %x %y
;This works but is slow:
;drawdot -nr @GreyScale::Buffer $rgb(%n,%n,%n) 1 %x %y
}
;drawdot @GreyScale::Buffer
inc %x
}
inc %y
}