'Circular Mazes
'By Sierraken on June 13, 2020.  Mod B+ wall fix and some help.
'This one saves as a JPG picture. You need to have 2 libraries in the same folder: saveimage.bi and saveimage.bm.
'$include:'saveimage.bi'
$COLOR:32
_LIMIT 300
begin:
CLS
_TITLE "Circular Maze Generator"
s& = _NEWIMAGE(800, 600, 32)
SCREEN s&
PRINT: PRINT
c$ = "b"
start:
circles = 12
_TITLE "Space Bar to make new maze, (S)ave, (P)rint, Esc to quit."
PAINT (1, 1), _RGB32(255, 255, 255)
RANDOMIZE TIMER
sz = 250
x = 400: y = 300
r2 = .25
FOR cir = 1 TO circles
    r1 = (RND * 5) + 1
    IF cir > 10 THEN r2 = .5
    cl = cir
    CIRCLE (x, y), sz, _RGB32(0, cl, 0), r1, r1 - r2
    _DELAY .25
    sz = sz - 20: wsz = 19
NEXT cir
sz = 250
FOR wall = 1 TO circles - 1
    ra = _PI(2) * RND
    LINE (x + sz * COS(ra), y + sz * SIN(ra))-(x + (sz - 20) * COS(ra), y + (sz - 20) * SIN(ra)), _RGB32(0)
    sz = sz - 20
NEXT
keys:
_PUTIMAGE , s&
SCREEN s&
IF sav = 1 THEN Result = SaveImage(nm$, 0, 0, 0, _WIDTH(img), _HEIGHT(img)): sav = 0 'first zero is your screen, second zero is X start, 3th zero is y start


DO
    a$ = INKEY$
    IF a$ = CHR$(27) THEN END
    IF a$ = " " THEN GOTO begin:
    IF a$ = "p" OR a$ = "P" THEN
        IF col = 0 THEN
            j& = _COPYIMAGE(0)
            _DELAY .25
            INPUT "Print on printer (Y/N)?", i$ 'print screen page on printer
            CLS
            SCREEN j&
            _DELAY .25
            IF LEFT$(i$, 1) = "y" OR LEFT$(i$, 1) = "Y" THEN
                'printer prep (code copied and pasted from bplus Free Calendar Program)
                YMAX = _HEIGHT: XMAX = _WIDTH
                landscape& = _NEWIMAGE(YMAX, XMAX, 32)
                _MAPTRIANGLE (XMAX, 0)-(0, 0)-(0, YMAX), 0 TO(0, 0)-(0, XMAX)-(YMAX, XMAX), landscape&
                _MAPTRIANGLE (XMAX, 0)-(XMAX, YMAX)-(0, YMAX), 0 TO(0, 0)-(YMAX, 0)-(YMAX, XMAX), landscape&
                _PRINTIMAGE landscape&
                _DELAY 2
                landscape& = 0
                s& = j&
            END IF
        END IF
    END IF
    IF a$ = "S" OR a$ = "s" THEN GOTO saving:
LOOP

saving:
s& = _COPYIMAGE(0)
CLS
PRINT "                       Saving"
PRINT
PRINT "         Your jpg file will be saved in the"
PRINT "         same directory as this program is."
PRINT "         It can be used with almost any"
PRINT "         other graphics program or website."
PRINT "         It is saved using:"
PRINT "         width: 800  height: 600 pixels."
PRINT
PRINT "         Type a name to save your picture"
PRINT "         and press the Enter key. Do not"
PRINT "         add .jpg at the end, the program"
PRINT "         will do it automatically."
PRINT
PRINT "         Example: MyPic"
PRINT "         Quit and Enter key ends program."
PRINT
INPUT "         ->"; nm$
IF nm$ = "Quit" OR nm$ = "quit" OR nm$ = "QUIT" THEN END
nm$ = nm$ + ".jpg"
'Checking to see if the file already exists on your computer.
theFileExists = _FILEEXISTS(nm$)
IF theFileExists = -1 THEN
    PRINT
    PRINT "       File Already Exists"
    PRINT "       Saving will delete your old"
    PRINT "       jpg picture."
    PRINT "       Would you like to still do it?"
    PRINT "      (Y/N)."
    PRINT "      Esc goes to start screen."
    llloop:
    _LIMIT 100
    ag2$ = INKEY$
    IF ag2$ = CHR$(27) THEN GOTO start:
    IF ag2$ = "" THEN GOTO llloop:
    IF ag2$ = "y" OR ag$ = "Y" THEN
        SHELL _HIDE "DEL " + nm$
        GOTO saving2:
    END IF
    GOTO llloop:
END IF
saving2:
CLS
sav = 1
FOR snd = 100 TO 700 STEP 100
    SOUND snd, 2
NEXT snd

GOTO keys:
'$include:'saveimage.bm'

