This is a tutorial to help you to get started with drawing blobby objects using simple Max2D commands.
Normally when you draw an image on the screen you see it as it is, pixel for pixel. If it were an image of a sphere you would simply paste it down and you would then see a sphere on the screen. The shape of it doesn't change because its appearance is fixed in place already - stored in the pixels. Adding more spheres doesn't change the shape of each one.
The difference with blobby objects is that their shape, which starts out usually as a sphere, changes depending on how close the objects are to each other. Two objects can go from being completely separate to completely unified - appearing to be one. Blobby objects are cool!
If you draw more than one blobby sphere and they are close enough together, they start to influence each other. As they approach they begin to bulge in the direction of each other as if being sucked together by gravity. As the shapes get even closer they eventually begin to merge together as one shape with a smoothly curved surface. You can adequately describe that shape as a `blob`, hense the name. If the objects end up in exactly the same location they form one single larger sphere as representative of their final union. Sometimes blobby objects are called metaballs because that describes them well also - a ball that is more than just a ball.
You can think of each individual blob as being an atom with an electrical energy field around it. The closer to the atom you get the stronger the energy field is. The circular shape of an actual atom is usually produced by electrons orbiting it at such a high speed that the `blur` of movement gives the impression of a sphere. As the atoms get closer to each other this apparent shape deforms as the electrons start to be affected by the pull of the other nearby atoms. Eventually the electrons start to break out of the orbit of the original atom and circle the other atom for a while, maybe moving back and forth. This creates more of a `blob`. This is why blobby objects are often used in science to model the behavior of atoms and molecules (and it's a handy metaphor).
The question for us is how can we draw these constantly flexible shapes on the screen and make them interact when they get close. Another big question that seems to arise is how to draw the shapes with nice smooth curves, and to do it fast.
There have been a number of algorithms invented to render blobby objects. The most well known is the `marching cubes` algorithm. You can read up more about it on the web. It has a patent attached so we can't very well use it (figures).
However, certain individuals have produced spinoffs such as marching triangles and other base shapes which are more accessible. The basic idea of the algorithm is to subdivide a given set of `atoms` and their combined energy fields into cubes. You then work out, on increasingly small levels, where within the cube a polygon should be generated perpendicular to the surface of the energy field. You needn't worry about understanding how that works, because we won't be using it. It's usually used to generate 3D polygon meshes with a specific level of detail which can be rendered on 3D hardware.
Most commonly a polygon will be generated by these algorithms at any location where the energy-field's intensity is at about half strength. This is referred to as a threshold. Since the algorithm needs to be aware of all the possible locations where the energy it at this `threshold` of half strength, a lot of computation is involved, especially working in 3D. One of the prime uses for blobby objects therefore is to model organic shapes in 3D, and is a feature of higher-end 3D modelling software. For the most part it is hard to do it usefully in realtime - hense its appearance as a demo effect produced by highly specific, hardwired code.
What we are interested in first of all is taking a look at the combined energy fields of several blob objects, or atoms. Imagine several atoms hanging in the air near to each other. They are emitting energy fields of a given strength which dissipates with distance. Where any two atoms are near to each other the energy fields overlap and add their strength together. Where they overlap, the strength of the energy at that location is the sum total of contributions from both energy fields.
What you want to work out first of all is, given the location of all the atoms, how much energy emission there is at every location. Obviously in 3D that is a lot of locations. In 2D things are simpler, and especially since we are dealing with a limited number of pixels on a screen. So we just want to know what this energy field looks like on a per-pixel basis.
Traditional algorithms, like the marchine cubes, has a lot of math going on to work out where the energy field is. Since it usually deals with 3D it has to take a 3D grid of points of a particular resolution and work out the energy field at each point - actually where along the edge of each side of each cube the energy field is at a specific strength. It usually does this with various formulas and, in the case of the marching algorithm, it tries to refer to a certain number of possible permutations of results in order to optimize things. But all of this has to be calculated by the CPU.
Since we are going to create 2D blobby objects, we want to know what the combined energy field looks like in 2D. We are basically going to start off by actually drawing an image of the energy field in grayscale (shades of gray).
All we need to do is draw the energy field of each atom and make sure that where they overlap, the energy from each contributing atom is added together. Since we are only working in 2D and figuring out the points on our `mesh` in one step, each individual pixel can be used to represent a location in the energy field. We are taking a simple 2D cross section - a snapshot of a slice of the energy surrounding all these atoms.
Instead of using some 2D array to store the energy field, or using math to work it out in realtime, we're going to use an image on the screen. A screen is basically an array of data, it just happens to be turned into colors by the display hardware depending on the value of the data. And the joyful thing is this: Because we're treating it as an image, we can get the GPU (graphics processing unit) of your graphics card involved. GPU=visual speed.
In BlitzMax, there are several rendering modes which allow you to draw images in different ways. You set what mode you want using `SetBlend`. Usually you would draw an image as solid, using SOLIDBLEND which is the default. With SOLIDBLEND, the content of the source image totally replaces the content of the screen. What we are interested in for our purposes is our trusty friend, LIGHTBLEND! This is simply an `add` mode. It performs a mathematical addition of the value of each source pixel and the value of each screen pixel. When the sum of the two pixels gets to be more than 255 (in color), or 1.0 (in floating point color), or white, the color just gets turned into white. So we can use the LIGHTBLEND mode to handle the overlapping parts of each energy field. It also doesn't hurt to use LIGHTBLEND where there is no overlap - since it would be drawing onto a black background it will just draw that part of the energy field as if drawn with SOLIDBLEND.
So we can use LIGHTBLEND to combine the energy fields of each atom. We will also be using a simple call to `DrawImage`to draw each individual atom's energy. We will store a pre-calculated 2D image of an atom's energy field in our Image object. The precalculation of that image is an important factor in allowing us to have enough time, at runtime, to generate the blobby objects with enough speed. If we had to generate every single energy field, and combine them, all in realtime, that would be a lot more work.
So the question now is how to generate the energy field of an atom, and draw it as a grayscale image. Well, like I said earlier, the further away you get from the atom the less strength the energy field has. The energy field, therefore, is basically a ball with decreasing density the further you get away from the center. The center is the hotspot and the outer edges of the area are almost non-existant. What we're going to do is draw each energy level as a different color, and since we're working in grayscale we will use 256 shades of gray.
To draw the energy field of one atom is pretty simple, you would think. All you have to do is start of by setting the color to black and drawing a large circle equal to the size of the energy field. Then you just keep repeating that in a loop making the circle smaller and smaller each time, increasing the color by adding 1 to it (to Red Green and Blue equally). What you end up with is a sphere with a gradient of gray colors fading out the further away you get from the center. It looks like this:

If we grab this into an `Image`, and then draw it more than once to represent two atoms, we get this:

You'll notice that this does not exactly give us a blobby object. While the energy field areas do overlap and are added together, there is no smoothly curved surface being produced. This is made all the more evident by hiliting some of the `bands` that are the same color in a contrasting color, as follows:

Here you can see what kind of shape is actually being produced. A `bridge` is seemingly formed between the two energy fields, but it is not very curvacious. In fact, it's almost totally straight. Why? This straightness is a direct result of even incrementation of color in our source image. Since we drew circles that increased in brightness by `1` at every diameter, this produces a completely `linear` gradient as shown in the ball image above. The amount of change in this gradient is shown below:

As the color progresses from black to white, it is incremented in steady steps proportional to the diameter of the circles being drawn. It is because of this `linear` gradient that we get the effect of a straight bridge between the two composite energy fields. The energy fields do, technically, combine, and they do form a connection between them when they get close, but the connection is a sudden immediate bridge between them with a width directly proportional to their proximity. It's not very useful as a representation of blobby objects.
What we need to do is generate a curved surface. We want our two objects to interact with a nice gradual `approach` so that a smooth curve is formed, and not all at once. To do this we simply need to modify the shape of the gradient, it has to be a curve rather than linear. What this means is, for each circle that we draw in a shade of gray, instead of incrementing the shade by 1 for each circle we have to slowly accelerate the rate of incrementation over the course of the circles.
A curved gradient is similar to suggesting that our atom, with its energy field, is much harder to escape from when you are close to it, but the further from it you get the easier it becomes. When you are close to the center there isn't much difference in the strength of the gravity, but the further away you get the less it pulls.
Drawing a curved gradient is included in the sourcecode below. Basically what we do for blobby objects is increase our color intensity based on a curve produced by squaring a number by itself (rather than just adding a number to itself.) When the number is small, the curve obviously doesn't move much but as it increases the curve gets increasingly curvy. It ends up looking like this:

And when you've drawn the actual energy field of one atom, it looks like this:

If you compare this to the original linear image, you'll notice not only that the overal brightness seems a lot less but also there is more of a `peak` of brightness nearer the center. The brightness quickly falls away and then you're left with a gradually decreasing amount of dimming the further you get. This is the ideal shape for our blobby objects and the way that they need to interact with each other.
The side effect of generating an image with this kind of curved gradient is that the curvature directly translates to the way that the intensities of the energy fields combine. When you draw several of these images in LIGHTBLEND, where their values are added together, it forms not only smoothly curved shapes but also different degrees of curvature based on proximity. With the linear gradient we get a sudden total switching on of the `bridge` between the two atoms, whereas with a curved gradient we get different amounts of bulging.
So, drawing two curved-gradient energy fields, added together, we get this:

Now, it doesn't look a whole lot different at first glance to the original linear combination. But if you take a look at what is happening here you will notice there are actually completely smooth curves at every energy intensity level. We can hilite these again by showing some of these intensities with a contrastsing color:

As you can see, the energy field actually is forming proper blobby object perimeters. Areas closer to each atom have not yet `blobbed out` since they are out of reach of the influence of each other. But the parts of the energy field that do influence each other (by overlapping) begin to bulge toward each other and unify. Solely because of our curved gradient we get a curved shape instead of a rectangular shape.
There you have it, blobby objects rendered on-screen!
The great thing is, this is actually a very very simple technique compared with the marching cubes algorithm. It is especially great that we are doing all the `processing` using image data and even more great that we can therefore use hardware acceleration to perform all the computation. The simple combination of a pre-rendered energy field using the correct curvature of the gradient, along with an additive blend mode, gives us blobby objects.
There are other curves of gradient that can be used based on other formulae. The number*number formulae is the simplest and produces standard blobby objects. Other formulas produce perhaps flatter curves, or accentuate the area nearer the middle. Changing the curves in these ways can make the blobs appear to be more `sticky` or more reluctant to disconnect, so that when they do disconnect they seem to `snap back` into place more quickly.
The main idea of producing blobby objects is that you first of all generate the combined energy fields - officially known as an `isosurface` - and then you interpret that surface by rendering only at a certain threshold. In my example above I simply took a paint program, a flood fill tool with a treshhold of 5 pixel values, and clicked on the image in several places. What this shows you is that if you vary the threshold you vary how much energy needs to be present in order to make a perimeter.
Usually blobby objects will be drawn in this way, rendering only the pixels that have values of, say, between 120 and 140. This would produce a single `band` around all the blobs.
In this tutorial I am just showing you the basics of how to generate some blobby objects. What you need to do next is take the data that is generated - ie the resulting image on your screen, and find ways to manipulate that image to produce an effect that you like. In its more advanced incarnation I have taken this basic BlitzMax program and converted everything to direct OpenGL programming. This allows me to set up some blend modes and operations which are not currently implemented as part of Max2D. I use these additional modes to cover the screen several times with a filled rectangle, where each pass performs some `math` on the pixel color. The end result is that you can get bands of color to form.
In this tutorial example, there is an inbuilt threshold of 255 whereby, any areas that contain energy intensity at 255 simple remain that color. It never gets any brighter. You can use this fact and with a little further manipulation/post-processing let your blobs be formed only by the white pixels. In addition you can draw a rectangle over the whole screen in LIGHTBLEND mode with a color of $80,$80,$80 (mid-gray), which will cause the treshold to be formed at half-strength energy levels rather that at the white level. With a bit of clever manipulation you can come up with something looking like this:

So far all we've done is use a spherical energy field. You may have noticed we are now working with images here, and an image of a spherical energy field is precalculated before being used. For your further enjoyment you may wish to save that image and load it into your favorite graphics package. There is absolutely nothing stopping you from performing image processing functions on that image and then loading it into the blob-rendering routine. It only has to be loaded once at the start instead of generating the blob image from scratch. There are many interesting ways you can warp, twist and otherwide deform the basic blob image. When it comes to rendering it in the blob program, blobs will still be formed as before - combining and merging based on proximity - but now the energy field is simply a different shape. This can make for some pretty interesting effects!
There's also nothing stopping you from adding a `tint` to each image that you render, by using `SetColor` for each one. You will find that individual blobs form in each of the separate Red, Green and Blue channels, and that their shapes will overlap without interacting, as in the above image.
Have fun, play around with it. You can add as many blob objects to the screen as you like, this `algorithm` supports an unlimited number of combinations at no extra charge. ....... <- get it, *extra charge* ..... electrical fields,..... *ahem*.
I hope this has been clear and understandable. Feel free to ask questions.
The very simple final sourcecode is below, no strings attached. As it stands it generates blob fields that occupy a 512x512 space. It can also do 256x256 and 128x128, but any size other than that you'll have to work out the balldivider and lineardivider values - I'm sure there is a formulae that would generate them properly but I couldn't figure it out.
Please see below for part two of this tutorial :-)
Regards, AngelDaniel.
Normally when you draw an image on the screen you see it as it is, pixel for pixel. If it were an image of a sphere you would simply paste it down and you would then see a sphere on the screen. The shape of it doesn't change because its appearance is fixed in place already - stored in the pixels. Adding more spheres doesn't change the shape of each one.
The difference with blobby objects is that their shape, which starts out usually as a sphere, changes depending on how close the objects are to each other. Two objects can go from being completely separate to completely unified - appearing to be one. Blobby objects are cool!
If you draw more than one blobby sphere and they are close enough together, they start to influence each other. As they approach they begin to bulge in the direction of each other as if being sucked together by gravity. As the shapes get even closer they eventually begin to merge together as one shape with a smoothly curved surface. You can adequately describe that shape as a `blob`, hense the name. If the objects end up in exactly the same location they form one single larger sphere as representative of their final union. Sometimes blobby objects are called metaballs because that describes them well also - a ball that is more than just a ball.
You can think of each individual blob as being an atom with an electrical energy field around it. The closer to the atom you get the stronger the energy field is. The circular shape of an actual atom is usually produced by electrons orbiting it at such a high speed that the `blur` of movement gives the impression of a sphere. As the atoms get closer to each other this apparent shape deforms as the electrons start to be affected by the pull of the other nearby atoms. Eventually the electrons start to break out of the orbit of the original atom and circle the other atom for a while, maybe moving back and forth. This creates more of a `blob`. This is why blobby objects are often used in science to model the behavior of atoms and molecules (and it's a handy metaphor).
The question for us is how can we draw these constantly flexible shapes on the screen and make them interact when they get close. Another big question that seems to arise is how to draw the shapes with nice smooth curves, and to do it fast.
There have been a number of algorithms invented to render blobby objects. The most well known is the `marching cubes` algorithm. You can read up more about it on the web. It has a patent attached so we can't very well use it (figures).
However, certain individuals have produced spinoffs such as marching triangles and other base shapes which are more accessible. The basic idea of the algorithm is to subdivide a given set of `atoms` and their combined energy fields into cubes. You then work out, on increasingly small levels, where within the cube a polygon should be generated perpendicular to the surface of the energy field. You needn't worry about understanding how that works, because we won't be using it. It's usually used to generate 3D polygon meshes with a specific level of detail which can be rendered on 3D hardware.
Most commonly a polygon will be generated by these algorithms at any location where the energy-field's intensity is at about half strength. This is referred to as a threshold. Since the algorithm needs to be aware of all the possible locations where the energy it at this `threshold` of half strength, a lot of computation is involved, especially working in 3D. One of the prime uses for blobby objects therefore is to model organic shapes in 3D, and is a feature of higher-end 3D modelling software. For the most part it is hard to do it usefully in realtime - hense its appearance as a demo effect produced by highly specific, hardwired code.
What we are interested in first of all is taking a look at the combined energy fields of several blob objects, or atoms. Imagine several atoms hanging in the air near to each other. They are emitting energy fields of a given strength which dissipates with distance. Where any two atoms are near to each other the energy fields overlap and add their strength together. Where they overlap, the strength of the energy at that location is the sum total of contributions from both energy fields.
What you want to work out first of all is, given the location of all the atoms, how much energy emission there is at every location. Obviously in 3D that is a lot of locations. In 2D things are simpler, and especially since we are dealing with a limited number of pixels on a screen. So we just want to know what this energy field looks like on a per-pixel basis.
Traditional algorithms, like the marchine cubes, has a lot of math going on to work out where the energy field is. Since it usually deals with 3D it has to take a 3D grid of points of a particular resolution and work out the energy field at each point - actually where along the edge of each side of each cube the energy field is at a specific strength. It usually does this with various formulas and, in the case of the marching algorithm, it tries to refer to a certain number of possible permutations of results in order to optimize things. But all of this has to be calculated by the CPU.
Since we are going to create 2D blobby objects, we want to know what the combined energy field looks like in 2D. We are basically going to start off by actually drawing an image of the energy field in grayscale (shades of gray).
All we need to do is draw the energy field of each atom and make sure that where they overlap, the energy from each contributing atom is added together. Since we are only working in 2D and figuring out the points on our `mesh` in one step, each individual pixel can be used to represent a location in the energy field. We are taking a simple 2D cross section - a snapshot of a slice of the energy surrounding all these atoms.
Instead of using some 2D array to store the energy field, or using math to work it out in realtime, we're going to use an image on the screen. A screen is basically an array of data, it just happens to be turned into colors by the display hardware depending on the value of the data. And the joyful thing is this: Because we're treating it as an image, we can get the GPU (graphics processing unit) of your graphics card involved. GPU=visual speed.
In BlitzMax, there are several rendering modes which allow you to draw images in different ways. You set what mode you want using `SetBlend`. Usually you would draw an image as solid, using SOLIDBLEND which is the default. With SOLIDBLEND, the content of the source image totally replaces the content of the screen. What we are interested in for our purposes is our trusty friend, LIGHTBLEND! This is simply an `add` mode. It performs a mathematical addition of the value of each source pixel and the value of each screen pixel. When the sum of the two pixels gets to be more than 255 (in color), or 1.0 (in floating point color), or white, the color just gets turned into white. So we can use the LIGHTBLEND mode to handle the overlapping parts of each energy field. It also doesn't hurt to use LIGHTBLEND where there is no overlap - since it would be drawing onto a black background it will just draw that part of the energy field as if drawn with SOLIDBLEND.
So we can use LIGHTBLEND to combine the energy fields of each atom. We will also be using a simple call to `DrawImage`to draw each individual atom's energy. We will store a pre-calculated 2D image of an atom's energy field in our Image object. The precalculation of that image is an important factor in allowing us to have enough time, at runtime, to generate the blobby objects with enough speed. If we had to generate every single energy field, and combine them, all in realtime, that would be a lot more work.
So the question now is how to generate the energy field of an atom, and draw it as a grayscale image. Well, like I said earlier, the further away you get from the atom the less strength the energy field has. The energy field, therefore, is basically a ball with decreasing density the further you get away from the center. The center is the hotspot and the outer edges of the area are almost non-existant. What we're going to do is draw each energy level as a different color, and since we're working in grayscale we will use 256 shades of gray.
To draw the energy field of one atom is pretty simple, you would think. All you have to do is start of by setting the color to black and drawing a large circle equal to the size of the energy field. Then you just keep repeating that in a loop making the circle smaller and smaller each time, increasing the color by adding 1 to it (to Red Green and Blue equally). What you end up with is a sphere with a gradient of gray colors fading out the further away you get from the center. It looks like this:

If we grab this into an `Image`, and then draw it more than once to represent two atoms, we get this:

You'll notice that this does not exactly give us a blobby object. While the energy field areas do overlap and are added together, there is no smoothly curved surface being produced. This is made all the more evident by hiliting some of the `bands` that are the same color in a contrasting color, as follows:

Here you can see what kind of shape is actually being produced. A `bridge` is seemingly formed between the two energy fields, but it is not very curvacious. In fact, it's almost totally straight. Why? This straightness is a direct result of even incrementation of color in our source image. Since we drew circles that increased in brightness by `1` at every diameter, this produces a completely `linear` gradient as shown in the ball image above. The amount of change in this gradient is shown below:

As the color progresses from black to white, it is incremented in steady steps proportional to the diameter of the circles being drawn. It is because of this `linear` gradient that we get the effect of a straight bridge between the two composite energy fields. The energy fields do, technically, combine, and they do form a connection between them when they get close, but the connection is a sudden immediate bridge between them with a width directly proportional to their proximity. It's not very useful as a representation of blobby objects.
What we need to do is generate a curved surface. We want our two objects to interact with a nice gradual `approach` so that a smooth curve is formed, and not all at once. To do this we simply need to modify the shape of the gradient, it has to be a curve rather than linear. What this means is, for each circle that we draw in a shade of gray, instead of incrementing the shade by 1 for each circle we have to slowly accelerate the rate of incrementation over the course of the circles.
A curved gradient is similar to suggesting that our atom, with its energy field, is much harder to escape from when you are close to it, but the further from it you get the easier it becomes. When you are close to the center there isn't much difference in the strength of the gravity, but the further away you get the less it pulls.
Drawing a curved gradient is included in the sourcecode below. Basically what we do for blobby objects is increase our color intensity based on a curve produced by squaring a number by itself (rather than just adding a number to itself.) When the number is small, the curve obviously doesn't move much but as it increases the curve gets increasingly curvy. It ends up looking like this:

And when you've drawn the actual energy field of one atom, it looks like this:

If you compare this to the original linear image, you'll notice not only that the overal brightness seems a lot less but also there is more of a `peak` of brightness nearer the center. The brightness quickly falls away and then you're left with a gradually decreasing amount of dimming the further you get. This is the ideal shape for our blobby objects and the way that they need to interact with each other.
The side effect of generating an image with this kind of curved gradient is that the curvature directly translates to the way that the intensities of the energy fields combine. When you draw several of these images in LIGHTBLEND, where their values are added together, it forms not only smoothly curved shapes but also different degrees of curvature based on proximity. With the linear gradient we get a sudden total switching on of the `bridge` between the two atoms, whereas with a curved gradient we get different amounts of bulging.
So, drawing two curved-gradient energy fields, added together, we get this:

Now, it doesn't look a whole lot different at first glance to the original linear combination. But if you take a look at what is happening here you will notice there are actually completely smooth curves at every energy intensity level. We can hilite these again by showing some of these intensities with a contrastsing color:

As you can see, the energy field actually is forming proper blobby object perimeters. Areas closer to each atom have not yet `blobbed out` since they are out of reach of the influence of each other. But the parts of the energy field that do influence each other (by overlapping) begin to bulge toward each other and unify. Solely because of our curved gradient we get a curved shape instead of a rectangular shape.
There you have it, blobby objects rendered on-screen!
The great thing is, this is actually a very very simple technique compared with the marching cubes algorithm. It is especially great that we are doing all the `processing` using image data and even more great that we can therefore use hardware acceleration to perform all the computation. The simple combination of a pre-rendered energy field using the correct curvature of the gradient, along with an additive blend mode, gives us blobby objects.
There are other curves of gradient that can be used based on other formulae. The number*number formulae is the simplest and produces standard blobby objects. Other formulas produce perhaps flatter curves, or accentuate the area nearer the middle. Changing the curves in these ways can make the blobs appear to be more `sticky` or more reluctant to disconnect, so that when they do disconnect they seem to `snap back` into place more quickly.
The main idea of producing blobby objects is that you first of all generate the combined energy fields - officially known as an `isosurface` - and then you interpret that surface by rendering only at a certain threshold. In my example above I simply took a paint program, a flood fill tool with a treshhold of 5 pixel values, and clicked on the image in several places. What this shows you is that if you vary the threshold you vary how much energy needs to be present in order to make a perimeter.
Usually blobby objects will be drawn in this way, rendering only the pixels that have values of, say, between 120 and 140. This would produce a single `band` around all the blobs.
In this tutorial I am just showing you the basics of how to generate some blobby objects. What you need to do next is take the data that is generated - ie the resulting image on your screen, and find ways to manipulate that image to produce an effect that you like. In its more advanced incarnation I have taken this basic BlitzMax program and converted everything to direct OpenGL programming. This allows me to set up some blend modes and operations which are not currently implemented as part of Max2D. I use these additional modes to cover the screen several times with a filled rectangle, where each pass performs some `math` on the pixel color. The end result is that you can get bands of color to form.
In this tutorial example, there is an inbuilt threshold of 255 whereby, any areas that contain energy intensity at 255 simple remain that color. It never gets any brighter. You can use this fact and with a little further manipulation/post-processing let your blobs be formed only by the white pixels. In addition you can draw a rectangle over the whole screen in LIGHTBLEND mode with a color of $80,$80,$80 (mid-gray), which will cause the treshold to be formed at half-strength energy levels rather that at the white level. With a bit of clever manipulation you can come up with something looking like this:

So far all we've done is use a spherical energy field. You may have noticed we are now working with images here, and an image of a spherical energy field is precalculated before being used. For your further enjoyment you may wish to save that image and load it into your favorite graphics package. There is absolutely nothing stopping you from performing image processing functions on that image and then loading it into the blob-rendering routine. It only has to be loaded once at the start instead of generating the blob image from scratch. There are many interesting ways you can warp, twist and otherwide deform the basic blob image. When it comes to rendering it in the blob program, blobs will still be formed as before - combining and merging based on proximity - but now the energy field is simply a different shape. This can make for some pretty interesting effects!
There's also nothing stopping you from adding a `tint` to each image that you render, by using `SetColor` for each one. You will find that individual blobs form in each of the separate Red, Green and Blue channels, and that their shapes will overlap without interacting, as in the above image.
Have fun, play around with it. You can add as many blob objects to the screen as you like, this `algorithm` supports an unlimited number of combinations at no extra charge. ....... <- get it, *extra charge* ..... electrical fields,..... *ahem*.
I hope this has been clear and understandable. Feel free to ask questions.
The very simple final sourcecode is below, no strings attached. As it stands it generates blob fields that occupy a 512x512 space. It can also do 256x256 and 128x128, but any size other than that you'll have to work out the balldivider and lineardivider values - I'm sure there is a formulae that would generate them properly but I couldn't figure it out.
'Blobby objects with BlitzMax using Max2D only 'Some special numbers Local ballsize:Int=512 Local ballsizehalf:Int=ballsize/2 'Set up the display Graphics 800,600,0 Cls 'Work out what the dividers needs to be Local balldivider:Float If ballsize=128 Then balldivider=64 '8x8 If ballsize=256 Then balldivider=256 '16x16 If ballsize=512 Then balldivider=1024 '32x32 Local lineardivider:Float If ballsize=128 Then lineardivider=0.5 If ballsize=256 Then lineardivider=1 If ballsize=512 Then lineardivider=2 'Render the gradient image For Local r:Float=1 To ballsize-1 Step 0.5 Local level:Float=r level:*level level=level/balldivider SetColor level,level,level 'For blobby gradient shape 'SetColor r/lineardivider,r/lineardivider,r/lineardivider 'For linear gradients DrawOval r/2,r/2,ballsize-r,ballsize-r Next 'Turn it into an image AutoMidHandle True Local img:TImage=CreateImage(ballsize,ballsize,1,FILTEREDIMAGE) GrabImage(img,0,0,0) 'Set the drawing mode SetBlend LIGHTBLEND 'Keep drawing the image until you press Escape Repeat Cls DrawImage img,400,300 DrawImage img,MouseX(),MouseY() Flip Until KeyHit(KEY_ESCAPE)
Please see below for part two of this tutorial :-)
Regards, AngelDaniel.



