' This program exported from BASIC Anywhere Machine (Version [5.2.3].[2023.10.26.02.14]) on 2023.11.06 at 04:45 (Coordinated Universal Time) _TITLE "BAM Draw" OPTION EXPLICIT ' Program by Charlie Veniot ' 🟠🟠🟠 DECLARATIONS ' screen variables CONST minw% = 52, maxw% = 260, minh% = 1, maxh% = 51 VAR w% = 0, h% = 0 VAR grid% = TRUE ' menu constants / variables CONST menuh% = 3 VAR color_menu_mode$ = "Foreground" ' pen variables VAR pen$ = " " VAR f_color% = 15, b_color% = 0 ' mouse/touch variables VAR x%, y% ' other variables VAR temp$, what_drawing$, this_mark$, this_pen$, this_f_color%, this_b_color% VAR i%, iy%, ix% ' 🟠🟠🟠 MAIN PROGRAM GOSUB ⚙init_program 🔃drawing_cycle: _DISPLAY LET temp$ = INKEY$ IF temp$ <> "" THEN pen$ = temp$ : GOSUB ✒set_pen IF _MOUSEBUTTON THEN IF _MOUSEZONE (0, 0, _WIDTH, [_HEIGHT-(menuh%*8)] ) _ THEN GOSUB ✒do_pen_mark : GOTO ⏩done IF _MOUSEZONE(0, yMAX - 15, 40, 8 ) _ THEN GOSUB ✒change_pen : GOTO ⏩done IF _MOUSEZONE(0, yMAX - 7, 32, 8 ) _ THEN GOSUB 🖥toggle_grid : GOTO ⏩done IF _MOUSEZONE(8*6, yMAX - 15, 88, 8 ) _ THEN GOSUB 🎨toggle_color_menu_mode : GOTO ⏩done IF _MOUSEZONE(8*6+88, yMAX - 15, 256, 8 ) _ THEN GOSUB 🎨change_color : GOTO ⏩done ⏩done: END IF GOTO 🔃drawing_cycle END ' 🟠🟠🟠 SUBROUTINES ⚙init_program: IF GetLocalStorageItem( "draw:height" ) <> "" _ THEN LET what_drawing$ = _PROMPT("Continue previous drawing or start a new drawing?\n\n 'C' to continue previous drawing, 'N' for new drawing", "C") IF UCASE$( what_drawing$ ) = "C" _ THEN GOSUB ⚙do_continue_canvas _ ELSE GOSUB ⚙do_new_canvas RETURN ⚙do_new_canvas: LET w% = MAX( minw%, _ _PROMPT( "Canvas Width (i.e. how many characters wide, minimum = " + minw% + ")", minw%) ) LET h% = MAX( minh%, _ _PROMPT( "Canvas Width (i.e. how many characters wide, minimum = " + minh% + ")", 20) ) FOR iy% = 1 TO MAX( minh% , GetLocalStorageItem( "draw:width" ) ) FOR ix% = 1 TO MAX( minw%, GetLocalStorageItem( "draw:width" ) ) RemoveLocalStorageItem("draw:mark:" + iy% +"," + ix%) NEXT ix% NEXT iy% SetLocalStorageItem( "draw:width", w% ) SetLocalStorageItem( "draw:height", h% ) LET w% = w% * 8 LET h% = h% * 8 GOSUB ✒set_pen GOSUB 🖥setup_screen RETURN ⚙do_continue_canvas: LET pen$ = GetLocalStorageItem( "draw:pen" ) LET f_color% = GetLocalStorageItem( "draw:f_color" ) LET b_color% = GetLocalStorageItem( "draw:b_color" ) GOSUB 🖥setup_screen GOSUB 🖥refresh_canvas GOSUB 🖥do_grid RETURN 🖥refresh_canvas: 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_pen$ = 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_pen$; END IF NEXT ix% NEXT iy% COLOR f_color%, b_color% RETURN 🖥toggle_grid: WHILE _MOUSEBUTTON : WEND 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: IF w% <> [ MAX(minw%, GetLocalStorageItem( "draw:width" ) ) ] * 8 _ OR h% <> [ MAX(minh%, GetLocalStorageItem( "draw:height" ) ) + menuh% ] * 8 _ THEN 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 LINE (0,_HEIGHT-20) TO (xMAX,_HEIGHT-20), 15 LOCATE (_HEIGHT/8)-1, 1 : PRINT "Pen:"; : GOSUB ✒set_pen LOCATE (_HEIGHT/8)-1, 7 : PRINT color_menu_mode$ + ":"; LOCATE (_HEIGHT/8), 1 : PRINT "Grid"; GOSUB 🎨show_color_picks END IF RETURN ✒change_pen: WHILE _MOUSEBUTTON : WEND LET pen$ = LEFT$(_PROMPT("Enter one simple keyboard character as a new pen shape.", pen$), 1) GOSUB ✒set_pen RETURN ✒do_pen_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 pen$; IF grid% THEN GOSUB 🖥do_grid SetLocalStorageItem( "draw:mark:" + iy% + "," + ix%, pen$ + " " + f_color% + "," + b_color%) COLOR 15,0 RETURN ✒set_pen: LOCATE (_HEIGHT/8)-1, 5 : COLOR f_color%, b_color% : PRINT pen$; SetLocalStorageItem( "draw:pen", pen$ ) COLOR 15, 0 RETURN 🎨toggle_color_menu_mode: WHILE _MOUSEBUTTON : WEND LET color_menu_mode$ = IFF(color_menu_mode$="Foreground", "Background", "Foreground") LOCATE (_HEIGHT/8)-1, 7 : PRINT color_menu_mode$ + ":"; RETURN 🎨show_color_picks: LOCATE (_HEIGHT/8),18 : COLOR 15,0 : PRINT STRING$(32, " "); FOR i% = 0 TO 15 LOCATE (_HEIGHT/8)-1,18+(i%*2) : COLOR i%, 0 : PRINT CHR$(219) + CHR$(219) IF i% = f_color% THEN LOCATE (_HEIGHT/8),18+(i%*2) : COLOR 15,0 : PRINT "F"; IF i% = b_color% THEN LOCATE (_HEIGHT/8),18+(i%*2)+1 : COLOR 15,0 : PRINT "B"; NEXT i% COLOR 15,0 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_pen RETURN