Author Topic: MandelText Fractal  (Read 3069 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
MandelText Fractal
« on: June 12, 2011, 02:40:10 AM »

Hi Kent,

Following up on that strange C code you tried from Ken Perlins Website:

Code: Text
  1.  
  2.  
  3. '==========================
  4. 'ASCII CHARACTER MANDELBROT
  5. '==========================
  6.  
  7.  
  8. 'http://cs.nyu.edu/~perlin/
  9.  
  10. 'COMPILE THIS:
  11. '-------------
  12. 'COMPILE THIS:
  13. 'main(k){float i,j,r,x,y=-16;while(puts(""),y++<15)for(x
  14. '=0;x++<84;putchar(" .:-;!/>)|&IH%*#"[k&15]))for(i=k=r=0;
  15. 'j=r*r-i*i-2+x/25,i=2*r*i+y/10,j*j+i*i<11&&k++<111;r=j);}
  16.  
  17.  
  18. 'SHORT
  19. '=====
  20.  
  21. sys x,y,k, single i,j,r, string b
  22. for y=0 to 31
  23.   for x=1 to 84
  24.     b+=mid " .:-;!/>)|&IH%*#",1+(k and 15),1
  25.     i=0 : k=0 : r=0
  26.     do
  27.       j=r*r-i*i-2+x*.04 : i=2*r*i-1.6+y*.1 : r=j
  28.       if k++>110 or i*i+j*j>10 then exit do
  29.     end do
  30.   next
  31.   b+=chr(13)+chr(10)
  32. next
  33. putfile "m.txt",b
  34.  
  35.  
  36. 'MORE EFFICIENT STRING BUFFER
  37. '============================
  38.  
  39. sys    x,y,k
  40. single i,j,r
  41. string b=space(86*33)
  42. for y=0 to 31
  43.   for x=1 to 84
  44.     mid b,y*86+x,mid " .:-;!/>)|&IH%*#",1+(k and 15),1
  45.     i=0 : k=0 : r=0
  46.     do
  47.       j=r*r-i*i-2+x*.04 : i=2*r*i-1.6+y*.1 : r=j
  48.       if i*i+j*j>10 then exit do
  49.       if k++>110 then exit do  
  50.     end do
  51.   next
  52.   mid b,y*86+85,chr(13)+chr(10)
  53. next
  54. putfile "m.txt",b
  55.  

Charles

Charles Pegge

  • Guest
Re: MandelText Fractal
« Reply #1 on: June 12, 2011, 03:26:23 AM »

Now encapsulated in an Object with scaling and character pattern setting.

Code: Text
  1.  
  2. 'OBJECTIFIED
  3. '===========
  4.  
  5.  
  6.   '---------------
  7.   class MandelText
  8.   '===============
  9.  
  10.   string buf,pat,cr
  11.   sys sx,sy
  12.  
  13.   method scale(single s)
  14.   '=====================
  15.   '
  16.   sx=84*s : sy=32*s
  17.   end method
  18.   '
  19.   '
  20.   method CharPattern(p as string)
  21.   '=============================
  22.   '
  23.   pat=p
  24.   end method
  25.  
  26.   method RenderText() as string
  27.   '============================
  28.   '
  29.   sys    x,y,k
  30.   single i,j,r,rx,ry
  31.   if sx+sy=0 then sx=84 : sy=32
  32.   if pat="" then pat=" .:-;!/>)|&IH%*#"
  33.   cr=chr(13)+chr(10)
  34.   buf=space(sx*(sy+1))
  35.   rx=.04*84/sx
  36.   ry=.1*32/sy
  37.   '
  38.   for y=0 to sy
  39.     for x=1 to sx
  40.       mid buf,y*(sx+2)+x,mid pat,1+(k and 15),1
  41.       i=0 : k=0 : r=0
  42.       do
  43.         j=r*r-i*i-2+x*rx : i=2*r*i-1.6+y*ry : r=j
  44.         if k++>110 or i*i+j*j>10 then exit do
  45.       end do
  46.     next
  47.     mid buf,y*(sx+2)+sx+1,cr
  48.   next
  49.   return buf
  50.   end method
  51.  
  52.   end class
  53.  
  54.   'TEST:
  55.   '=====
  56.  
  57.   MandelText man
  58.   man.CharPattern " .-=abcdefABCDEF"
  59.   man.scale 4
  60.   putfile "m.txt", man.RenderText
  61.  
  62.  

Charles

kryton9

  • Guest
Re: MandelText Fractal
« Reply #2 on: June 12, 2011, 01:35:31 PM »
That is super Charles! 

A lot to study in this one and have fun at the same time doing it!

JRS

  • Guest
Re: MandelText Fractal
« Reply #3 on: June 12, 2011, 09:25:14 PM »
Runs fine under Wine.

Pretty slick Charles!