GRAPHICS IN QBASIC TUTORIAL (PART 3), by "Hacker" aka Damian Nikodem Hacker@alphalink.com.au

Intro :
Today I will cover RANDOMIC ALGORITHMS. You will probably be asking yourself what are they and how will they improve the graphics in my programs. Well randomic algorythms add a twist of reality to your graphics. Take a look around you is everything around you in total order is there NO light shining off ANYTHING near you. If you notaice nearly everything has a random element. So this is where I will base my tutorial on today.

Grass Routine:
Now lets just say that your writing a RPG and you have to write a graphics routine. It most likeley looks kinda like this (asuming you are doing a 15x15 tileset)

'Start CODE
SCREEN 13
LINE (1,1)-(15,15),2 , BF
'END CODE

Well try this little program instead [ 12-rnd1.bas ]

'Start CODE
SCREEN 13
RANDOMIZE TIMER
FOR x = 1 TO 15
FOR y = 1 TO 15
z = INT(RND * 2) + 1
IF z = 2 THEN z = 10
IF z = 1 THEN z = 2
PSET (x, y), z
NEXT y
NEXT x
'END code

Does that look a bit better? It should. But its still missing something isnt it, it dosent have enough colors. Because we are using VGA mode 13h(Screen 13) we have 255 colors to play with theres bound to be at least 1 GREEN! WAIT. there is also dirt on the ground so we have to add BROWN and if you look almost always there is about 2 browns before a green so here is a small EDIT of the program above [ 12-rnd2.bas ]

'Start CODE
SCREEN 13
RANDOMIZE TIMER
FOR x = 1 TO 15
FOR y = 1 TO 15
z2 = INT(RND * 8) + 1
z = z2 + 186
PSET (x, y), z
NEXT y
NEXT x
'End CODE

Now do you see the benifits of randomized graphics. If you downloaded quake2 unzip it and play it. While you are doing that take a look at some of the graphics they look fuzzy (Unless you have a 3d card). If the graphics werent fuzzy they would look hopeless. Because of the time that it would take to "smooth" the graphic. So if you have some kind of graphic that dosent look quite right try stuffing around with the colors for a bit if done properly it will look ok if not good.

This is the end of what is going to be the last tutorial in this series because I dont have enough time to write them. But eventually I might be able to write another tutorial series on sound or even 3d calculations (pick up
where the other guys one left off)

- Hacker (Hacker@alphalink.com.au)





This article originally appeared in The BASIX Fanzine Issue 12 from October 1998.