Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fractals
#13
Classic Fern Swaying in the Wind


Code: (Select All)
_Title "Classic Fern sway in wind mod, press spacebar for new landscape, esc to quit" 'b+ 2020-08-06
Screen _NewImage(1000, 600, 32)
_Delay .25
_ScreenMove _Middle
Window (-5, 0)-(5, 11)
Randomize Timer

Type obj
    x As Single 'offset from centered fern
    y As Single 'offest from centered fern
    scale As Single ' from 0 to 1
    c As _Unsigned Long
End Type

Dim Shared nFerns
ReDim Shared fern(1 To nFerns) As obj

initFerns
wind = 0: dw = .01: dir = 1
While _KeyDown(27) = 0
    If InKey$ = " " Then initFerns
    For i = 4 To 11 Step .2
        Line (-5, i)-(5, i + .2), _RGB32(60, (1 - i / 11) * 150 + 60, (1 - i / 11) * 75 + 180), BF
    Next
    For i = 0 To 4 Step .2
        Line (-5, i)-(5, i + .2), _RGB32(i / 4 * 90 + 10, i / 4 * 45 + 5, i / 4 * 22 + 2), BF
    Next
    For i = 1 To nFerns
        drawFern fern(i).x, fern(i).y, fern(i).scale, fern(i).c, wind
    Next

    _Display
    _Limit 10
    wind = wind + dir * dw
    If wind > .06 Or wind < -.72 Then dir = -dir
Wend

Sub initFerns
    nFerns = 4 + Int(Rnd * 9)
    ReDim fern(1 To nFerns) As obj
    For i = 1 To nFerns
        fern(i).x = Rnd * 10 - 5
        fern(i).y = Rnd * 2 - 1
        fern(i).scale = Rnd * .7 + .3
        g = Rnd * 100 + 40
        fern(i).c = _RGB32(g - 20 - Rnd * 60, g, g - 20 - Rnd * 60)
    Next
End Sub

Sub drawFern (xoff0, yoff0, scale, c As _Unsigned Long, w)
    yAdj = yoff0 + (1 - scale) * 5
    For i = 1 To 90000 'enough dots to get idea
        Select Case Rnd
            Case Is < .01
                nextX = 0
                nextY = .16 * y
            Case .01 TO .08
                nextX = .2 * x - .26 * y
                nextY = .23 * x + .22 * y + 1.6
            Case .08 TO .15
                nextX = -.15 * x + .28 * y
                nextY = .26 * x + .24 * y + .44
            Case Else
                nextX = .85 * x + .04 * y
                nextY = -.04 * x + .85 * y + 1.6
        End Select
        x = nextX + w * nextY / 10
        y = nextY
        Line (x * scale + xoff0, y * scale + yAdj)-Step(0, 0), c, BF
    Next
End Sub

Occasionally with these ferns you get a sighting of the Fernerator
   
b = b + ...
Reply


Messages In This Thread
Fractals - by bplus - 05-19-2022, 07:34 PM
RE: Fractals - by bplus - 05-19-2022, 07:46 PM
RE: Fractals - by bplus - 05-19-2022, 07:52 PM
RE: Fractals - by bplus - 05-19-2022, 08:03 PM
RE: Fractals - by bplus - 05-19-2022, 08:25 PM
RE: Fractals - by bplus - 05-19-2022, 08:33 PM
RE: Fractals - by TarotRedhand - 05-19-2022, 10:33 PM
RE: Fractals - by bplus - 05-20-2022, 01:14 AM
RE: Fractals - by TarotRedhand - 05-20-2022, 07:01 AM
RE: Fractals - by bplus - 05-20-2022, 03:55 PM
RE: Fractals - by TarotRedhand - 05-21-2022, 10:12 PM
RE: Fractals - by bplus - 05-21-2022, 11:16 PM
RE: Fractals - by bplus - 05-21-2022, 11:33 PM
RE: Fractals - by bplus - 06-03-2022, 03:37 PM
RE: Fractals - by bplus - 06-03-2022, 03:43 PM
RE: Fractals - by bplus - 10-02-2024, 08:01 PM



Users browsing this thread: 3 Guest(s)