The QB64 Edition

Full Version: Splatter Art with Martin Fractals
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Here is a modified version of the Martin Fractals Demo I posted before. This on looks like splatter art.

Here is the code:
Code Snippet: [Select]
DIM SHARED ScreenWidth AS _UNSIGNED INTEGER
DIM SHARED ScreenHeight AS _UNSIGNED INTEGER
DIM SHARED MainWindow AS _UNSIGNED LONG
DIM CenterX AS _FLOAT
DIM CenterY AS _FLOAT
DIM ParamA AS _FLOAT, ParamB AS _FLOAT, ParamC AS _FLOAT
DIM XOld AS _FLOAT, XOld2 AS _FLOAT, YOld AS _FLOAT, YOld2 AS _FLOAT
DIM XNew AS _FLOAT, XNew2 AS _FLOAT, YNew AS _FLOAT, YNew2 AS _FLOAT
DIM Scale AS _FLOAT
DIM CurrentCount AS _FLOAT
DIM CountMax AS _FLOAT
DIM NumPointsPlotted AS _UNSIGNED LONG
DIM PlottedMax AS _UNSIGNED LONG
DIM ColorChange AS _UNSIGNED LONG
DIM ColorChangeMax AS _UNSIGNED LONG
DIM Colr AS _UNSIGNED LONG

ScreenWidth = _DESKTOPWIDTH
ScreenHeight = _DESKTOPHEIGHT

MainWindow = _NEWIMAGE(ScreenWidth, ScreenHeight, 32)
SCREEN MainWindow

_FULLSCREEN
_MOUSEHIDE

CenterX = ScreenWidth / 2
CenterY = ScreenHeight / 2

CountMax = 15
PlottedMax = 5000
ColorChangeMax = 20000

DO

    LINE (0, 0)-(ScreenWidth - 1, ScreenHeight - 1), _RGB(255, 255, 255), BF

    ParamA = RND * 100 - 50
    ParamB = RND * 100 - 50
    ParamC = RND * 100 - 50

    XOld = 0: XOld2 = 0: YOld = 0
    Colr = _RGB(RND * 255, RND * 255, RND * 255)
    ColorChange = 0
    CurrentCount = 0
    NumPointsPlotted = 0
    Scale = 3

    DO

        PlotPoint XOld2 * Scale + CenterX, YOld2 * Scale + CenterY, Colr

        XNew = YOld - SGN(XOld) * SQR(ABS(ParamB * XOld - ParamC))
        YNew = ParamA - XOld

        XNew2 = (YOld2 - SIN(XOld2) * SIN((ParamB * XOld + ParamC))) * 0.999995
        YNew2 = ParamA - XOld2

        XOld2 = XNew2
        YOld2 = YNew2

        XOld = XNew
        YOld = YNew

        NumPointsPlotted = NumPointsPlotted + 1

        IF NumPointsPlotted > PlottedMax THEN
            _LIMIT 60
            CurrentCount = CurrentCount + 0.0125
            NumPointsPlotted = 0
            _DISPLAY
        END IF

        ColorChange = ColorChange + 1

        IF ColorChange > ColorChangeMax THEN
            Colr = _RGB(RND * 255, RND * 255, RND * 255)
            ColorChange = 0
        END IF

        k$ = INKEY$

    LOOP WHILE k$ = "" AND CurrentCount < CountMax

    _DISPLAY

    PointsAcross = 16
    PointsDown = 8
    SectionWidth = ScreenWidth / (PointsAcross + 1)
    SectionHeight = ScreenHeight / (PointsDown + 1)
    MaxSize = SectionWidth * 1.5

    FOR ObjSize = 0 TO MaxSize STEP 2

        _LIMIT 60
        FOR y = SectionHeight TO ScreenHeight - SectionHeight / 2 STEP SectionHeight
            FOR x = SectionWidth TO ScreenWidth - SectionWidth / 2 STEP SectionWidth

                LINE (x - ObjSize, y - ObjSize)-(x + ObjSize, y + ObjSize), _RGBA(255, 255, 255, 32), BF
                IF k$ = CHR$(27) THEN SYSTEM
                k$ = INKEY$
            NEXT
        NEXT

        _DISPLAY
    NEXT

LOOP WHILE k$ <> CHR$(27)

SYSTEM



' *************************************************************************************************
' *                                                                                               *
' *************************************************************************************************
SUB PlotPoint (X AS _FLOAT, y AS _FLOAT, colr AS _UNSIGNED LONG)

Red = _RED32(colr)
Green = _GREEN32(colr)
Blue = _BLUE32(colr)
MaxI = 1
MaxRndSize = RND * 16

FOR i2 = 0 TO 5

    x1 = X + ((RND * MaxRndSize) - (MaxRndSize / 2))
    y1 = y + ((RND * MaxRndSize) - (MaxRndSize / 2))

    iMul = MaxI * (RND * 3)
    NewColr& = _RGBA(Red, Green, Blue, 8)

    LINE (INT(.5 + x1) - iMul, INT(.5 + y1) - iMul)-(INT(.5 + x1) + iMul, INT(.5 + y1) + iMul), NewColr&, BF

NEXT

END SUB


HERE ARE SOME SCREENSHOTS:


[attachment=272][attachment=273][attachment=274]
[attachment=275][attachment=276][attachment=277]
[attachment=278][attachment=279][attachment=280]

Looks Great Walter...

It looks like the Floor after I have come back from a Night on the Beer! Smile

I am sure there is some Complex Math going on there to make all that Work!



Anthony.
Anthony,

There really isn't any complex math being used in this project. Here is the math behind it:


Code Snippet: [Select]
        PlotPoint XOld2 * Scale + CenterX, YOld2 * Scale + CenterY, Colr

        XNew = YOld - SGN(XOld) * SQR(ABS(ParamB * XOld - ParamC))
        YNew = ParamA - XOld

        XNew2 = (YOld2 - SIN(XOld2) * SIN((ParamB * XOld + ParamC))) * 0.999995
        YNew2 = ParamA - XOld2

        XOld2 = XNew2
        YOld2 = YNew2

        XOld = XNew
        YOld = YNew


There are some multiplications, Additions, subtractions, a SQR(), a SGN(), and two SIN() functions.

If you think that is cool, check out the other fractal demo I posted. It is identical except with some minor changes in the algorithm.


Walter Whitman
The Joyful Programmer
Reference URL's