Showing posts with label fractals. Show all posts
Showing posts with label fractals. Show all posts

Saturday, April 13, 2013

Cellular automation 2


# The cellular automation program was malfunctioning for a long time because I did not update the code for the New Basic 256 version .
# This is a new version where the chaotic rule and the fractal rule are used different alternating patterns.
#http://mathworld.wolfram.com/ElementaryCellularAutomaton.html

fastgraphics
graphsize 600,300
For n = 1 to 300
plot (300,1)
Print "Fractal rule every "+n+" rows"
For y = 1 to 300
For x = 1 to 600
a=0
if pixel(x-1,y)=black then a=a+1
if pixel(x,y)=black then a=a+10
if pixel(x+1,y)=black then a=a+100

if y/n = int (y/n) then
gosub fractal
else
gosub chaotic
end if

next x
refresh
next y
refresh
clg
next n

chaotic:
if a=001 or a=110 or a =010 or a=100 then plot (x,y+1)
return
fractal:
if a=001 or a=010 or a=100 then plot (x,y+1)
return

Saturday, December 25, 2010

Mandelbrot


rem Zoomable Mandelbrot based in Joel Kahn's example
sz=600
font "arial",10,100
graphsize sz,sz
fastgraphics
kt=50:m=4.0
xmin=-2.1:xmax=.6:ymin=-1.5:ymax=1.5
gosub draw
input "press enter to zoom in",a$
xmin=-0.5:xmax=0:ymin=0.5:ymax=1
gosub draw
input "press enter to zoom in",a$
xmin=-0.15:xmax=-.05:ymin=0.9:ymax=1
gosub draw
input "press enter to zoom in ",a$
xmin=-0.14:xmax=-.13:ymin=0.98:ymax=.99
gosub draw
end
 
draw:
clg
refresh
dx=(xmax-xmin)/sz:dy=(ymax-ymin)/sz
for x=xmin to xmax step dx
for y=ymin to ymax step dy
k=0:a=0:b=0
do
# In the iteration z=z^2+c
#z=ai + b
#c=yi + x
tx=a^2-b^2+x
b=2*b*a+y
a=tx
d=a^2+b^2
k=k+1
until not (d <= m and k < kt)
color k*50000000
plot (x-xmin)/dx,(ymax-y)/dy
next y
refresh
next x
# grid
color black
for n= 0 to 9
line n*sz/10,sz,n*sz/10,0
text n*sz/10,5,xmin+(xmax-xmin)*n/10
text 5,n*sz/10,ymax-(ymax-ymin)*n/10
line sz,n*sz/10,0,n*sz/10
next n
refresh
return

Friday, December 3, 2010

Dragon curve

graphsize 900,900
color yellow
rect 0,0,900,900
color black
fastgraphics
order=15
Dim s(2^order+1)
s[1]=1 : s[2]=1
for n=2 to order
a= 2^n-1 : b=2^(n-1)+1
for g= a to b step -1
s[g]= abs(s[2^n-g]-1)
next g
s[2^n]=1
next n
Zoom =3 : angle=180
x1=110*Zoom : y1=90*Zoom
for g= 1 to 2^(order)-1
refresh
gosub lines
if s[g]=1 then angle =angle+90
if s[g]=0 then angle =angle-90
next g
lines:
r = (angle/180)*pi
y2=y1 + (sin (r))*Zoom
x2=x1 - (cos (r))*Zoom
line x1,y1,x2,y2
x1=x2
y1=y2
return

Monday, November 29, 2010

Fractal Tree


graphsize 600,600
for i = 1 to 1000
x1=300
y1=600
s=290
angle = 270
color 127*int(rand*3),127*int(rand*3),127*int(rand*3)
for b = 1 to 6
gosub lines
s=s*.5
angle = angle + int(rand*5)*45-90
next b
next i
lines:
r = (angle/180)*pi
y2=y1 + (sin (r))*s
x2=x1 - (cos (r))*s
for n = 1 to 30
circle (x2*n+x1*(30-n))/30,(y2*n+y1*(30-n))/30,36/b^2
next n
x1=x2
y1=y2
return

Friday, November 12, 2010

Chaos Game

fastgraphics
rx=300:ry=150:x=150:y=0
for sides = 3 to 10
for m = 1 to 10
mult=m/10
for t = 0 to 200
refresh
gosub plotthepoints
next t
clg
next m
next sides
choosevertex:
angle = (360/sides)*int(rand*sides*360)
rad = -3.14159*(angle/180)
y=(sin (rad))*150
x=(cos (rad))*150
return
plotthepoints:
for cicle = 1 to 200
gosub choosevertex
midx= (x-rx)*mult+rx
midy= (y-ry)*mult+ry
plot 150+midx,150+midy
rx=midx
ry=midy
next cicle
return