Triangle MozaicThis is a way of creating a mozaic of triangles (instead of the usual squares) from a given image. The right image is the result of processing the left image with the code below. |
![]()
|
rem rem This is an example of image manipulation software written in Basic rem using the freeware Macintosh METAL basic interpreter. rem rem This program creates a mozaic from a given image. Instead of identical rem squares of fixed color, this program uses triangles (just those traditional rem squares sliced diagonally). Very simple, but nice result. rem rem Metal seems to have a problem with very large images, so try this on rem relatively small ones, say 600 x 500 or smaller. rem rem Matthew M. Conroy, 2001. rem Do whatever you want to with this code, especially improve it. rem file$ = open preview dialog$ get quicktime pict size file$,picW,picH resize console 20,50,picW+20,picH+50 load quicktime pict file$ virtu = init screen (0,0,picW+0,picH+0) set screen to virtu cls copyrect 0,0,picW,picH,0,0,picW,picH,0,0,virtu set screen to console cls squareSize=10 xLim = int(picW/squareSize) yLim = int(picH/squareSize) for i=0 to xLim-1 for j=0 to yLim-1 redSum=0: greenSum=0: blueSum=0 redSum2 = 0: greenSum2 = 0: blueSum2 =0 set screen to virtu rem ***** do upper triangles for x = i*squareSize+1 to (i+1)*squareSize for y = j*squareSize+1 to j*squareSize+1+x-i*squareSize-1 get pixel x,y,red,green,blue redSum= redSum+red greenSum = greenSum + green blueSum =blueSum + blue next y next x meanRed = 2*redSum/((squareSize+1)*(squareSize+1)) meanGreen = 2*greenSum/((squareSize+1)*(squareSize+1)) meanBlue = 2*blueSum/((squareSize+1)*(squareSize+1)) for x = i*squareSize+1 to (i+1)*squareSize for y = j*squareSize+1 to j*squareSize+1+x-i*squareSize-1 set screen to console forecolor meanRed, meanGreen, meanBlue plot x,y next y next x rem **** do lower triangles redSum=0: greenSum=0: blueSum=0 for x = i*squareSize+1 to (i+1)*squareSize for y = j*squareSize+1+((x-i*squareSize-1)) to (j+1)*squareSize set screen to virtu get pixel x,y,red,green,blue redSum= redSum+red greenSum = greenSum + green blueSum =blueSum + blue next y next x meanRed = 2*redSum/((squareSize+1)*(squareSize+1)) meanGreen = 2*greenSum/((squareSize+1)*(squareSize+1)) meanBlue = 2*blueSum/((squareSize+1)*(squareSize+1)) for x = i*squareSize+1 to (i+1)*squareSize for y = j*squareSize+1+((x-i*squareSize-1)) to (j+1)*squareSize set screen to console forecolor meanRed, meanGreen, meanBlue plot x,y next y next x next j next i |
|
back |