Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple Random Hills Maker
#1
This code can be used in adventure games or any other type of game or app. It makes random looking hills on the screen and when you press the Space Bar it makes different looking ones. I was experimenting with graphics. You can also change the PSET _RGB32 color to blue if you wish to make water waves instead. Just replace the last 0 with the c and the c with a 0.  

Code: (Select All)
'Random Hills Maker by SierraKen 9-9-2022
_Title "Random Hills Maker - Press Space Bar For Another One - Esc to quit"
Screen _NewImage(800, 600, 32)
start:
_Limit 20
Cls
Paint (10, 10), _RGB32(127, 255, 255)
c = 255
size = (Rnd * 500) + 55
For s = 50 To size Step (size / 10)
    For yy = 100 To 650
        For i = 0 To 1200
            x = Sin((i / s) * 3.1415)
            PSet (((i / 360) * 320) - 100, (x * 50) + 50 + yy), _RGB32(0, c, 0)
        Next i
        c = c - 1
        If c < 100 Then c = 255
    Next yy
Next s
Do
    a$ = InKey$
    If a$ = " " Then GoTo start:
    If a$ = Chr$(27) Then End
Loop
Reply
#2
(09-09-2022, 08:18 PM)SierraKen Wrote: This code can be used in adventure games or any other type of game or app. It makes random looking hills on the screen and when you press the Space Bar it makes different looking ones. I was experimenting with graphics. You can also change the PSET _RGB32 color to blue if you wish to make water waves instead. Just replace the last 0 with the c and the c with a 0.  

Code: (Select All)
'Random Hills Maker by SierraKen 9-9-2022
_Title "Random Hills Maker - Press Space Bar For Another One - Esc to quit"
Screen _NewImage(800, 600, 32)
start:
_Limit 20
Cls
Paint (10, 10), _RGB32(127, 255, 255)
c = 255
size = (Rnd * 500) + 55
For s = 50 To size Step (size / 10)
    For yy = 100 To 650
        For i = 0 To 1200
            x = Sin((i / s) * 3.1415)
            PSet (((i / 360) * 320) - 100, (x * 50) + 50 + yy), _RGB32(0, c, 0)
        Next i
        c = c - 1
        If c < 100 Then c = 255
    Next yy
Next s
Do
    a$ = InKey$
    If a$ = " " Then GoTo start:
    If a$ = Chr$(27) Then End
Loop

That was fun.  Thanks for sharing!

BAM version:
Reply
#3
Pretty cool! I like programs that can create a variety of random graphical elements. And nice to see that I'm not the only one who still occasionally uses GOTO statements in their code Tongue
Reply
#4
LOL thanks guys. Smile Whenever I get bored or have extra time, I often play around with equations and graphics.
Reply
#5
Oh what the hill?

Code: (Select All)
_Title "Rnd Hills" 'b+ 2022-09-10
Screen _NewImage(800, 600, 32)
Randomize Timer
Do
    a = 0: b = 0
    For y = 0 To 500
        Line (0, y)-(_Width - 1, y), _RGB32(100, 100, y / 500 * 155 + 100)
    Next
    For y = 300 To 500 Step 25
        a = .1 * a + Rnd * 30 - 15: b = .1 * b + Rnd * 60 - 30
        For x = 0 To 800
            h = y + a * Sin(_D2R(2 * x)) + b * Sin(_D2R(.5 * x))
            Line (x, h)-(x, _Height), _RGB32(0, 200 - 128 * (y - 300) / 200, 0)
        Next
    Next
    Sleep
Loop Until _KeyDown(27) 'escape
b = b + ...
Reply
#6
This one looks great in QBJS with no modifications:  View in QBJS
Reply




Users browsing this thread: 1 Guest(s)