'=========================================================================== ' Subject: SPRITE MASK MAKER Date: 12-14-97 (17:05) ' Author: Bert van Dam Code: QB, QBasic, PDS ' Origin: bd1rsd@usa.net Packet: GRAPHICS.ABC '=========================================================================== 'Here's another program for the abc's. It will take a sprite and 'autoamtically generate a masking for it. Then you can see a (silly) example 'on how to make an animation using the mask, with preservation of the 'background, and use of vertical retrace. The mask itself can be saved to 'file for use in other programs. Not very spectacular but if you're new to 'animation (such as myself) this will clearify a lot. '-----------------beginning of source code--------------------- 'Mask Maker produces masks to mask colors in animations dec 1997 'Program by Bert van Dam, donated to the public domain. I can be reached 'at Fido 2:285/750.16 or the internet BD1RSD@USA.NET 'The masking technique is based on the program MASK.BAS by Dave Shea 'which was donated to the public domain on January 19th, 1997, 'adapted for use with screen 9 (needed for reasonable resolution with '2 screen pages) and for sprites which are designed with the SHAPE 'sprite designer. 'The mask can be saved to data lines, which can be merged into another 'program, an example is maskdemo.bas 'The animation demo uses a separate array to preserve the background. To 'prevent flicker drawing waits for the video retrace. The way to do this 'is from a mail by Steve Gartrell. CLS SCREEN 9 Elem = 385 'These dimensional parameters are generated x = 64 'by the sprite designer SHAPE and recorded y = 48 'in rem statements near the data DIM Rups(Elem - 1) AS LONG 'DIM the array to hold the sprite DIM Mask(Elem - 1) AS LONG 'Do the same for the mask array 'and dim an array to preserve the 'background DIM Preserve(Elem - 1) AS LONG TCol = 0 'Color you want to be transparent MCol = 15 'Mask color, this must be 'a color that is not used in 'the background nor the sprite FOR i = 0 TO Elem - 1 'Read the sprite into the array READ Rups(i) NEXT i PUT (1, 1), Rups 'and put it on the screen on 1,1 LOCATE 20, 1 PRINT "---===[ MASK MAKER ]===--- Masking in progress...." FOR a = 1 TO x FOR b = 1 TO y 'The following commands search the sprite, and 'change any pixel that's NOT the transparent 'color to the transparent color, and any pixel 'that IS the transparent color to the mask color '(This is the masking process) IF POINT(a, b) = TCol THEN PSET (a, b), MCol IF POINT(a, b) <> TCol AND POINT(a, b) <> MCol THEN PSET (a, b), TCol NEXT NEXT GET (1, 1)-(x, y), Mask 'Get the mask for the sprite LOCATE 20, 1 PRINT SPC(70); LOCATE 20, 1 PRINT "Would you like to see the result (y/n)? "; Answer$ = INPUT$(1) PRINT Answer$ IF UCASE$(Answer$) = "Y" THEN CLS FOR a = 1 TO 100 'Draw some lines for a background LINE (a + 80, 80)-(a + 80, 150), a / 6 NEXT PUT (100, 90), Mask, AND 'Lay down the mask using AND PUT (100, 90), Rups, XOR 'Lay down sprite using XOR END IF LOCATE 20, 1 PRINT "Would you like write the mask to disk as data statements (y/n)? "; Answer$ = INPUT$(1) PRINT Answer$ IF UCASE$(Answer$) = "Y" THEN LINE INPUT "Filename (incl. extension and path) "; FileName$ OPEN FileName$ FOR OUTPUT AS #1 PRINT #1, "'Mask generated with the MaskMaker" PRINT #1, "'Elem = "; Elem PRINT #1, "'x = "; x PRINT #1, "'y = "; y PRINT #1, Regel = 0 FOR i = 0 TO Elem - 1 IF Regel MOD 5 = 0 THEN PRINT #1, PRINT #1, "DATA "; Mask(i); ELSE PRINT #1, " , "; Mask(i); END IF Regel = Regel + 1 NEXT i CLOSE #1 END IF LOCATE 21, 1 PRINT SPC(70); LOCATE 20, 1 PRINT "Would you like to see an animation using the newly generated mask (y/n)? "; Answer$ = INPUT$(1) PRINT Answer$ IF UCASE$(Answer$) <> "Y" THEN END CLS FOR a = 1 TO 600 'Draw some lines for a background LINE (a, 1)-(a, 250), a / 39 NEXT LOCATE 22, 1 PRINT "Animation demo using the new mask and video retrace timing..." DEF SEG = &HA000 'Define video segment FOR xp = 1 TO 260 STEP 2 'Save the background GET (xp * 2, 90)-(xp * 2 + x - 1, 90 + y - 1), Preserve WAIT &H3DA, 8, 8 'Wait till _start_ of vertical retrace WAIT &H3DA, 8 'method by Steve Gartrell 'Draw mask and sprite PUT (xp * 2, 90), Mask, AND PUT (xp * 2, 90), Rups, XOR 'Wait a bit FOR t = 1 TO 200: NEXT t WAIT &H3DA, 8, 8 'Wait till _start_ of vertical retrace WAIT &H3DA, 8 '(method by Steve Gartrell) 'Put the background back to erase the sprite PUT (xp * 2, 90), Preserve, PSET NEXT xp END Rups: 'Designed using SHAPE sprite maker 'ELEM: 385 X: 64 Y: 48 DATA 3145792 , 0 , 0 , 0 , 0 , 0 DATA 0 , 0 , 0 , 0 , 0 , 0 DATA 0 , 0 , 0 , 0 , 0 , 0 DATA 0 , 0 , 0 , 0 , 0 , 0 DATA 0 , 0 , 0 , 0 , 0 , 0 DATA 0 , 0 , 0 , 0 , 0 , 0 DATA 0 , 0 , 0 , 0 , 0 , 0 DATA 0 , 0 , 0 , 0 , 0 , 0 DATA 0 , 0 , 0 , 0 , 0 , 0 DATA 0 , 0 , 0 , 0 , 0 , 0 DATA 0 , 0 , 0 , 0 , 0 , 0 DATA 0 , 0 , 0 , 0 , 0 , 0 DATA 0 , 0 , 0 , 0 , 0 , 0 DATA 0 , 0 , 0 , 0 , 0 , 0 DATA 0 , 0 , 0 , 0 , 0 , 0 DATA 0 , 0 , 0 , 0 , 0 , 0 DATA 0 , 0 , 0 , 0 , 0 , 0 DATA -2139095040 , 0 , 0 , 0 ,-2134835200 , 0 DATA -2134835200 , 0 ,-2134835200 , 0 , 0 , 0 DATA 6488064 , 0 , 6488064 , 0 , 6488064 , 0 DATA 0 , 0 , 2228224 , 0 , 2228224 , 0 DATA 2228224 , 0 , 0 , 0 , 2228224 , 471604224 DATA 4070428 , 0 , 2228224 , 0 , 0 , 0 DATA 0 , 1044266496 , 4079166 , 0 , 0 , 0 DATA 0 , 0 , 1310720 , 2139062016 , 7044991 , 0 DATA 0 , 0 , 0 , 0 , 0 ,-33024 DATA 16777215 , 0 , 0 ,-2139095040 , 8421504 , 0 DATA 0 , 2139062016 , 7044991 , 0 , 1310720 , 0 DATA 0 , 0 , 0 , 1044266496 , 3554878 , 0 DATA 524288 , 0 , 0 , 0 , 0 , 471604224 DATA 1842204 , 0 , 0 , 0 , 0 , 0 DATA 0 , 0 , 0 , 0 , 0 , 0 DATA 0 , 0 , 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