January 26, 2021, 06:03:30 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Graphics
»
[bmx] Fast 2D Blobby Objects/Metaballs in Max2D by ImaginaryHuman [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bmx] Fast 2D Blobby Objects/Metaballs in Max2D by ImaginaryHuman [ 1+ years ago ] (Read 524 times)
BlitzBot
Jr. Member
Posts: 1
[bmx] Fast 2D Blobby Objects/Metaballs in Max2D by ImaginaryHuman [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:38 AM »
Title :
Fast 2D Blobby Objects/Metaballs in Max2D
Author :
ImaginaryHuman
Posted :
1+ years ago
Description :
This program shows how to generate an energy field image which can then be used to render blobby objects on the screen. Since it works using images it is highly optimized by hardware acceleration of your graphics card, so is very fast. It also allows any number of blobby objects to be added and still produces the same results. This example shows the basic technique of drawing metaballs. See my other submission for how to turn the final image into something more useful.
Code :
Code: BlitzMax
'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
)
Comments :
drnmr(Posted 1+ years ago)
you can create green blobs by changing the line SetColor level,level,level to SetColor level,r/lineardivider,level.
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Graphics
»
[bmx] Fast 2D Blobby Objects/Metaballs in Max2D by ImaginaryHuman [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal