' This program exported from BASIC Anywhere Machine (Version [5.2.3].[2023.10.26.02.14]) on 2023.11.11 at 03:35 (Coordinated Universal Time) _TITLE "BAM Draw" OPTION EXPLICIT ' Program by Charlie Veniot ' 🟠🟠🟠 DECLARATIONS ' multi-use variables VAR temp$, what_drawing$, this_mark$, this_marker$, this_f_color%, this_b_color% VAR i%, iy%, ix% ' screen variables CONST minw% = 33, maxw% = 260, minh% = 1, maxh% = 51 VAR w% = 0, h% = 0 VAR grid% = TRUE ' menu constants / variables CONST menuh% = 3 ' number of rows in footer menu CONST fc4bc%(0 to 15) = {15,15,15,15,15,15,15,0,15,15,0,0,0,0,0,0} VAR color_menu_mode$ = "Foreground" CONST vmic% = 8 ' vmic = variable menu items count CONST vmi$(1 TO vmic%) = { "Grid","Wdth","Hght","Xprt","MovL","MovR","MovU","MovD" } ' vmi = variable menu item FOR i% = 1 TO vmic% : _MAPSET(vmi$(i%), i%) : NEXT i% VAR more_menu_pick$ = "Grid" ' marker variables VAR marker$ = " " VAR f_color% = 15, b_color% = 0 ' mouse/touch variables VAR x%, y% ' 🟠🟠🟠 MAIN PROGRAM GOSUB ⚙init_program 🔃drawing_cycle: _DISPLAY LET temp$ = INKEY$ IF temp$ <> "" THEN marker$ = temp$ : GOSUB ✒set_marker IF _MOUSEBUTTON THEN IF _MOUSEZONE (0, 0, _WIDTH, [_HEIGHT-(menuh%*8)] ) _ THEN GOSUB ✒do_marker_mark : GOTO ⏩done WHILE _MOUSEBUTTON : WEND IF _MOUSEZONE(40, yMAX - 7, 64, 8 ) _ THEN GOSUB ✒change_marker : GOTO ⏩done IF _MOUSEZONE(0, yMAX - 7, 32, 8 ) _ THEN GOSUB 🖥do_variable_menu_handling : GOTO ⏩done IF _MOUSEZONE(0, yMAX - 15, 32, 8 ) _ THEN GOSUB 🖥toggle_variable_menu : GOTO ⏩done IF _MOUSEZONE(8*5, yMAX - 15, 88, 8 ) _ THEN GOSUB 🎨toggle_color_menu_mode : GOTO ⏩done IF _MOUSEZONE(8*6+80, yMAX - 15, 128, 16 ) _ THEN GOSUB 🎨change_color : GOTO ⏩done ⏩done: END IF GOTO 🔃drawing_cycle END ' 🟠🟠🟠 SUBROUTINES ⚙init_program: IF GetLocalStorageItem( "draw:height" ) <> "" _ THEN LET what_drawing$ = NVL$(_PROMPT("Continue previous drawing or start a new drawing?\n\n 'C' to continue previous drawing, 'N' for new drawing", "C"), "C") IF UCASE$( what_drawing$ ) = "C" _ THEN GOSUB ⚙do_continue_canvas _ ELSE GOSUB ⚙do_new_canvas RETURN ⚙do_new_canvas: GOSUB ⚙prompt_width GOSUB ⚙prompt_height i% = MAX(1,NVL$(GetLocalStorageItem( "draw:height" ), 20)) FOR iy% = 1 TO i% FOR ix% = 1 TO MAX( minw%, GetLocalStorageItem( "draw:width" ) ) RemoveLocalStorageItem("draw:mark:" + iy% +"," + ix%) NEXT ix% NEXT iy% SetLocalStorageItem( "draw:f_color", 15 ) SetLocalStorageItem( "draw:b_color", 0 ) GOSUB ✒set_marker GOSUB 🖥setup_screen RETURN ⚙prompt_width: LET i% = _PROMPT( "Canvas Width (i.e. how many characters wide, minimum = " + minw% + ")", MAX(w%/8,minw%) ) LET w% = IFF(i%"" THEN LET this_marker$ = LEFT$(this_mark$, 1) : LET this_mark$ = RIGHT$(this_mark$, LEN(this_mark$) - 2) LET this_f_color% = VAL(LEFT$(this_mark$, INSTR(this_mark$, ",") - 1)) LET this_b_color% = VAL(RIGHT$(this_mark$, LEN(this_mark$) - INSTR(this_mark$, ","))) COLOR this_f_color%, this_b_color% LOCATE iy%, ix% : PRINT this_marker$; ELSE COLOR 15, 0 : LOCATE iy%, ix% : PRINT " "; END IF NEXT ix% NEXT iy% IF grid% THEN GOSUB 🖥do_grid COLOR f_color%, b_color% RETURN 🖥toggle_variable_menu: ' WHILE _MOUSEBUTTON : WEND i% = _MAPGET(more_menu_pick$) + 1 : IF i% > vmic% THEN i% = 1 more_menu_pick$ = vmi$(i%) GOSUB 🖥show_more_menu_pick RETURN 🖥do_variable_menu_handling: ' WHILE _MOUSEBUTTON : WEND ON _MAPGET(more_menu_pick$) GOSUB 🖥toggle_grid, ⚙prompt_width, ⚙prompt_height, 🔧do_export, 🧭MovL, 🧭MovR, 🧭MovU, 🧭MovD IF BETWEEN(_MAPGET(more_menu_pick$),2,3) THEN GOSUB 🖥setup_screen : GOSUB 🖥refresh_canvas RETURN 🖥toggle_grid: grid% = NOT grid% IF grid% THEN GOSUB 🖥do_grid ELSE GOSUB 🖥undo_grid RETURN 🖥do_grid: FOR i% = 0 TO xMAX STEP 8 LINE (i%,0) TO (i%,(yMAX-menuh%*8)), 7 NEXT i% FOR i% = 7 TO (yMAX-menuh%*8) STEP 8 LINE (0,i%) TO (xMAX,i%), 7 NEXT i% RETURN 🖥undo_grid: FOR i% = 0 TO xMAX STEP 8 LINE (i%,0) TO (i%,(yMAX-menuh%*8)), 0 NEXT i% FOR i% = 7 TO (yMAX-menuh%*8) STEP 8 LINE (0,i%) TO (xMAX,i%), 0 NEXT i% GOSUB 🖥refresh_canvas RETURN 🖥setup_screen: LET w% = [ MAX(minw%, GetLocalStorageItem( "draw:width" ) ) ] * 8 LET h% = [ MAX(minh%, GetLocalStorageItem( "draw:height" ) ) + menuh% ] * 8 SCREEN _NEWIMAGE( w%, h%, 7 ) GOSUB 🖥do_grid COLOR 15, 0 LINE (0,_HEIGHT-20) TO (xMAX,_HEIGHT-20) : LINE (35,_HEIGHT-20) TO (36, yMAX), ,B LOCATE (_HEIGHT/8)-1, 1 : PRINT STRING$(4,CHR$(240)); LOCATE (_HEIGHT/8), 6 : PRINT "Marker:"; : GOSUB ✒set_marker GOSUB 🖥show_more_menu_pick GOSUB 🎨show_color_menu GOSUB 🎨show_color_picks RETURN 🖥show_more_menu_pick: COLOR 15, 0 LOCATE (_HEIGHT/8), 1 : PRINT more_menu_pick$; COLOR f_color%, b_color% RETURN ✒change_marker: ' WHILE _MOUSEBUTTON : WEND LET marker$ = LEFT$(_PROMPT("Enter one simple keyboard character as a new marker shape.", marker$)+marker$, 1) GOSUB ✒set_marker RETURN ✒do_marker_mark: LET x% = _MOUSEX : LET y% = _MOUSEY LET iy% = FIX(y%/8)+1 : LET ix% = FIX(x%/8)+1 COLOR f_color%, b_color% LOCATE iy%, ix% : PRINT marker$; IF grid% THEN GOSUB 🖥do_grid SetLocalStorageItem( "draw:mark:" + iy% + "," + ix%, marker$ + " " + f_color% + "," + b_color%) RETURN ✒set_marker: LOCATE (_HEIGHT/8), 13 : COLOR f_color%, b_color% : PRINT marker$; SetLocalStorageItem( "draw:marker", marker$ ) RETURN 🎨toggle_color_menu_mode: ' WHILE _MOUSEBUTTON : WEND LET color_menu_mode$ = IFF(color_menu_mode$="Foreground", "Background", "Foreground") GOSUB 🎨show_color_menu RETURN 🎨show_color_menu: COLOR 15,0 LOCATE (_HEIGHT/8)-1, 6 : PRINT color_menu_mode$ + ":"; COLOR f_color%, b_color% RETURN 🎨show_color_picks: FOR i% = 0 TO 15 LOCATE (_HEIGHT/8)-IFF(i%<8,1,0),17+([i%-IFF(i%<8,0,8)]*2) : COLOR i%, 0 : PRINT CHR$(219) + CHR$(219); IF i% = f_color% THEN LOCATE (_HEIGHT/8)-IFF(i%<8,1,0),17+([i% - IFF(i%<8,0,8)]*2) : COLOR fc4bc%(i%),i% : PRINT "F"; IF i% = b_color% THEN LOCATE (_HEIGHT/8)-IFF(i%<8,1,0),17+([i% - IFF(i%<8,0,8)]*2)+1 : COLOR fc4bc%(i%),i% : PRINT "B"; NEXT i% ' COLOR 15,0 COLOR f_color%, b_color% RETURN 🎨change_color: ' WHILE _MOUSEBUTTON : WEND LET f_color% = IFF(color_menu_mode$="Foreground", POINT(_MOUSEX,_MOUSEY), f_color%) LET b_color% = IFF(color_menu_mode$="Background", POINT(_MOUSEX,_MOUSEY), b_color%) SetLocalStorageItem( "draw:f_color", f_color% ) SetLocalStorageItem( "draw:b_color", b_color% ) GOSUB 🎨show_color_picks GOSUB ✒set_marker RETURN 🔧do_export: OPEN "YourDrawing.bas" FOR OUTPUT AS #1 PRINT#1, "SCREEN _NEWIMAGE( " + w% + ", " + (h%-24) + ", 7 )" PRINT#1, "" PRINT#1, "DO" PRINT#1, SPC(2) + "READ row%, col%, marker$, f_color%, b_color%" PRINT#1, SPC(2) + "IF marker$ <> " + CHR$(34) + "END" + CHR$(34) + " THEN _" PRINT#1, SPC(4) + "COLOR f_color%, b_color%" PRINT#1, SPC(4) + "LOCATE row%, col% : PRINT marker$;" PRINT#1, "LOOP UNTIL marker$ = " + CHR$(34) + "END" + CHR$(34) PRINT#1, "" FOR iy% = 1 TO MAX( minh% , GetLocalStorageItem( "draw:height" ) ) FOR ix% = 1 TO MAX( minw%, GetLocalStorageItem( "draw:width" ) ) LET this_mark$ = GetLocalStorageItem( "draw:mark:" + iy% + "," + ix%) IF this_mark$ <> "" THEN LET this_marker$ = LEFT$(this_mark$, 1) : LET this_mark$ = RIGHT$(this_mark$, LEN(this_mark$) - 2) LET this_f_color% = VAL(LEFT$(this_mark$, INSTR(this_mark$, ",") - 1)) LET this_b_color% = VAL(RIGHT$(this_mark$, LEN(this_mark$) - INSTR(this_mark$, ","))) PRINT#1, "DATA " + iy% + ", " + ix% + ", " + CHR$(34) + this_marker$ + CHR$(34) + ", " + this_f_color% + ", " + this_b_color% END IF NEXT ix% NEXT iy% PRINT#1, "DATA -99, -99, " + CHR$(34) + "END" + CHR$(34) + ", -99, -99" CLOSE #1 RETURN ' 🧭🧭🧭 Move Drawing SUB Mov_slsi(y%,x%) SetLocalStorageItem( "draw:mark:" + iy% + "," + ix%, GetLocalStorageItem("draw:mark:" + y% + "," + x% ) ) END SUB DEF FN_h = GetLocalStorageItem("draw:height") DEF FN_w = GetLocalStorageItem("draw:width") 🧭MovL: FOR iy% = 1 TO FN_h : FOR ix% = 1 TO FN_w CALL Mov_slsi(iy%,ix%+1) : NEXT ix%, iy% GOSUB 🖥refresh_canvas RETURN 🧭MovR: FOR iy% = 1 TO FN_h : FOR ix% = FN_w TO 1 STEP -1 CALL Mov_slsi(iy%,ix%-1) : NEXT ix%, iy% GOSUB 🖥refresh_canvas RETURN 🧭MovU: FOR iy% = 1 TO FN_h : FOR ix% = 1 TO FN_w CALL Mov_slsi(iy%+1,ix%) : NEXT ix%, iy% GOSUB 🖥refresh_canvas RETURN 🧭MovD: FOR iy% = FN_h TO 1 STEP - 1 : FOR ix% = 1 TO FN_w CALL Mov_slsi(iy%-1,ix%) : NEXT ix%, iy% GOSUB 🖥refresh_canvas RETURN