Metaballs? I'd call them "Blobs"
	
	People emailed me to write a tutorial about stuff/effects they saw in my "mono and disco" QB demo.  Most of which regarding Plasmas, 3d and Blobs.  As I've already finished writing the plasma article, and discussing 3d in layman's tern would involve me dicussing polar coordinates and Trig Identities, I am writing a tutorial on how to model 2d blobs as it would require less space. ;*)

I. Illumination
	Illumination is how light behaves proportional to its distance from the center.
ie:
Intensity=1/distance

	Which means that the Intensity of light is *inversely* proportional to its distance from the lightsource.  So the farther the coordinate from the center of the lightsource the darker it gets.  If you don't believe me, try to point a flashlight on a dark area. ;*)

II. Preparing the LightMap
	First you have to make a lightmap.  A lightmap is a map/table of illumination.  We sould use the above formula in making the lightmap. Say we want to have a 64*64 Lightmap (you could use an size that will fit your purpose), we wan't to fill that table with values derived from our illumination formula. As we are using screen 13, which has 256 colors (0-255), our value for MAXCOLOR would be 255. You'll notice that the image of the Lightmap is curved/quadratic:

<Lmap1.Gif>
	This is what our lightmap would look like if plotted on the screen.  But this lightmap, although mathematically sound, won't look very good for our blobs.  What we wan't is a more linear lightmap like this:
<Lmap2.Gif>

	Trust me on this,  the second one would look way cooler.  You could develop your own formula if you want, as long as it follows the concept of inverse proportion. Here's the QB code to generate both Lightmaps:

<TestLite.BAS>

III. The Algorithm

	Now that we have decided what lightMap to use, we can start making our blob render.  The algo is actually very simple it hurts. ;*) Blobs are made when lightmaps "overlap".

[Pseudo code}
1. Decide where you want to put a
 	blob.
2. Read your lightmap sequentially
3. Check if the lightmap contains a
 	color.
3. If it contains a color other than
 	0, Check the color of the
 	the particular pixel on the
 	screen.
4. Add both colors together
5. Limit the color to the maximum
 	color.
6. Plot the summed-up colors to
 	screen. 
[end pseudo code]

	See, pretty elementary.  If you want QB code here it is:

[code]
SUB DrawBlob (bx%, by%)

    FOR y% = 0 TO 64
    FOR x% = 0 TO 64
        c% = Light%(x%, y%)
        IF c% THEN
            oc% = POINT(x% + bx%, y% + by%)
            occ% = c% + oc%
            IF occ% > 255 THEN
                occ% = 255
            END IF
            PSET (x% + bx%, y% + by%), occ%
        END IF
    NEXT x
    NEXT y

END SUB

[end code]

	It is very important that you clear the screen to blank after every frame to make the display right.  Now that we know how to generate blobs, we would want to see it in action.  To do those cool movements, use what you have learned in HighSchool algebra/Trig. Ie. Polar coordinates or vectors.

Here's the complete commented code:

<Blob.BAS>

<Blob1.GIF><Blob2.GIF><Blob3.GIF>

IV.  Appendix

	Yes, I got mine removed already. Oops!!!!  If you already have read my articles on QBCM issues prior to this, you already know how to generate realtime plasmas and you could combine both effects in one as in this example:

<BlobPlas.Bas>
<BlobPlas.Gif>


V.  Disclaimer

	Who cares? ;*)  I want to have  some feedback regarding this article or the others that I have written.  I'm accepting requests as to what to write next. And remember. You are only limited by your imagination. ;*)


Relsoft 2003
vic_viperph@yahoo.com
rel.betterwebber.com



