
'==========================
'ASCII CHARACTER MANDELBROT
'==========================


'http://cs.nyu.edu/~perlin/

'COMPILE THIS:
'-------------
'COMPILE THIS:
'main(k){float i,j,r,x,y=-16;while(puts(""),y++<15)for(x
'=0;x++<84;putchar(" .:-;!/>)|&IH%*#"[k&15]))for(i=k=r=0;
'j=r*r-i*i-2+x/25,i=2*r*i+y/10,j*j+i*i<11&&k++<111;r=j);}


'SHORT
'=====

sys x,y,k, single i,j,r, string b
for y=0 to 31
  for x=1 to 84
    b+=mid " .:-;!/>)|&IH%*#",1+(k and 15),1
    i=0 : k=0 : r=0
    do
      j=r*r-i*i-2+x*.04 : i=2*r*i-1.6+y*.1 : r=j
      if ++k>110 or i*i+j*j>10 then exit do
    end do
  next
  b+=chr(13)+chr(10)
next
putfile "m.txt",b


'MORE EFFICIENT STRING BUFFER
'============================

sys    x,y,k
single i,j,r
string b=space(86*33)
for y=0 to 31
  for x=1 to 84
    mid b,y*86+x,mid " .:-;!/>)|&IH%*#",1+(k and 15),1
    i=0 : k=0 : r=0
    do
      j=r*r-i*i-2+x*.04 : i=2*r*i-1.6+y*.1 : r=j
      if i*i+j*j>10 then exit do
      if ++k>110 then exit do  
    end do
  next
  mid b,y*86+85,chr(13)+chr(10)
next
putfile "m.txt",b


'OBJECTIFIED
'===========


  '---------------
  class MandelText
  '===============

  string buf,pat,cr
  sys sx,sy

  method scale(single s)
  '=====================
  '
  sx=84*s : sy=32*s
  end method
  '
  '
  method CharPattern(p as string)
  '=============================
  '
  pat=p
  end method

  method RenderText() as string
  '============================
  '
  sys    x,y,k
  single i,j,r,rx,ry
  if sx+sy=0 then sx=84 : sy=32
  if pat="" then pat=" .:-;!/>)|&IH%*#"
  cr=chr(13)+chr(10)
  buf=space(sx*(sy+1))
  rx=.04*84/sx
  ry=.1*32/sy
  '
  for y=0 to sy
    for x=1 to sx
      mid buf,y*(sx+2)+x,mid pat,1+(k and 15),1
      i=0 : k=0 : r=0
      do
        j=r*r-i*i-2+x*rx : i=2*r*i-1.6+y*ry : r=j
        if ++k>110 or i*i+j*j>11 then exit do
      end do
    next
    mid buf,y*(sx+2)+sx+1,cr
  next
  return buf
  end method

  end class

  'TEST:
  '=====

  MandelText man
  man.CharPattern " .,:abcdefABCDEF"
  man.scale 2
  putfile "m.txt", man.RenderText




