04-27-2022, 02:26 PM
Here's something I found collecting dust. Made it when I started playing around with RotoZoom3. Generates pages of clusters of balls and spins them around in various size, speed and transparency.
- Dav
- Dav
Code: (Select All)
'====================
'SWIRLINGCLUSTERS.BAS
'====================
'Swirling clusters of colored balls
'Code by Dav, FEB/2021
'(I didn't make RotoZoom3 SUB)
SCREEN _NEWIMAGE(800, 800, 32)
RANDOMIZE TIMER
NumberOfClusters = 30
DIM Cluster(NumberOfClusters) AS LONG
ballsize = 20
balls = 80
FOR d = 1 TO NumberOfClusters
Cluster(d) = _NEWIMAGE(_WIDTH, _HEIGHT, 32)
_DEST Cluster(d)
FOR i = 1 TO balls
x = RND * _WIDTH
IF x < ballsize * 2 THEN x = x + (ballsize * 2)
y = RND * _HEIGHT
IF y < ballsize * 2 THEN y = y + (ballsize * 2)
ball x, y, RND * ballsize, RND * 128, RND * 128, 255, RND * 150
NEXT
NEXT
_DEST 0
DIM ClusterX(NumberOfClusters), ClusterY(NumberOfClusters), ClusterSize(NumberOfClusters)
DIM ClusterRotate(NumberOfClusters), ClusterSpeed(NumberOfClusters)
FOR G = 1 TO NumberOfClusters
ClusterX(G) = RND * _WIDTH
ClusterY(G) = RND * _HEIGHT
ClusterSize(G) = RND * 1.3
ClusterRotate(G) = 2
ClusterSpeed(G) = RND * 2
NEXT
DO
CLS , _RGB(0, 0, 64)
FOR G = 1 TO NumberOfClusters
RotoZoom3 ClusterX(G), ClusterY(G), Cluster(G), ClusterSize(G), ClusterSize(G), _D2R(ClusterRotate(G))
ClusterRotate(G) = ClusterRotate(G) + ClusterSpeed(G): IF ClusterRotate(G) > 360 THEN ClusterRotate(G) = 1
NEXT
_DISPLAY
_LIMIT 30
LOOP UNTIL INKEY$ <> ""
FOR d = 1 TO NumberOfClusters
_FREEIMAGE Cluster(d)
NEXT
END
' Description:
' Started from a mod of Galleon's in Wiki that both scales and rotates an image.
' This version scales the x-axis and y-axis independently allowing rotations of image just by changing X or Y Scales
' making this tightly coded routine a very powerful and versatile image tool.
SUB RotoZoom3 (X AS LONG, Y AS LONG, Image AS LONG, xScale AS SINGLE, yScale AS SINGLE, radianRotation AS SINGLE)
' This assumes you have set your drawing location with _DEST or default to screen.
' X, Y - is where you want to put the middle of the image
' Image - is the handle assigned with _LOADIMAGE
' xScale, yScale - are shrinkage < 1 or magnification > 1 on the given axis, 1 just uses image size.
' These are multipliers so .5 will create image .5 size on given axis and 2 for twice image size.
' radianRotation is the Angle in Radian units to rotate the image
' note: Radian units for rotation because it matches angle units of other Basic Trig functions
' and saves a little time converting from degree.
' Use the _D2R() function if you prefer to work in degree units for angles.
DIM px(3) AS SINGLE: DIM py(3) AS SINGLE ' simple arrays for x, y to hold the 4 corners of image
DIM W&, H&, sinr!, cosr!, i&, x2&, y2& ' variables for image manipulation
W& = _WIDTH(Image&): H& = _HEIGHT(Image&)
px(0) = -W& / 2: py(0) = -H& / 2 'left top corner
px(1) = -W& / 2: py(1) = H& / 2 ' left bottom corner
px(2) = W& / 2: py(2) = H& / 2 ' right bottom
px(3) = W& / 2: py(3) = -H& / 2 ' right top
sinr! = SIN(-radianRotation): cosr! = COS(-radianRotation) ' rotation helpers
FOR i& = 0 TO 3 ' calc new point locations with rotation and zoom
x2& = xScale * (px(i&) * cosr! + sinr! * py(i&)) + X: y2& = yScale * (py(i&) * cosr! - px(i&) * sinr!) + Y
px(i&) = x2&: py(i&) = y2&
NEXT
_MAPTRIANGLE _SEAMLESS(0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
_MAPTRIANGLE _SEAMLESS(0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
END SUB
SUB ball (BallX, BallY, size, r&, g&, b&, a&)
FOR s = 1 TO size STEP .2
CIRCLE (BallX, BallY), s, _RGBA(r&, g&, b&, a&)
r& = r& - 2: g& = g& - 2: b& = b& - 2
NEXT
END SUB