Oxygen Basic
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
Latest OxygenBasic.zip at GitHub
(Click on the Wizard)
Home
Help
Search
Login
Register
Oxygen Basic
»
Programming
»
Example Code
»
Graphics
»
MandelText Fractal
« previous
next »
Print
Pages: [
1
]
Author
Topic: MandelText Fractal (Read 3066 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
'==========================
'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
Charles
Logged
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
'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>10 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 4
putfile "m.txt", man.RenderText
Charles
Logged
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!
Logged
JRS
Guest
Re: MandelText Fractal
«
Reply #3 on:
June 12, 2011, 09:25:14 PM »
Runs fine under Wine.
Pretty slick Charles!
Logged
Print
Pages: [
1
]
« previous
next »
Oxygen Basic
»
Programming
»
Example Code
»
Graphics
»
MandelText Fractal