TGC Codebase Backup



Picture recreation by demons breath

16th Sep 2007 5:59
Summary

This code creates a text file with all the commands to recreate an image. You then just copy all the text in the file into your programme.



Description

I created this for TDK's DBC Challenge because no external media's allowed. Turns out it's "against the spirit of the challenge" but I thought someone might find a use for it. Plus I just wanted to contribute so I could act useful :p

Please feel free to mock this if it's really as pointless as it may actually be.

It takes a while, but you get pixel-by-pixel recreation of any bitmap you load, including all the commands. it creates a text file that looks something like this...


ink 6972762,0 : dot 0,0 : ink 5393473,0 : dot 0,1 : ink 3748913,0 : dot 0,2 : ink 4863033,0 : dot 0,3 : ink 4863033,0 : dot 0,4 : ink 5394506,0 : dot 0,5 : ink 3224625,0 : dot 0,6 : ink 4274225,0 : dot 0,7
ink 3748905,0 : dot 0,8 : ink 4274225,0 : dot 0,9 : ink 5391417,0 : dot 0,10 : ink 6971722,0 : dot 0,11 : ink 6971722,0 : dot 0,12 : ink 7562578,0 : dot 0,13 : ink 8614234,0 : dot 0,14 : ink 6447434,0 : dot 0,15



... and so on and so forth...



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    cls

` these variables can be changed so you don't have to change the actual
`program so much.
targfile$ = "wallsdata.txt"
sourcepic$ = "walls.bmp"
`the size of the picture. If you go too high, then it will take ages and
`your data will take ridiculous amounts of space. Even with 16 commands per
`line, a 256*256 image will use more than 8000 lines. Use powers of two,
`because that is what most textures are anyway, so my code 
`puts data for 8 pixels onto a line. obviously if you had an image that was 
`132 pixels wide, then it would end up reading some black pixels off the side.
`(powers of 2=2,4,8,16,32,64,128,256,512,1024,2048...)
picsizex = 32
picsizey = 32

`this code checks if the text file which you want to write the file to
`exists. If it does it deletes it so you can write a new one.
if file exist(targfile$)=1
	delete file targfile$
endif

`this loads the image that you want copying and puts it onto a bitmap. This 
`slightly improves the speed I think, because having stuff on the screen
`generally seems to take longer
load image sourcepic$,1
create bitmap 1,picsizex,picsizey
paste image 1,0,0

`this is where your file is read
open to write 1,targfile$
for x=0 to (picsizex-1)
	for y=0 to (picsizey-1) step 8
		`the reason that I have 8 variables is so that the amount of lines used 
		`is minimized. Otherwise, if you have one line for each command, it would
		`take 131072 lines for a 256*256 image. It also saves time as the file
		`doesn't need to be written to so many times.
		pixeldat1$ = str$(point(x,y))
		pixeldat2$ = str$(point(x,y+1))
		pixeldat3$ = str$(point(x,y+2))
		pixeldat4$ = str$(point(x,y+3))
		pixeldat5$ = str$(point(x,y+4))
		pixeldat6$ = str$(point(x,y+5))
		pixeldat7$ = str$(point(x,y+6))
		pixeldat8$ = str$(point(x,y+7))
		cld1$ = "ink " + pixeldat1$ + ",0 : dot " + str$(x) + "," + str$(y) + " : ink " + pixeldat2$ + ",0 : dot " + str$(x) + "," + str$(y+1)
		cld2$ = " : ink " + pixeldat3$ + ",0 : dot " + str$(x) + "," + str$(y+2) + " : ink " + pixeldat4$ + ",0 : dot " + str$(x) + "," + str$(y+3)
		cld3$ = " : ink " + pixeldat5$ + ",0 : dot " + str$(x) + "," + str$(y+4) + " : ink " + pixeldat6$ + ",0 : dot " + str$(x) + "," + str$(y+5)
		cld4$ = " : ink " + pixeldat7$ + ",0 : dot " + str$(x) + "," + str$(y+6) + " : ink " + pixeldat8$ + ",0 : dot " + str$(x) + "," + str$(y+7)
		cld$ = cld1$ + cld2$ + cld3$ + cld4$
		write string 1,cld$
	next y
next x
close file 1
`the text file is now ready for you to copy all the data out into your project
delete bitmap 1
`this just tells you when the program has finished because up til this point
`you have a black screen.
center text 320,240,"finished (press any key to end)"
suspend for key
end