  OPTION SCALE, 96
  TITLE By Mac
  DIALOG CREATE,Draw Shapes Using Chars In A List Box,-1,0,450,355
  DIALOG ADD,STYLE,Style1,Courier,8,B
  DIALOG ADD,STYLE,Style2,Courier,8
  DIALOG ADD,BUTTON,Clear,5,5,36,20
  DIALOG ADD,COMBO,C1,5,46,114,20,,CLICK
  DIALOG ADD,TEXT,T1,8,170,,,"x1       y1       x2       y2",Style2
  DIALOG ADD,COMBO,C2,5,189,40,20,0
  DIALOG ADD,COMBO,C3,5,261,40,20,0
  DIALOG ADD,COMBO,C4,5,333,40,20
  DIALOG ADD,COMBO,C5,5,405,40,20
  DIALOG ADD,LIST,L1,30,5,440,320,Style1
  DIALOG SHOW

  LIST LOADTEXT, C1
"Line x1,y1 to x2,y2
"Circle radius 3
"Circle radius 4
"Circle radius 5
"Circle radius 6
"Circle radius 7
"Circle radius 8
"Circle radius 9
"Circle radius 10
"Circle radius 11

  %x = 1
  REPEAT 
    LIST ADD, C2, %x
    LIST ADD, C4, %x
    if @greater(25, %x)
      LIST ADD, C3, %x
      LIST ADD, C5, %x
    end 
    %x = @succ(%x)
  UNTIL @greater(%x, 48)
  LIST SEEK, C2, 11
  LIST SEEK, C3, 0
  LIST SEEK, C4, 34
  LIST SEEK, C5, 23

  rem -- load with 48x24 blank spaces (1 - 48 for X , 0 - 23 for Y)
  rem -- Y is modified to use 1 - 24 input in Dot routine --
:ClearBUTTON
  LIST CLEAR, L1
  %y = 0
  REPEAT 
    %x = 1
    %s = ""
    REPEAT 
      %s = %s" "
      %x = @succ(%x)
    UNTIL @greater(%x, 48)
    LIST ADD, L1, %s
    %y = @succ(%y)
  UNTIL @greater(%y, 23)

:EVLOOP
  WAIT EVENT
  goto @event()

:C1CLICK
  if @equal(@item(C1), "Line x1,y1 to x2,y2")
    %%x1 = @item(C2)
    %%y1 = @item(C3)
    %%x2 = @item(C4)
    %%y2 = @item(C5)
    GOSUB DrawLine
  else 
    rem -- Approx center of draw area --
    %x = 24
    %y = 13
    rem -- Get radius --
    %r = @substr(@item(C1), @pred(@len(@item(C1))), @len(@item(C1)))
    GOSUB DrawCircle
  end 
  goto EVLOOP

:CLOSE
  EXIT 
  STOP 

  rem ---- GOSUB Routines ----

:Dot
  rem -- Draw dot at xd, yd --
  %s = @item(L1, @pred(%%yd))
  %s = @strdel(%s, %%xd)
  %s = @strins(%s, %%xd, @chr(174))
  LIST PUT, L1, %s
  exit 

:DrawCircle
  rem -- Draw circle at x, y with approx radius of r --
  rem -- Best I could do, list width/height ratio is strange --
  %%xc = %x
  %%yc = %y
  %x = 0
  %y = %r
  %d = @prod(2, @diff(1, %r))
  REPEAT 
    %%xd = @sum(%%xc, %x)
    %%yd = @sum(%%yc, %y)
    GOSUB Dot
    %%xd = @sum(%%xc, %x)
    %%yd = @diff(%%yc, %y)
    GOSUB Dot
    %%xd = @diff(%%xc, %x)
    %%yd = @sum(%%yc, %y)
    GOSUB Dot
    %%xd = @diff(%%xc, %x)
    %%yd = @diff(%%yc, %y)
    GOSUB Dot
    if @greater(@sum(%d, %y), 0)
      %y = @pred(%y)
      rem -- The "4" adjusts vertical ellipse --
      %d = @diff(%d, @pred(@prod(4, %y)))
    end 
    if @greater(%x, %d)
      %x = @succ(%x)
      rem -- The "2" adjusts horizontal ellipse --
      %d = @sum(%d, @succ(@prod(2, %x)))
    end 
  UNTIL @greater(0, %y)
  exit 

:DrawLine
  rem -- Draw line from x1,y1 to x2,y2 --
  if @greater(%%x2, %%x1)
    %%dx = @diff(%%x2, %%x1)
    %%sx = 1
  else 
    %%dx = @diff(%%x1, %%x2)
    %%sx = -1
  end 
  if @greater(%%y2, %%y1)
    %%dy = @diff(%%y2, %%y1)
    %%sy = 1
  else 
    %%dy = @diff(%%y1, %%y2)
    %%sy = -1
  end 
  %%steep = ""
  if @greater(%%dy, %%dx)
    %%steep = 1
    rem -- swap x1 y1, dx dy, sx sy -- 
    %z = %%x1
    %%x1 = %%y1
    %%y1 = %z
    %z = %%dx
    %%dx = %%dy
    %%dy = %z
    %z = %%sx
    %%sx = %%sy
    %%sy = %z
  end 
  %e = @diff(@prod(2, %%dy), %%dx)
  %i = 0
  REPEAT 
    if %%steep
      %%xd = %%y1
      %%yd = %%x1
    else 
      %%xd = %%x1
      %%yd = %%y1
    end 
    GOSUB Dot
    if @greater(%e, -1)
      REPEAT 
        %%y1 = @sum(%%y1, %%sy)
        %e = @diff(%e, @prod(2, %%dx))
      UNTIL @greater(0, %e)
    end 
    %%x1 = @sum(%%x1, %%sx)
    %e = @sum(%e, @prod(2, %%dy))
    %i = @succ(%i)
  UNTIL @equal(%i, %%dx)
  %%xd = %%x2
  %%yd = %%y2
  GOSUB Dot
  exit 
