Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Candy Corn Trees
#2
Part 2

OK now when the Candy Corn ripens, it falls into the water... and a new fruit starts from that branch.
Code: (Select All)
Option _Explicit
_Title "Candy Corn Trees 2" 'bplus 2025-10-11
' from "Alien Trees Mod 3: Leaves" 'b+ 2022-09-05
' 10/10 good have it growing on trees next step is to drop corn when full size.
' 10/11 falling fruit complete next is to distribute to Sugarland Productions.

Randomize Timer
DefDbl A-Z
Const xmax = 1024, ymax = 600

Type corn
    As Double x, y, scale, frac, falling, dy, savey
End Type

Screen _NewImage(xmax, ymax, 32)
_ScreenMove 170, 40 ' clear sides
'_FullScreen
Randomize Timer

Dim Shared CC&
CC& = _LoadImage("Candy Corn 1.png")

Dim Shared As Long bk ' background image
bk = _NewImage(xmax, ymax, 32) 'container for drawings

Dim Shared As Long seed(1 To 3), start, cN ' Randomize seeds for trees and plasma starters
Dim Shared As Single rd(1 To 3), gn(1 To 3), bl(1 To 3) ' plasma colors for trees

Dim Shared leaf ' indexing ends of branches
Dim ref&
ref& = _NewImage(xmax, ymax * .2, 32) 'container for reflection image

Dim Shared corns(448) As corn ' corns / leaves

Dim As Long i
restart:
makeBackground
seed(1) = Rnd * 1000 ' get new trees setup  including the Plasma generators
seed(2) = Rnd * 1000
seed(3) = Rnd * 1000
For i = 1 To 3
    rd(i) = Rnd + .1
    gn(i) = Rnd * rd(i)
    bl(i) = 0 'Rnd * Rnd
Next
leaf = 0
start = 0
cN = start
Randomize Using seed(1)
branch xmax * .6 + Rnd * .3 * xmax, ymax * .8 - 30, 6, 90, xmax / 20, 0, 1, 1
cN = start
Randomize Using seed(2)
branch Rnd * .3 * xmax, ymax * .8 - 15, 7, 90, xmax / 18, 0, 2, 1
cN = start
Randomize Using seed(3)
branch xmax / 2, ymax * .8 - 8, 8, 90, xmax / 16, 0, 3, 1

For i = 1 To 448 'assign rnd sizes
    corns(i).frac = Rnd
Next

Do
    _PutImage , bk, 0
    start = start + 1
    cN = start
    Randomize Using seed(1)
    branch xmax * .6 + Rnd * .3 * xmax, ymax * .8 - 30, 6, 90, xmax / 20, 0, 1, 0
    cN = start
    Randomize Using seed(2)
    branch Rnd * .3 * xmax, ymax * .8 - 15, 7, 90, xmax / 18, 0, 2, 0
    cN = start
    Randomize Using seed(3)
    branch xmax / 2, ymax * .8 - 8, 8, 90, xmax / 16, 0, 3, 0
    For i = 448 To 1 Step -1
        'FCirc corns(i).x, corns(i).y, 3, &HFF0000FF
        If corns(i).falling Then
            corns(i).y = corns(i).y + corns(i).dy
            If corns(i).y > _Height Then
                corns(i).y = corns(i).savey ' back to start position
                corns(i).frac = .1 ' small start
                corns(i).falling = 0 ' no longer falling
            Else
                RotoZoom corns(i).x, corns(i).y, CC&, corns(i).scale / 10, 0
                corns(i).dy = corns(i).dy + .5
            End If
        Else
            RotoZoom corns(i).x, corns(i).y, CC&, corns(i).frac * corns(i).scale / 10, 0
            corns(i).frac = corns(i).frac + .001
            If corns(i).frac > 1.0 Then
                corns(i).frac = .1: corns(i).falling = 1: corns(i).dy = 1
            End If
        End If
    Next
    If _KeyDown(32) Then GoTo restart
    _PutImage , 0, ref&, (0, 0)-(xmax, .8 * ymax)
    _PutImage (0, .8 * ymax)-(xmax, ymax), ref&, 0, (0, _Height(ref&))-(xmax, 0)
    _Display
    _Limit 30
Loop Until _KeyDown(27)

Sub makeBackground
    Dim As Long i, stars
    Dim horizon
    _Dest bk
    For i = 0 To ymax
        Line (0, i)-(xmax, i), _RGB32(70, 60, i / ymax * 160)
    Next
    stars = xmax * ymax * 10 ^ -4
    horizon = .67 * ymax
    For i = 1 To stars 'stars in sky
        PSet (Rnd * xmax, Rnd * horizon), _RGB32(175 + Rnd * 80, 175 + Rnd * 80, 175 + Rnd * 80)
    Next
    stars = stars / 2
    For i = 1 To stars
        FCirc Rnd * xmax, Rnd * horizon, 1, _RGB32(175 + Rnd * 80, 175 + Rnd * 80, 175 + Rnd * 80)
    Next
    stars = stars / 2
    For i = 1 To stars
        FCirc Rnd * xmax, Rnd * horizon, 2, _RGB32(175 + Rnd * 80, 175 + Rnd * 80, 175 + Rnd * 80)
    Next
    DrawTerrain 405, 25, &HFF002255
    DrawTerrain 420, 15, &HFF224444
    DrawTerrain 435, 6, &HFF448855
    DrawTerrain 450, 5, &HFF88FF66
    _Dest 0
End Sub

Sub branch (x, y, startr, angD, lngth, lev, tree, leafTF)
    Dim As Double x2, y2, dx, dy
    Dim As Long i, lev2
    x2 = x + Cos(_D2R(angD)) * lngth
    y2 = y - Sin(_D2R(angD)) * lngth
    dx = (x2 - x) / lngth
    dy = (y2 - y) / lngth
    For i = 0 To lngth
        FCirc x + dx * i, y + dy * i, startr, changePlasma~&(tree)
    Next
    If startr <= 0 Or lev > 11 Or lngth < 5 Then
        If leafTF Then
            leaf = leaf + 1
            corns(leaf).scale = .5 * tree + 1 '.4 - (4 - tree) * .01 ' .075
            corns(leaf).x = x2
            corns(leaf).y = y2
            corns(leaf).savey = y2
        End If
        Exit Sub
    Else
        lev2 = lev + 1
        branch x2, y2, startr - 1, angD + 10 + 30 * Rnd, .8 * lngth + .2 * Rnd * lngth, lev2, tree, leafTF
        branch x2, y2, startr - 1, angD - 10 - 30 * Rnd, .8 * lngth + .2 * Rnd * lngth, lev2, tree, leafTF
    End If
End Sub

Sub FCirc (CX As Long, CY As Long, R As Long, C As _Unsigned Long)
    Dim Radius As Long, RadiusError As Long
    Dim X As Long, Y As Long
    Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0
    If Radius = 0 Then PSet (CX, CY), C: Exit Sub
    Line (CX - X, CY)-(CX + X, CY), C, BF
    While X > Y
        RadiusError = RadiusError + Y * 2 + 1
        If RadiusError >= 0 Then
            If X <> Y + 1 Then
                Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
                Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
            End If
            X = X - 1
            RadiusError = RadiusError - X * 2
        End If
        Y = Y + 1
        Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
        Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
    Wend
End Sub

Function changePlasma~& (n) ' red green for reds and yellows
    cN = cN - 1 'dim shared cN as _Integer64, pR as long, pG as long, pB as long
    changePlasma~& = _RGB32(127 + 127 * Sin(rd(n) * cN), 127 + 127 * Sin(gn(n) * cN), 0)
End Function

Sub DrawTerrain (h, modN, c As _Unsigned Long) ' modN for ruggedness the higher the less smooth
    Dim x, dy
    For x = 0 To _Width
        If x Mod modN = 0 Then ' adjust mod number for ruggedness the higher the number the more jagged
            If h < 600 - modN And h > 50 + modN Then
                dy = Rnd * 20 - 10
            ElseIf h >= 600 - modN Then
                dy = Rnd * -10
            ElseIf h <= 50 + modN Then
                dy = Rnd * 10
            End If
        End If
        h = h + .1 * dy
        Line (x, _Height)-(x, h), c
    Next
End Sub

Sub RotoZoom (X As Long, Y As Long, Image As Long, Scale As Double, degreesRotation As Double)
    Dim px(3) As Single, py(3) As Single, W&, H&, sinr!, cosr!, i&, x2&, y2&
    W& = _Width(Image&): H& = _Height(Image&)
    px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
    px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
    sinr! = Sin(-degreesRotation / 57.2957795131): cosr! = Cos(-degreesRotation / 57.2957795131)
    For i& = 0 To 3
        x2& = (px(i&) * cosr! + sinr! * py(i&)) * Scale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * Scale + Y
        px(i&) = x2&: py(i&) = y2&
    Next
    _MapTriangle (0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image& To(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
    _MapTriangle (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

Candy Corn 1.PNG
   
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply


Messages In This Thread
Candy Corn Trees - by bplus - 10-11-2025, 03:37 PM
RE: Candy Corn Trees - by bplus - 10-12-2025, 12:26 AM
RE: Candy Corn Trees - by madscijr - 10-12-2025, 01:20 AM
RE: Candy Corn Trees - by bplus - 10-12-2025, 05:44 AM
RE: Candy Corn Trees - by vince - 10-12-2025, 01:49 PM
RE: Candy Corn Trees - by bplus - 10-12-2025, 02:56 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)