Code archives/Graphics/Blobby Object Plasma
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
This simple but attractive effect is produced by the interactions of numerous blobby object particle fields. For a 1024x768 display I have set it up to use 60 blobby objects. Each field consumes a 512x512 area. The blobby energy field, which is a gradient with a squared falloff, is rendered into a 2 dimensional array in the form of an image. The image is then pasted onto the screen with additive blending. The values of all overlapping fields add up and the curvature of their gradients produces a gently curved contour. This is done on 255 energy levels in 3 separate color components, whereby every level of energy is rendered and not just those beyond a threshold. This produces a plasma effect and the changes in color further animate the contours. This code was originally a 512-byte program and has been re-expanded into more human-readable form. As a result, calculation of colors is done based on object coordinates and rotation angles, and you will notice the red component eventually goes out of range, resulting in a mainly blue-green palette. There are many better ways to generate and maintain colors but I was short on space originally. This should run well on even mid-low-range graphics cards since it is mainly just drawing images with additive blending. Enjoy. | |||||
'Set these to what you want Const Objects:Int=60 Const ScrWidth:Int=1024 Const ScrHeight:Int=768 Const RotationSpeed:Float=0.2 'Open a screen and draw a blobby energy field with squared falloff Graphics ScrWidth,ScrHeight,32 For Local Radius:Float=1 Until 512 Step 0.5 Local Energy:Float=(Radius*Radius)/1024.0 SetColor Energy,Energy,Energy DrawOval Radius/2.0,Radius/2.0,512-Radius,512-Radius 'Try DrawRect Next 'Turn it into an image/texture Local Image:TImage=CreateImage(512,512) GrabImage(Image,0,0) 'Set up the positions and movement directions/speeds/angles of objects Local XPos:Float[Objects],YPos:Float[Objects] Local XMove:Float[Objects],YMove:Float[Objects] Local Rotation:Float[Objects] Local Obj:Int For Obj=0 Until Objects XPos[Obj]=Rand(0,ScrWidth) Ypos[Obj]=Rand(0,ScrHeight) XMove[Obj]=(RndFloat()-0.5)*4 YMove[Obj]=(RndFloat()-0.5)*4 Rotation[Obj]=RndFloat()*360 Next 'Additive blending to combine blob fields SetBlend LIGHTBLEND 'Do a demo Repeat Cls For Obj=0 Until Objects 'Move the objects XPos[Obj]:+XMove[Obj] YPos[Obj]:+YMove[Obj] 'Bounce the objects off the screen edges If XPos[Obj]<0 or XPos[Obj]>ScrWidth Then XMove[Obj]=-XMove[Obj] If YPos[Obj]<0 or YPos[Obj]>ScrHeight then YMove[Obj]=-YMove[Obj] 'Rotate the objects around their corners Rotation[Obj]:+RotationSpeed 'Set object color based on coords/angles SetColor 1024-(Rotation[Obj] Mod 256),512-XPos[Obj],512-YPos[Obj] 'Draw the blobby object SetRotation Rotation[Obj] DrawImage Image,XPos[Obj],YPos[Obj] Next Flip 1 Until KeyHit(KEY_ESCAPE) |
Comments
| ||
Many thanks for this! |
| ||
Here is a blitz3d port of it...not a direct port, had to change some things, but it should look the same (I don't have blitzmax, but the screenshots look the same). It uses an additive blended mesh with each "blob" being a seperate surface for ease of vertex manipulation :) |
| ||
Cool. I can't see the Blitz3D version but the code is an interesting adaptation. You are welcome, too, Boiled Man. Enjoy. |
| ||
@mindstorm - awesome. Screen saver in the pipeline :-) |
Code Archives Forum