Color to Black and White Converter
DEF CONVERT X,Y,X2,Y2
FOR I=X TO X2
FOR I2=Y TO Y2
A=GSPOIT(I,I2)
RGBREAD A OUT R,G,B
B=(R+G+B)/3
GPSET I,I2,RGB(B,B,B)
NEXT
NEXT
END
 Submitted
 Updated
 Categories
 Keywords

 grayscale
DEF CONVERT X,Y,X2,Y2
FOR I=X TO X2
FOR I2=Y TO Y2
A=GSPOIT(I,I2)
RGBREAD A OUT R,G,B
B=(R+G+B)/3
GPSET I,I2,RGB(B,B,B)
NEXT
NEXT
END
DEF CONVERT X,Y,X2,Y2 'get width and height of area to convert VAR W=X2X VAR H=Y2Y ' VAR AREA=W*H'calculates area WHILE COUNT<AREA VAR X3=(AREA MOD W)+X'gets the single axis value into an x value VAR Y3=(FLOOR(AREA/WIDTH))+Y'gets the single axis value into a y value VAR COL=GSPOIT(X3, Y3) VAR R, G, B RGBREAD COL OUT R, G, B'convert a single 'value integer into three values VAR GREY=(R+G+B)/3'or "gray" if you spell it 'that way GPSET X3, Y3, RGB(GREY, GREY, GREY)'recolor 'that pixel in greyscale WEND END
DEF GRAY X,Y,W,H DIM COL%[W*H],RED%[W*H],GRB%[W*H] 'SAVE DATA GSAVE X,Y,W,H,COL%,TRUE 'save 16 bit colors 'EXTRACT RED ARYOP #AOPDIV,RED%,COL%,&H800 ARYOP #AOPMAD,COL%,RED%,&H800,COL% 'EXTRACT GREEN ARYOP #AOPDIV,GRB%,COL%,&H40 ARYOP #AOPMAD,COL%,GRB%,&H40,COL% ARYOP #AOPADD,RED%,RED%,GRB% 'EXTRACT BLUE ARYOP #AOPDIV,GRB%,COL%,&H2 ARYOP #AOPMAD,COL%,GRB%,&H2,COL% ARYOP #AOPADD,RED%,RED%,GRB% 'GET AVERAGE ARYOP #AOPDIV,RED%,RED%,3 'MAKE GRAY ARYOP #AOPMAD,COL%,RED%,&H2,COL% ARYOP #AOPMAD,COL%,RED%,&H40,COL% ARYOP #AOPMAD,COL%,RED%,&H800,COL% 'LOAD DATA GLOAD X,Y,W,H,COL%,TRUE,TRUE END
DEF GRAYSCREEN X0,Y1,X1,Y1 VAR X,Y,R,G,B FOR Y = Y0 TO Y1 FOR X = X0 TO X1 RGBREAD GSPOIT(X,Y) OUT R,G,B GPSET X,Y,GRAY((R+G+B)/3) NEXT NEXT END DEF GRAY(V%) RETURN RGB(V%,V%,V%) END