Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scene Generator 2
#1
For awhile, I was doing a lot of graphical stuff. Here is one of them that makes a random scene of hills, trees, and a randomly placed creek. On this new version, I added file dialog to save the picture to JPG, PNG, GIF, or BMP. Press S to Save the picture if you wish, or the Space Bar to make a new picture. 

Code: (Select All)

'Made on Dec. 21, 2019 by SierraKen
'Version 2: August 14, 2024 added file dialog box when saving.

_Title "Scene Generator 2 - by SierraKen - Space Bar for new scene, (S)ave Picture, Esc to quit."
start:
_Limit 500
Cls
picture& = _NewImage(800, 600, 32)
Screen picture&
'Draw sky.
Randomize Timer
sky = Int(Rnd * 154) + 100
For sk = 0 To 299
    sky = sky + .25
    If sky > 255 Then sky = 255
    Line (0, sk)-(800, sk), _RGB32(0, 0, sky)
Next sk
'Draw ground.
Randomize Timer
cc2 = Int(Rnd * 50) + 20
For cc = 300 To 600
    cc2 = cc2 + .5
    Line (0, cc)-(800, cc), _RGB32(116, cc2, 0)
Next cc
y = 300
Randomize Timer
c1 = Int(Rnd * 100) + 20
c2 = Int(Rnd * 150) + 60
c4 = c2
c3 = Int(Rnd * 100) + 20
t = 0
tt = 0
si = 0
'Draw hills.
amount = Int(Rnd * 40) + 5
For t = 1 To amount
    _Limit 100
    Randomize Timer
    x = (Rnd * 800) + 1
    s = (Rnd * 250) + 1
    aspect = Rnd * 2
    For sz = .25 To s Step .25
        c2 = c2 + .05
        If c2 > 255 Then c2 = 255
        Circle (x, y), sz, _RGB32(c1, c2, c3), 2 * _Pi, _Pi, aspect
    Next sz
    c2 = c4
    l = .5
Next t
'Draw grass.
For grassy = 300 To 600 Step 2.5
    For grassx = 0 To 800 Step 2
        Randomize Timer
        sst = Rnd * 2
        sst2 = Rnd * 1
        Line (grassx + sst, grassy + sst2)-(grassx + sst, (grassy + sst2) - l), _RGB32(50, 255, 127)
    Next grassx
    l = l + .025
    If l > 4 Then l = 4
Next grassy
'Draw random river.
yy = 305
Randomize Timer
xx = (Rnd * 650) + 50
rw = 2
Do
    If yy > 600 Then GoTo trees:
    _Delay .1
    tt = tt + 1
    si = si + 1
    yy = yy + (si * 2)
    If tt = 1 Then
        For sz = 1 To 5 Step .25
            Circle (xx, yy), si + sz, _RGB32(6, 128, 255), _Pi / 2, (3 / 2) * _Pi
        Next sz
    End If
    If tt = 2 Then
        For sz = 1 To 5 Step .25
            Circle (xx, yy), si - sz, _RGB32(6, 128, 255), (3 / 2) * _Pi, _Pi / 2
        Next sz
        tt = 0
    End If
Loop
'Bare Trees
trees:
Randomize Timer
trees = Int(Rnd * 25) + 3
For tree = 1 To trees
    Randomize Timer
    xt = Rnd * 800
    yt = (Rnd * 300) + 300
    length = yt * 8 / 160
    th = yt / 100
    For thick = 1 To th
        Line (xt + thick, yt)-(xt + thick, yt - length), _RGB32(211, 83, 6)
        'left side
        Line (xt + thick, yt - length)-((xt - length) + thick, yt - length * 2), _RGB32(211, 83, 6)
        Line ((xt - length) + thick, yt - (length * 2))-((xt - (length * 2)) + thick, yt - (length * 3)), _RGB32(211, 83, 6)
        Line ((xt - length) + thick, yt - (length * 2))-((xt - (length * 1.5) + thick), yt - (length * 3)), _RGB32(211, 83, 6)
        'right side
        Line ((xt + thick), yt - length)-((xt + length) + thick, yt - (length * 2)), _RGB32(211, 83, 6)
        Line ((xt + length) + thick, yt - (length * 2))-((xt + (length * 2) + thick), yt - (length * 3)), _RGB32(211, 83, 6)
        Line ((xt + length) + thick, yt - (length * 2))-((xt + (length * 1.5) + thick), yt - (length * 3)), _RGB32(211, 83, 6)
    Next thick
Next tree

again:
ag$ = InKey$
If ag$ = "s" Or ag$ = "S" Then GoTo saving:
If ag$ = " " Then GoTo start:
If ag$ = Chr$(27) Then End
GoTo again:
saving:
picture2& = _CopyImage(picture&)
_Delay .2
saving2:
nm$ = _SaveFileDialog$("Save File", "", "*.jpg|*.png|*.gif|*.bmp", "Picture Files .jpg,.png,.gif,.bmp")
If nm$ = "" Then GoTo again:
_SaveImage nm$, picture&
For snd = 100 To 700 Step 100
    Sound snd, 2
Next snd
GoTo again:







Reply


Messages In This Thread
Scene Generator 2 - by SierraKen - 08-15-2024, 05:52 AM



Users browsing this thread: 1 Guest(s)