linebricks or brickfill
#1
Here's a couple routines to create randomly varying brickfill patterns. There are briefer and mathematically slicker ways to do simple brick patterns but if you want to add a little variation in color and style the code can get a little longer. If you can make use of it feel free.

Code: (Select All)
'linebricks
'playing with brick patterns drawn with the line command
'fills whole screen and 2 other area with a colored brick pattern that can randomly vary from brick to brick
'press any key for brickish wonder    or esc to quit
Screen _NewImage(800, 500, 32)
_Title "Linebricks a brickfill demo"
Randomize Timer
Do
    'this randomly sey bw (brick width) bh (brick height) and mw (mortar width) for the purposes of demonstration
    bw = 4 + 4 * Int(Rnd * 8)
    bh = (bw * 3) / 5
    mw = bh / (4 + Rnd * 8)
    If mw < .5 Then mw = .5
    brickfill 0, 0, _Width, _Height, bw, bh, mw, _RGB32(240, 40, 40), _RGB32(100, 100, 100), 49, 12
    brickfill 0, 0, 200, 150, bw, bh, mw, _RGB32(40, 40, 40), _RGB32(100, 100, 100), 50, 6
    brickfill 200, 160, 400, 350, bw * 2, bh * 2, mw, _RGB32(40, 240, 40), _RGB32(100, 100, 100), 20, 10
Loop Until waitanykey$ = Chr$(27)
Function waitanykey$
    _KeyClear
    Do
        _Limit 60
        kk$ = InKey$
    Loop Until kk$ <> ""
    waitanykey$ = kk$
End Function
Sub brick (x, y, w, h, mwid, brickcolor As _Unsigned Long, mortarcolor As _Unsigned Long, cv)
    'draw a brick
    'each brick has color variation randomly picked in side the raneg defiend by cv
    'each brick may be randonly standard, have a lightened highlight  or a deep shadow and a higlight
    Dim tcolor As _Unsigned Long
    tred = _Red32(brickcolor) + Int(Rnd * cv) - Int(Rnd * cv)
    tgreen = _Green32(brickcolor) + Int(Rnd * cv) - Int(Rnd * cv)
    tblue = _Blue32(brickcolor) + Int(Rnd * cv) - Int(Rnd * cv)
    If tred < 0 Then tred = 0
    If tgreen < 0 Then tgreen = 0
    If tblue < 0 Then tblue = 0
    If tred > 255 Then tred = 255
    If tgreen > 255 Then tgreen = 255
    If tblue > 255 Then tblue = 255
    tcolor = _RGB32(tred, tgreen, tblue)
    Line (x, y)-(x - 1 + w, y - 1 + h), mortarcolor, BF
    Select Case Int(1 + Rnd * 14)
        Case 1, 2, 3, 4, 5, 6 'plain brick
            Line (x + mwid, y + mwid)-(x - 1 + w - mwid, y - 1 + h - mwid), tcolor, BF
        Case 7, 8 'sahdow and highlight brick
            tred = tred - Int(cv / 2 + Rnd * cv)
            tgreen = tgreen - Int(cv / 2 + Rnd * cv)
            tblue = tblue - Int(cv / 2 + Rnd * cv)
            If tred < 0 Then tred = 0
            If tgreen < 0 Then tgreen = 0
            If tblue < 255 Then tblue = 0
            tcolor = _RGB32(tred, tgreen, tblue)
            Line (x + mwid, y + mwid)-(x - 1 + w - mwid, y - 1 + h - mwid), tcolor, BF
            tred = tred + Int(2 + Rnd * cv)
            tgreen = tgreen + Int(2 + Rnd * cv)
            tblue = tblue + Int(2 + Rnd * cv)
            If tred > 255 Then tred = 255
            If tgreen > 255 Then tgreen = 255
            If tblue > 255 Then tblue = 255
            tcolor = _RGB32(tred, tgreen, tblue)
            sv = (10 + Rnd * 20) / 10
            Line (x + (mwid * sv), y + mwid)-(x - 1 + w - mwid, y - 1 + h - (mwid * sv)), tcolor, BF

        Case Else 'highlight brick
            Line (x + mwid, y + mwid)-(x - 1 + w - mwid, y - 1 + h - mwid), tcolor, BF
            tred = tred + Int(Rnd * (cv * .65))
            tgreen = tgreen + Int(Rnd * (cv * .65))
            tblue = tblue + Int(Rnd * (cv * .65))
            If tred > 255 Then tred = 255
            If tgreen > 255 Then tgreen = 255
            If tblue > 255 Then tblue = 255
            tcolor = _RGB32(tred, tgreen, tblue)
            sv = (10 + Rnd * 20) / 10
            Line (x + (mwid * sv), y + mwid)-(x - 1 + w - mwid, y - 1 + h - (mwid * sv)), tcolor, BF
    End Select
End Sub

Sub brickfill (sx, sy, ex, ey, bw, bh, mwid, brickcolor As _Unsigned Long, mortarcolor As _Unsigned Long, cv, crackrange)
    'crackrange is the raw maximum rnd range used to add cracks to the wall
    Dim zag(1 To 10, 1 To 2)
    b = 0
    For y = sy To ey Step bh
        b = b + 1
        For x = sx To ex Step bw
            If b Then
                brick x - (bw \ 2), y, bw, bh, mwid, brickcolor, mortarcolor, cv
            Else
                brick x, y, bw, bh, mwid, brickcolor, mortarcolor, cv
            End If
        Next x
        If b = 1 Then b = -1
    Next y
    cracks = Int(Rnd * crackrange)
    For c = 1 To cracks
        cx = Int(sx + Rnd * (ex - sx)): cy = Int(sy + Rnd * (ey - sy))
        zag(1, 1) = cx: zag(1, 2) = cy
        xshift = Int(-3 + Rnd * 6)
        yshift = Int(-3 + Rnd * 6)
        If xshift = 0 Then xshift = -1
        If yshift = 0 Then yshift = -1
        For z = 2 To 10
            zag(z, 1) = zag(z - 1, 1) + xshift * Int(Rnd * ((ex - sx) / 20))
            zag(z, 2) = zag(z - 1, 2) + yshift * Int(Rnd * ((ey - sy) / 20))
        Next z
        For z = 1 To 9
            If zag(z, 1) > 0 And zag(z, 2) > 0 Then
                If zag(z + 1, 1) <= ex And zag(z + 1, 2) <= ey Then Line (zag(z, 1), zag(z, 2))-(zag(z + 1, 1), zag(z + 1, 2)), _RGB32(90, 90, 90)
            End If
        Next z
    Next c
End Sub
Reply


Messages In This Thread
linebricks or brickfill - by James D Jarvis - 03-10-2023, 04:24 PM
RE: linebricks or brickfill - by mnrvovrfc - 03-10-2023, 05:03 PM
RE: linebricks or brickfill - by James D Jarvis - 03-10-2023, 05:22 PM
RE: linebricks or brickfill - by TerryRitchie - 03-10-2023, 05:04 PM
RE: linebricks or brickfill - by James D Jarvis - 03-10-2023, 05:24 PM
RE: linebricks or brickfill - by SpriggsySpriggs - 03-10-2023, 07:03 PM
RE: linebricks or brickfill - by James D Jarvis - 03-10-2023, 09:33 PM



Users browsing this thread: 5 Guest(s)