Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
4 Section Grid Terrain
#1
I found some code for just 1 small mountain spike and 1 small indention spike on a grid on a FB group page, so I've been experimenting with it for hours and came up with 4 sections of connected grids with 1 random mountain on each and 1 random indention on each. Every time you press the Space Bar it makes a new one. Press Esc to quit.

I realize the 4 sections makes it ugly, but it's as good as I can make it for myself. Feel free to do what you wish with it. I got a little bit of help with ChatGPT for connecting the grids together. 

Code: (Select All)

'From BASIC Programming Language FB Group
'Edited by SierraKen

_Title "Mountains - Press Space Bar For More, Esc to quit"
Cls
Screen _NewImage(800, 600, 32)
'120 XA = 6: YA = 5: ZA = 11: XB = 15: YB = 4: ZB = -13
Do
    Randomize Timer
    XA = Rnd * 10: YA = Rnd * 10: ZA = Rnd * 15: XB = Rnd * 10: YB = Rnd * 10: ZB = Rnd * -15
    For Y = 0 To 20: For X = 0 To 10
            t = X: GoSub calculations
    Next X: Next Y
    For X = 0 To 10: For Y = 0 To 20
            t = Y: GoSub calculations
    Next Y: Next X

    t = 0
    XA2 = (Rnd * 10) + 10: YA2 = Rnd * 10: ZA2 = Rnd * 15: XB2 = (Rnd * 10) + 10: YB2 = Rnd * 10: ZB2 = Rnd * -15
    For Y = 0 To 20: For X = 10 To 20
            t = X: GoSub calculations2
    Next X: Next Y
    For X = 10 To 20: For Y = 0 To 20
            t = Y: GoSub calculations2
    Next Y: Next X

    ' Draw connection lines between Grid 1 and Grid 2 at X = 10
    For Y = 0 To 20
        X = 10: t = X: GoSub calculations ' Get (XOLD, YOLD) at X=10 from Grid 1
        X = 10: t = X: GoSub calculations2 ' Get (XNEW2, YNEW2) at X=10 from Grid 2
        Line (XOLD, YOLD)-(XNEW2, YNEW2), _RGB32(0, 255, 0)
    Next Y

    XA3 = (Rnd * 10): YA3 = (Rnd * 10): ZA3 = Rnd * 15: XB3 = (Rnd * 10): YB3 = (Rnd * 10): ZB3 = Rnd * -15
    For Y = 0 To 20: For X = 0 To 10
            t = X: GoSub calculations3
    Next X: Next Y
    For X = 0 To 10: For Y = 0 To 20
            t = Y: GoSub calculations3
    Next Y: Next X

    t = 0
    XA4 = (Rnd * 10) + 10: YA4 = (Rnd * 10): ZA4 = Rnd * 15: XB4 = (Rnd * 10) + 10: YB4 = (Rnd * 10): ZB4 = Rnd * -15
    For Y = 0 To 20: For X = 10 To 20
            t = X: GoSub calculations4
    Next X: Next Y
    For X = 10 To 20: For Y = 0 To 20
            t = Y: GoSub calculations4
    Next Y: Next X

    ' Draw connection lines between Grid 1 and Grid 2 at X = 10
    For Y = 0 To 20
        X = 10: t = X: GoSub calculations3 ' Get (XOLD, YOLD) at X=10 from Grid 1
        X = 10: t = X: GoSub calculations4 ' Get (XNEW2, YNEW2) at X=10 from Grid 2
        Line (XOLD3, YOLD3)-(XNEW4, YNEW4), _RGB32(0, 255, 0)
    Next Y
    ' === Connect TOP and BOTTOM left grids ===
    For X = 0 To 10
        Y = 20: t = Y: GoSub calculations ' Bottom edge of top-left grid
        Y = 0: t = Y: GoSub calculations3 ' Top edge of bottom-left grid
        Line (XNEW, YNEW)-(XNEW3, YNEW3), _RGB32(255, 255, 0)
    Next X

    ' === Connect TOP and BOTTOM right grids ===
    For X = 10 To 20
        Y = 20: t = Y: GoSub calculations2 ' Bottom edge of top-right grid
        Y = 0: t = Y: GoSub calculations4 ' Top edge of bottom-right grid
        Line (XNEW2, YNEW2)-(XNEW4, YNEW4), _RGB32(255, 255, 0)
    Next X

    Do
        a$ = InKey$
        If a$ = Chr$(27) Then End
    Loop Until a$ = " "
    Cls
Loop
r = 0
rr = 0

End

calculations:
XNEW = X * 20 + 10 * Y: Rem subroutine
L = Sqr((XA - X) ^ 2 + (YA - Y) ^ 2) + 1: Rem distance
L2 = Sqr((XB - X) ^ 2 + (YB - Y) ^ 2) + 1: Rem 2nd distance
YNEW = 200 - Y * 5 - 10 * (ZA / L + ZB / L2) + 300
If t > 0 Then Line (XOLD, YOLD)-(XNEW, YNEW), _RGB32(0, 255, 0)
XOLD = XNEW: YOLD = YNEW
Return

calculations2:
r = r + 1
If r = 1 Then
    xold2 = XOLD
    yold2 = YOLD
End If
XNEW2 = X * 20 + 10 * Y: Rem subroutine
L = Sqr((XA2 - X) ^ 2 + (YA2 - Y) ^ 2) + 1: Rem distance
L2 = Sqr((XB2 - X) ^ 2 + (YB2 - Y) ^ 2) + 1: Rem 2nd distance
YNEW2 = 200 - Y * 5 - 10 * (ZA2 / L + ZB2 / L2) + 300
If t > 0 Then Line (xold2, yold2)-(XNEW2, YNEW2), _RGB32(0, 255, 0)
xold2 = XNEW2: yold2 = YNEW2
Return

calculations3:
XNEW3 = X * 20 + 10 * Y + 200: Rem subroutine
L = Sqr((XA3 - X) ^ 2 + (YA3 - Y) ^ 2) + 1: Rem distance
L2 = Sqr((XB3 - X) ^ 2 + (YB3 - Y) ^ 2) + 1: Rem 2nd distance
YNEW3 = 200 - Y * 5 - 10 * (ZA3 / L + ZB3 / L2) + 200
If t > 0 Then Line (XOLD3, YOLD3)-(XNEW3, YNEW3), _RGB32(0, 255, 0)
XOLD3 = XNEW3: YOLD3 = YNEW3
Return

calculations4:
rr = rr + 1
If rr = 1 Then
    XOLD4 = XOLD3
    YOLD4 = YOLD3
End If
XNEW4 = X * 20 + 10 * Y + 200: Rem subroutine
L = Sqr((XA4 - X) ^ 2 + (YA4 - Y) ^ 2) + 1: Rem distance
L2 = Sqr((XB4 - X) ^ 2 + (YB4 - Y) ^ 2) + 1: Rem 2nd distance
YNEW4 = 200 - Y * 5 - 10 * (ZA4 / L + ZB4 / L2) + 200
If t > 0 Then Line (XOLD4, YOLD4)-(XNEW4, YNEW4), _RGB32(0, 255, 0)
XOLD4 = XNEW4: YOLD4 = YNEW4
Return

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Demo: Adaptable Hardware Grid Pete 1 182 02-01-2026, 08:16 PM
Last Post: grymmjack
  Many Mountains Terrain on One Grid SierraKen 4 813 07-30-2025, 05:45 PM
Last Post: DANILIN
Video PLAY music grid wiki example code review grymmjack 2 808 06-13-2023, 01:19 AM
Last Post: bplus

Forum Jump:


Users browsing this thread: 1 Guest(s)