## Ascii Draw

Charlie Veniot10th April 2022 at 2:40am
``````gosub init_program
getmouse x,y,nw,nb
do
temp\$ = inkey\$
if temp\$ <> "" then brush\$ = temp\$ : gosub show_brush
getmouse x,y,nw,nb
if nb = 1 and y < (sy-17) and x >= 0 and x < sx then gosub do_brush_stroke
if nb = 1 and y > (sy-9) and x < menu_name_pxw then gosub toggle_menu
if nb = 1 and y > (sy-9) and x > (menu_name_pxw + 7) and x < (((11 + 32) * 8) -1)  THEN GOSUB set_brush_color
loop
'
color 15,0
else
end if
locate (sy/8),1 : print menu\$ : sleep 0.125
color f_color, b_color
return
show_color_picks:
for i = 0 to 15
locate (sy/8),12+(i*2) : color i, 0 : print chr\$(219) + chr\$(219)
next i
color 15,0
locate (sy/8), (11 + (16 * 2) + 3) : print "brush:"
color f_color, b_color
return
set_brush_color:
if menu\$ = "foreground:" then f_color = int(((x-87)/16)) else b_color = int(((x-87)/16))
color f_color,b_color
SetLocalStorageItem( "draw:f_color", f_color)
SetLocalStorageItem( "draw:b_color", b_color)
gosub show_brush
return
do_brush_stroke:
new_y = (int(y/8)+1) : new_x = (int(x/8)+1)
locate new_y, new_x
print brush\$
SetLocalStorageItem( "draw:stroke:" + new_y + "," + new_x, brush\$ + " " + f_color + "," + b_color)
return
show_brush:
locate (sy/8), (11 + (16 * 2) + 3 + 6) : print brush\$
SetLocalStorageItem( "draw:brush", brush\$ )
return
do_grid:
for i = 7 to sx - 1 step 8
line (i,0)-(i,(sy-17)), 7
next i
for i = 7 to sy - 17 step 8
line (0,i)-((sx-1),i), 7
next i
return
init_program:
menu_name_pxw = 8 * 10  ' 8 pixels * 10 characters
c_width% = GetLocalStorageItem( "draw:width" )
c_height% = GetLocalStorageItem( "draw:height" )
screen 2
print "ASCII DRAW"
If c_width% >= 52 and c_width% <= 260 and c_height% >= 1 and c_height% <= 51 then
locate 3,1
print "Press N and enter to start a new drawing.", continue\$
input "Press enter to continue last drawing.", continue\$
if ucase\$(continue\$) <> "N" then gosub continue_drawing else gosub blank_drawing
else
gosub blank_drawing
end if
gosub toggle_menu : gosub show_color_picks : gosub show_brush
return
continue_drawing:
gosub do_screen
for this_y = 1 to c_height%
for this_x = 1 to c_width%
this_stroke\$ = GetLocalStorageItem( "draw:stroke:" + this_y + "," + this_x)
if this_stroke\$ <> "" then
this_brush\$ = left\$(this_stroke\$, 1) : this_stroke\$ = right\$(this_stroke\$, len(this_stroke\$) - 2)
this_f_color = val(left\$(this_stroke\$, instr(this_stroke\$, ",") - 1))
this_b_color = val(right\$(this_stroke\$, len(this_stroke\$) - instr(this_stroke\$, ",")))
color this_f_color, this_b_color
locate this_y, this_x : print this_brush\$
end if
next this_x
next this_y
brush\$ = GetLocalStorageItem( "draw:brush" )
f_color = GetLocalStorageItem( "draw:f_color" )
b_color = GetLocalStorageItem( "draw:b_color" )
return
blank_drawing:
f_color = 15 : b_color = 0 : 	brush\$ = " "
c_width% = 0 : c_height% = 0
screen 2
print "ASCII DRAW"
while c_width% < 52 or c_width% > 260
locate 3,1
input "how many characters wide? (min of 52, max of 260)", c_width%
if c_width% < 52 or c_width% > 260 then beep
wend
SetLocalStorageItem( "draw:width", c_width%)
print : print "Ok, canvas will be " + c_width% + " characters wide." : print
while c_height% < 1 OR c_height% > 51
locate 7,1
input "how many characters high? (min of 1, max of 51)", c_height%
if c_height% < 1 OR c_height% > 51 then beep
wend
SetLocalStorageItem( "draw:height", c_height%)
print : print "Ok, canvas will be " + c_height% + " characters high." : print
print "Preparing canvas.";
for this_y = 1 to c_height%
for this_x = 1 to c_width%
SetLocalStorageItem( "draw:stroke:" + this_y + "," + this_x, "")
next this_x
print ".";
next this_y
gosub do_screen
return
do_screen:
sx = c_width% * 8
sy = (c_height%+2) * 8
screen _newimage(sx,sy,0)
gosub do_grid
return``````