Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Screen Savers
#2
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

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

Find my programs here in Dav's QB64 Corner
Reply


Messages In This Thread
Screen Savers - by bplus - 04-27-2022, 12:29 AM
RE: Screen Savers - by Dav - 04-27-2022, 02:26 PM
RE: Screen Savers - by bplus - 04-27-2022, 02:33 PM
RE: Screen Savers - by bplus - 04-30-2022, 11:55 PM
RE: Screen Savers - by Dav - 05-01-2022, 07:22 PM
RE: Screen Savers - by bplus - 05-01-2022, 08:26 PM
RE: Screen Savers - by bplus - 05-02-2022, 12:00 AM
RE: Screen Savers - by Coolman - 05-02-2022, 09:42 AM
RE: Screen Savers - by bplus - 05-03-2022, 02:13 AM
RE: Screen Savers - by bplus - 05-09-2022, 01:32 PM
RE: Screen Savers - by bplus - 05-19-2022, 07:22 PM
RE: Screen Savers - by bplus - 05-21-2022, 11:22 PM
RE: Screen Savers - by Pete - 05-21-2022, 11:27 PM
RE: Screen Savers - by bplus - 05-21-2022, 11:38 PM
RE: Screen Savers - by Pete - 05-22-2022, 04:39 AM
RE: Screen Savers - by bplus - 06-17-2022, 01:10 PM
RE: Screen Savers - by johnno56 - 06-18-2022, 12:23 AM
RE: Screen Savers - by Kernelpanic - 06-18-2022, 11:48 AM
RE: Screen Savers - by bplus - 06-18-2022, 01:47 AM
RE: Screen Savers - by bplus - 06-18-2022, 12:33 PM
RE: Screen Savers - by SierraKen - 06-20-2022, 09:50 PM
RE: Screen Savers - by bplus - 06-21-2022, 12:15 AM
RE: Screen Savers - by bplus - 06-29-2022, 04:52 PM
RE: Screen Savers - by SierraKen - 06-29-2022, 06:10 PM
RE: Screen Savers - by vince - 07-01-2022, 10:32 PM
RE: Screen Savers - by bplus - 07-01-2022, 11:05 PM
RE: Screen Savers - by bplus - 07-04-2022, 06:54 PM
RE: Screen Savers - by Kernelpanic - 07-04-2022, 09:11 PM
RE: Screen Savers - by bplus - 07-04-2022, 09:54 PM
RE: Screen Savers - by Kernelpanic - 07-05-2022, 02:14 PM
RE: Screen Savers - by bplus - 07-19-2022, 08:28 PM
RE: Screen Savers - by bplus - 08-28-2022, 12:55 AM
RE: Screen Savers - by TempodiBasic - 08-29-2022, 09:26 AM
RE: Screen Savers - by bplus - 09-06-2022, 12:35 AM
RE: Screen Savers - by SierraKen - 09-08-2022, 07:37 PM
RE: Screen Savers - by bplus - 09-09-2022, 02:22 AM
RE: Screen Savers - by SpriggsySpriggs - 09-15-2022, 04:38 PM
RE: Screen Savers - by bplus - 09-15-2022, 05:20 PM
RE: Screen Savers - by bplus - 01-31-2023, 04:21 PM
RE: Screen Savers - by vince - 02-01-2023, 07:27 AM
RE: Screen Savers - by bplus - 02-01-2023, 05:05 PM
RE: Screen Savers - by bplus - 03-13-2023, 10:51 PM
RE: Screen Savers - by vince - 03-31-2023, 11:09 PM
RE: Screen Savers - by bplus - 04-01-2023, 12:09 AM
RE: Screen Savers - by bplus - 05-14-2024, 03:00 PM
RE: Screen Savers - by PhilOfPerth - 05-15-2024, 08:24 AM
RE: Screen Savers - by bplus - 05-15-2024, 11:15 PM
RE: Screen Savers - by bplus - 08-20-2024, 12:00 AM



Users browsing this thread: 3 Guest(s)