'original author: STxAxTIC
'Petr's speed up modification
' Constants
' Structures and variables
'FOR i = 1 TO 350
' p = RND * _WIDTH
' q = RND * _HEIGHT
' CIRCLE (p - 50, q - 50), 100, _RGB32(RND * 255, RND * 255, RND * 255, RND * 255)
' LINE (100, 100)-(300, 300), _RGB32(255, 155, 0, 255), BF
'NEXT
'_DISPLAY
MainPhase(i, j).VelocityRed = 1
MainPhase(i, j).VelocityGreen = 2
MainPhase(i, j).VelocityBlue = 3
' Main loop
' _DISPLAY
' Graphics
DrawIt:
FOR i
= mx
- 40 TO mx
+ 40 FOR j
= my
- 40 TO my
+ 40 t2 = (i - mx) * (i - mx) + (j - my) * (j - my)
'IF (t2 < 1600) THEN
' POINT is too slow
_MEMGET m
, m.OFFSET
+ IN
(i
, j
) + 2, r
_MEMGET m
, m.OFFSET
+ IN
(i
, j
) + 1, g
rOld = r
gOld = g
bOld = b
p = MainPhase(i, j).VelocityRed
q = MainPhase(i, j).VelocityGreen
w = MainPhase(i, j).VelocityBlue
r = r + p
IF (r
> 255) OR (r
< 1) THEN MainPhase
(i
, j
).VelocityRed
= -p
g = g + q
IF (g
> 255) OR (g
< 1) THEN MainPhase
(i
, j
).VelocityGreen
= -q
b = b + w
IF (b
> 255) OR (b
< 1) THEN MainPhase
(i
, j
).VelocityBlue
= -w
NC~&
= _RGBA32(r
, g
, b
, 255 * (1 - t2
/ 1600))
'PSET (i, j), _RGB32(r, g, b, 255 * (1 - t2 / 1600)) PSET is too slow
alfa = 255 * (1 - t2 / 1600)
af = alfa / 255
'for circle effect must be R, G, B values recaltulated with alfa first:
MEMALPHA
_RGBA32(rOld
, gOld
, bOld
, 255), NC~&
, newerest~&
_MEMPUT m
, m.OFFSET
+ IN
(i
, j
), newerest~&
SUB MEMALPHA
(oldColor~&
, newColor~&
, ResultColor~&
)
NovaAlfa = NewA / 255 ' new alpha channel value
NstaraR = oldR * ((255 - NewA) / 255) ' Recalculate old (background) color with alpha channel (255 is always background value minus alpha from new color) -> in MEM use, if is image draw to untransparent background
NstaraG = oldG * ((255 - NewA) / 255)
NstaraB = oldB * ((255 - NewA) / 255)
NnovaR = NewR * NovaAlfa 'Recalculate new (foreground) color
NnovaG = NewG * NovaAlfa
NnovaB = NewB * NovaAlfa
VysR = NnovaR + NstaraR 'output values, tested using MEM and POINT
VysG = NnovaG + NstaraG
VysB = NnovaB + NstaraB
ResultColor~&
= _RGB32(VysR
, VysG
, VysB
)