QB64 Phoenix Edition
Simple Random Hills Maker - Printable Version

+- QB64 Phoenix Edition (https://staging.qb64phoenix.com)
+-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3)
+---- Forum: Programs (https://staging.qb64phoenix.com/forumdisplay.php?fid=7)
+---- Thread: Simple Random Hills Maker (/showthread.php?tid=874)



Simple Random Hills Maker - SierraKen - 09-09-2022

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



RE: Simple Random Hills Maker - CharlieJV - 09-10-2022

(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:


RE: Simple Random Hills Maker - 40wattstudio - 09-10-2022

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


RE: Simple Random Hills Maker - SierraKen - 09-10-2022

LOL thanks guys. Smile Whenever I get bored or have extra time, I often play around with equations and graphics.


RE: Simple Random Hills Maker - bplus - 09-10-2022

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



RE: Simple Random Hills Maker - dbox - 09-11-2022

This one looks great in QBJS with no modifications:  View in QBJS