Heightmap editor by Atreides9th May 2004 14:38
|
---|
Summary That's a short program (140 lines) that allow you to draw the height of matrices... You cannot do another thing, but you can do it easily and fast. Description How does it works ? First, draw your heightmap with boxes (click on the greye box on the left to choose the color). To draw the boxes, click in the red square and let the mouse down. Move the cursor and release the mouse button... Easy, isn't it ? Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com set display mode 400,300,32 sync on sync rate 0 set text font "fixedsys" set text size 20 dim boxes(1000,5) color = rgb(128,128,128) do cls gosub draw if mouseclick()=1 and mousex()>9 and mousex()<41 and mousey()>21 and mousey()<277 color = point(mousex(),mousey()) endif if mouseclick()=1 and mousex()>99 and mousex()<301 and mousey()>49 and mousey()<251 rem get image startx = mousex() starty = mousey() inc b repeat cls gosub draw ink color,0 box minimum(startx,mousex()),minimum(starty,mousey()),maximum(startx,mousex()),maximum(starty,mousey()) sync until mouseclick()=0 boxes(b,1)=lim(startx,100,300) boxes(b,2)=lim(starty,50,250) boxes(b,3)=lim(mousex(),100,300) boxes(b,4)=lim(mousey(),50,250) boxes(b,5)=color endif if mouseclick()=1 and mousex()>168 and mousex()<232 and mousey()>173 and mousey()<297 goto export endif sync loop draw: ink rgb(255,0,0),0 line 99,49,301,49 line 301,49,301,251 line 301,251,99,251 line 99,251,99,51 line 9,21,41,21 line 41,22,41,277 line 41,277,9,277 line 9,277,9,21 for t=1 to b ink boxes(t,5),0 box minimum(boxes(t,1),boxes(t,3)),minimum(boxes(t,2),boxes(t,4)),maximum(boxes(t,1),boxes(t,3)),maximum(boxes(t,2),boxes(t,4)) next t box 10,22,40,277,rgb(0,0,0),rgb(255,255,255),rgb(0,0,0),rgb(255,255,255) ink color,0 box 325,125,375,175 ink rgb(255,255,255),0 center text 350,180,str$(rgbr(color)) rem 60*20, centré sur 200,275 line 168,273,232,273 line 232,273,232,297 line 232,297,168,297 line 168,297,168,273 center text 200,275,"Export" return function minimum(a as float, b as float) if a < b then exitfunction a else exitfunction b endfunction b function maximum(a as float, b as float) if a > b then exitfunction a else exitfunction b endfunction b function lim(x as float,y as float,z as float) if x < y then x = y if x > z then x = z endfunction x export: CLS set cursor 0,0 print "Drawing a bitmap..." create bitmap 1,200,200 for t=1 to b ink boxes(t,5),0 box minimum(boxes(t,1)-100,boxes(t,3)-100),minimum(boxes(t,2)-50,boxes(t,4)-50),maximum(boxes(t,1)-100,boxes(t,3)-100),maximum(boxes(t,2)-50,boxes(t,4)-50) next t ink rgb(255,255,255),0 set current bitmap 0 print "Done." input "Tiles on X axis> ",tilesx input "Tiles on Z axis> ",tilesz print "Thank you." print "Now, we need to blur the bitmap." print "When you think it has been enough" print "blured, press returnkey." print "When you're ready, press any key." repeat sync until scancode()>0 and returnkey()=0 clear entry buffer repeat cls blur bitmap 1,5 set current bitmap 1 get image 1,0,0,200,200 set current bitmap 0 paste image 1,100,50 sync until asc(right$(entry$(),1))=13 cls name as string print "It is done. The matrix is written." print "Write the name of the file where" print "you want to save the matrix" input ">",name if file exist(name)=1 then delete file name print "Building the map ..." sync set current bitmap 1 open to write 1,name write file 1,tilesx write file 1,tilesz for x=1 to 200 step (200/tilesx) for z=1 to 200 step (200/tilesz) write file 1,rgbr(point(x,z)) next z next x set current bitmap 0 close file 1 REM X-X-X-X-X-X-X-X-X-X-X REM HERE BEGINS THE CODE TO REM OPEN A MATRIX open to read 1,name read file 1,tx read file 1,tz make matrix 1,1000,1000,tx,tz for x=1 to tx for z=1 to tz read file 1,h set matrix height 1,x,z,h next z next x update matrix 1 debug = mousemovex()-mousemovey() do xrotate camera wrapvalue(camera angle x()+mousemovey()) yrotate camera wrapvalue(camera angle y()+mousemovex()) move camera upkey()-downkey() sync loop |