aUCBLogo Demos and Tests / ifs_alnum
to ifs_alnum [mytext 1234]
;I_terative F_unction S_ystem alpha-numeric drawings
maxi2=16
maxi2Move=12
maxi=Int 2^maxi2
trafomode=true
palsize=256
pal=IntArray loadpalette "ifs.pal
on=1
data=[]
initAlphabet mytext
initGraph
demoNr=1
odemoNr=1
Ntrafo=Int count data.demoNr.2
dat=deepCopy data.odemoNr
Ntrafo=Int lcm Ntrafo count dat.2
dat.7=Ntrafo/count dat.2
dat.8=240/count dat.2
dat.2=enlarge dat.2 Ntrafo
dat.3=enlarge dat.3 Ntrafo
p=dat.2
d=dat.3
sk=dat.4
x0=dat.5
y0=dat.6
cf=dat.7
cf2=dat.8
initProbabilities
x=rSeqFA 0 0 maxii
y=rSeqFA 0 0 maxii
for [runnr 1 10]
[ IFSiterate
]
end
be initAlphabet mytext
a=
{ {1 90 6 .0 -0.55 1 }
{1 -30 5 .15 -0.1 1 }
{1 30 5 .15 -1 1 }
{1 30 5 .45 -0.1 1 }
{1 -30 5 .45 -1 1 }
{1 -90 10 .6 -0.6 1 }
}
c=
{ {1 90 6 .0 -0.55 1 }
{1 -30 5 .15 -0.1 1 }
{1 30 5 .15 -1 1 }
{1 30 5 .45 -0.1 1 }
{1 -30 5 .45 -1 1 }
}
d=
{ {1 90 6 .0 -0.55 1 }
{1 -30 5 .15 -0.1 1 }
{1 30 5 .15 -1 1 }
{1 30 5 .45 -0.1 1 }
{1 -30 5 .45 -1 1 }
{1 -90 25 .6 0 .3}
}
e=
{ {1 90 6 .0 -0.55 1 }
{1 -30 5 .15 -0.1 1 }
{1 30 5 .15 -1 1 }
{1 30 5 .45 -0.1 1 }
{1 -30 5 .45 -1 1 }
{1 0 8 .25 -0.55 1 }
{1 -90 4 .6 -0.4 1 }
}
g=
{ {1 90 6 .0 -0.55 1 }
{1 -30 5 .15 -0.1 1 }
{1 30 5 .15 -1 1 }
{1 30 5 .45 -0.1 1 }
{1 -30 5 .45 -1 1 }
{1 -90 18 .6 -1 1 }
{1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 30 6 .5 1 1 }
{1 -90 8 .0 0.5 1 }
{1 90 8 .7 0.5 1 }
{1 0 6 .3 0 2 }
}
_9=
{ {1 30 6 .2 -1 1 }
{1 -30 6 .5 -1 1 }
{1 90 8 .7 -0.5 1 }
{1 -30 6 .2 1 1 }
{1 30 6 .5 1 1 }
{1 -90 8 .0 0.5 1 }
{1 90 8 .7 0.5 1 }
{1 0 6 .3 0 2 }
}
trafos={}
indexlist=[]
newlines=[]
foreach mytext
[ ifelse ?=="
[ newlines=lput (last indexlist) newlines
][ ifelse number? ?
[ trafos=combine trafos thing word "_ ?
][ trafos=combine trafos thing ?
]
]
indexlist=lput count trafos indexlist
]
newlines=lput count trafos newlines
len=count trafos
da=Array len
pa=Array len
xar=Array len
yar=Array len
xindex=0
yindex=first newlines
x0=0
y0=0
for [it 1 len]
[ da.it=FloatArray 6
if it > xindex
[ x0=x0+1
xindex=first indexlist
indexlist=butFirst indexlist
]
if it > yindex
[ y0=y0-2
x0=1
newlines=butFirst newlines
yindex=first newlines
xindex=first indexlist
indexlist=butFirst indexlist
]
xar.it=x0
yar.it=y0
]
xmax=(max xar+1)
xar2=(xar-xmax/2)
yar2=(yar-(min yar)/2)
xf=8/xmax
for [it 1 len]
[ ti=Array trafos.it
di=da.it
ti.3= ti.3/100
di.1= xf *ti.3* cos ti.2
di.2= ti.6*ti.3* sin ti.2
di.3= xf *ti.3*(sin ti.2)*(-1)
di.4= ti.6*ti.3* cos ti.2
di.5= ti.4*0.8+xar2.it
di.6= ti.5*0.8+yar2.it
da.it=di
pa.it=trafos.it.1
]
dat=(list [][][][][][][][])
dat.1=(list mytext)
dat.2=pa
dat.3=da
dat.4=170 ;sk
dat.5=0 ;x0
dat.6=0 ;y0
dat.7=1 ;cf
dat.8=1 ;cf2
push "data dat
end
to transposeArray a
local [l l2 b]
l=count a
l2=count a.1
b=Array l2
for [i 1 l2]
[ tmp=FloatArray l
for [j 1 l]
[ tmp.j=a.j.i
]
b.i=tmp
]
output b
end
to enlarge p N
local [pn p2 f]
pn=count p
p2=Array N
f=pn/N
for [i 1 N]
[ p2.i=p.(1+Int (i-1)*f)
]
output p2
end
to initProbabilities
(reRandom 0)
n=count p
p0=0
for [i 1 n]
[ p.i=p0+p.i
p0=p.i
]
p=p/(max p)
pa=Array maxi2
pai=Int (ln n)/ln 2
for [l pai maxi2]
[ l2=2^l
pat=IntArray l2
k=1
for [i 1 n]
[ kmax=Int p.i*l2
if kmax >= k
[ setItems k pat IntArray rseq i i kmax-k+1
; for [j k kmax]
; [
;(show j i)
; pat.j=i
; ]
]
k=kmax+1
]
pa.l=pat
;show p
;show pa.l
pa.l=shuffle pa.l
;show pa
]
maxii=Int 2^pai
m=count d
d1=FloatArray m
d2=FloatArray m
d3=FloatArray m
d4=FloatArray m
d5=FloatArray m
d6=FloatArray m
for [i 1 m]
[ d1.i=(d.i).1
d2.i=(d.i).2
d3.i=(d.i).3
d4.i=(d.i).4
d5.i=(d.i).5
d6.i=(d.i).6
]
end
to shuffle_Logo a
local [n j k tmp]
n=count a
for [i 1 n]
[ j=1+random n
k=1+random n
tmp=a.j
a.j=a.k
a.k=tmp
]
end
to initGraph
ht
PenUp
setXY -400 -300
bm=BitCopy 800 600
bx=BitMaxX bm
by=BitMaxY bm
t=16
PenDown
end
to IFSiterate
local [p]
p=pa.pai
for [i 1 2]
[ xx= d1.p*x + d2.p*y + d5.p
yy= d3.p*x + d4.p*y + d6.p
xi= xx*sk+x0
yi= yy*sk+y0
ifelse trafomode
[ setPixelXY xi yi
; IntArray (mod (FloatArray (p-1))/cf 15)+1
pal.(IntArray
(FloatArray (IntArray (FloatArray p-1)/cf))
*cf2+15)
][
setPixelXY xi yi pal.Int t
]
ox=x
oy=y
x=xx
y=yy
p=rotate p random maxii
t=(mod t palsize)+1
]
pa.pai=p
ifelse pai < maxi2
[ pai=pai+1
maxii=maxii*2
x=combine x ox
y=combine y oy
][
updateGraph
dispatchMessages
]
end