// Ascii metaballs made with CoolBasic
 
SCREEN 400, 400
 
sw = ScreenWidth()
sh = ScreenHeight()
 
w = sw / 10
h = sh / 10
 
Const BALLS = 3
 
Type ball
	Field x
	Field y
	Field r
	Field mod1 As Float
	Field mod2 As Float
EndType
 
For i = 1 To BALLS
	b.ball = New(ball)
	b\x = Rand(w)
	b\y = Rand(h)
	b\r = 35 + Rand(15)
	b\mod1 = 1.5 - Rnd(1)
	b\mod2 = 1.5 - Rnd(1)
Next i
 
Repeat
	For x = 0 To w
		For y = 0 To h
			n# = 0.0
			For b.ball = Each ball
				xx = x - b\x
				yy = y - b\y
				n# = n# + b\r / (((xx * xx) + (yy * yy)) * 1.1)
 
				b\x = (w Shr 1) + (Sin(b\mod1 * (Timer() / 10)) * ((w - 10) Shr 1))
				b\y = (h Shr 1) + (Cos(b\mod2 * (Timer() / 10)) * ((h - 10) Shr 1))
			Next b
 
			If n# < 0 Then 
				n# = 0
			ElseIf n# > 1 Then
				n# = 1
			EndIf
 
			Color 0, n * 255, 0
			Text x * 10, y * 10, "@"
		Next y
	Next x
 
	SetWindow "Ascii meatballs - " + FPS()
	DrawScreen OFF
Forever