Started updating my little Ball SUB (filled circle), thought I'd build it up over time by adding different kinds of textures to the balls, instead of just plain solid colors. Although this is nowhere near the speed of the gold standard fcirc routine, it can be handy, and it's easy to drop the SUB in your programs.
So far it can draw 6 kinds of filled balls. Solid, Gradient, and some textures like grainy, striped, plasma, mixed.
I will come up with some more textures. If you'd like to add one, please do.
- Dav
So far it can draw 6 kinds of filled balls. Solid, Gradient, and some textures like grainy, striped, plasma, mixed.
I will come up with some more textures. If you'd like to add one, please do.
- Dav
Code: (Select All)
'===========
'BALLSUB.BAS v1.0
'===========
'Simple Ball SUB that draws balls of different textures.
'Solid, Gradient, planet, plasma, noisey, striped, mixed.
'Coded by Dav, AUGUST/2023
Randomize Timer
Screen _NewImage(1000, 600, 32)
Do
'make random ball to show all kinds
ball Int(Rnd * 7), Rnd * _Width, Rnd * _Height, Rnd * 300 + 25, Rnd * 255, Rnd * 255, Rnd * 255, 100 + Rnd * 155
_Limit 10
Loop Until InKey$ <> ""
Sub ball (kind, x, y, size, r, g, b, a)
'SUB by Dav that draws many types of filled balls (circles).
'Not super fast, but small and easy to add to your programs.
'kind=0 (Gradient)
'kind=1 (noisey)
'kind=2 (planets)
'kind=3 (plasma)
'kind=4 (striped)
'kind=5 (plasma mix with gradient noise)
'kind=6 (solid)
'get current display status to restore later
displayStatus%% = _AutoDisplay
'turn off screen updates while we draw
_Display
t = Timer
For y2 = y - size To y + size
For x2 = x - size To x + size
If Sqr((x2 - x) ^ 2 + (y2 - y) ^ 2) <= size Then
clr = (size - (Sqr((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y)))) / size
Select Case kind
Case 1: 'noisey (grainy)
noise = Rnd * 255
Case 2: 'planet
noise = 20 * Sin((x2 + y2) / 30) + 10 * Sin((x2 + y2) / 10)
Case 3: 'plasma
r = (Sin(x2 / (size / 4)) + Sin(y2 / size / 2)) * 128 + 128
g = (Sin(x2 / (size / 6)) + Cos(y2 / (size / 4))) * 128 + 128
b = (Cos(x2 / (size / 4)) + Sin(y2 / (size / 6))) * 128 + 128
Case 4: 'striped
dx = x2 - size: dy = y2 - size
dis = Sqr(dx * dx + dy * dy)
r = Sin(dis / 5) * 255
g = Cos(dis / 25) * 255
b = 255 - Sin(dis / 50) * 255
Case 5: 'plasma mix with gradient & noise
noise = Int(Rnd * 50)
r = Sin(6.005 * t) * size - y2 + size + 255
g = Sin(3.001 * t) * size - x2 + size + 255
b = Sin(2.001 * x2 / size + t + y2 / size) * r + 255
t = t + .00195
Case Else: 'solid & gradient (no noise)
noise = 0
End Select
If kind = 6 Then
'if solid color
PSet (x2, y2), _RGBA(r, g, b, a)
Else
'all others, noise & gradient color aware
PSet (x2, y2), _RGBA(clr * r - noise, clr * g - noise, clr * b - noise, a)
End If
End If
Next
Next
'show the ball on the screen
_Display
'If autodislay was previously on, turn it back on
If displayStatus%% = 1 Then _AutoDisplay
End Sub