aUCBLogo Demos and Tests / ifs3d
to ifs3d ;I_terative F_unction S_ystem
setUpdateGraph false
setScreenColor 0
WindowMode
perspective
enableFog
fogdens=0.04
fogstart=300.0
fogend=1000.0
; allFullScreen
; (splitScreen 0.9)
maxi2=16
maxi2Move=16
maxi=Int 2^maxi2
trafomode=true
palsize=256
pal=IntArray loadpalette "ifs.pal
on=1
data=
[
[MengerSponge ;by AM
{1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1}
{
{0.333 0 0 0 0.333 0 0 0 0.333 1 1 1}
{0.333 0 0 0 0.333 0 0 0 0.333 1 1 0}
{0.333 0 0 0 0.333 0 0 0 0.333 1 1 -1}
{0.333 0 0 0 0.333 0 0 0 0.333 1 0 -1}
{0.333 0 0 0 0.333 0 0 0 0.333 1 -1 -1}
{0.333 0 0 0 0.333 0 0 0 0.333 1 -1 0}
{0.333 0 0 0 0.333 0 0 0 0.333 1 -1 1}
{0.333 0 0 0 0.333 0 0 0 0.333 1 0 1}
{0.333 0 0 0 0.333 0 0 0 0.333 0 1 1}
{0.333 0 0 0 0.333 0 0 0 0.333 0 1 -1}
{0.333 0 0 0 0.333 0 0 0 0.333 0 -1 -1}
{0.333 0 0 0 0.333 0 0 0 0.333 0 -1 1}
{0.333 0 0 0 0.333 0 0 0 0.333 -1 1 1}
{0.333 0 0 0 0.333 0 0 0 0.333 -1 1 0}
{0.333 0 0 0 0.333 0 0 0 0.333 -1 1 -1}
{0.333 0 0 0 0.333 0 0 0 0.333 -1 0 -1}
{0.333 0 0 0 0.333 0 0 0 0.333 -1 -1 -1}
{0.333 0 0 0 0.333 0 0 0 0.333 -1 -1 0}
{0.333 0 0 0 0.333 0 0 0 0.333 -1 -1 1}
{0.333 0 0 0 0.333 0 0 0 0.333 -1 0 1}
}
100 0 0 0 1 1
]
[Farn
{1 7 7 85} ;p=probability
{
{ 0 0 0 0 0.18 0 0 0 0 0 0 0}
{ 0.22 -0.23 0 0.24 0.22 0 0 0 0.32 0 0.82 0}
{-0.22 0.23 0 0.24 0.22 0 0 0 0.32 0 0.82 0}
{ 0.83 0 0 0 0.86 0.1 0 -0.12 0.84 0 1.62 0}
} ;d=Drehmatrix
70 ;sk=Skala
0 ;x0=xorigin
-400 ;y0=yorigin
0 ;z0=zorigin
1 ;cf=colorFactor
1 ;cf2=colorFactor2
]
[3dTetrahedron ; by Alex Matulich
{1 1 1 1}
{
{0.50 0 0 0 0.50 0 0 0 0.50 0.00 0.00 1.00}
{0.50 0 0 0 0.50 0 0 0 0.50 0.00 0.87 -0.50}
{0.50 0 0 0 0.50 0 0 0 0.50 -0.87 -0.50 -0.50}
{0.50 0 0 0 0.50 0 0 0 0.50 0.87 -0.50 -0.50}
}
150 0 -50 0 1 1
]
[3d5Tetrahedron ; by Alex Matulich
{1 1 1 1 1}
{
{0.44 0 0 0 0.44 0 0 0 0.44 0.00 0.00 1.00}
{0.44 0 0 0 0.44 0 0 0 0.44 0.00 0.87 -0.50}
{0.44 0 0 0 0.44 0 0 0 0.44 -0.87 -0.50 -0.50}
{0.44 0 0 0 0.44 0 0 0 0.44 0.87 -0.50 -0.50}
{0.44 0 0 0 0.44 0 0 0 0.44 0.00 0.00 0.00}
}
150 0 -50 0 1 1
]
[3dHexahedron ; by Alex Matulich
{1 1 1 1 1}
{
{0.44 0 0 0 0.44 0 0 0 0.44 0.00 0.00 0.90}
{0.44 0 0 0 0.44 0 0 0 0.44 0.87 -0.50 0.00}
{0.44 0 0 0 0.44 0 0 0 0.44 -0.87 -0.50 0.00}
{0.44 0 0 0 0.44 0 0 0 0.44 0.00 1.00 0.00}
{0.44 0 0 0 0.44 0 0 0 0.44 0.00 0.00 -0.90}
}
150 0 -50 0 1 1
]
[3dCube ; by Alex Matulich
{1 1 1 1 1 1 1 1}
{
{0.35 0 0 0 0.35 0 0 0 0.35 1.00 1.00 1.00}
{0.35 0 0 0 0.35 0 0 0 0.35 1.00 1.00 -1.00}
{0.35 0 0 0 0.35 0 0 0 0.35 1.00 -1.00 1.00}
{0.35 0 0 0 0.35 0 0 0 0.35 1.00 -1.00 -1.00}
{0.35 0 0 0 0.35 0 0 0 0.35 -1.00 1.00 1.00}
{0.35 0 0 0 0.35 0 0 0 0.35 -1.00 1.00 -1.00}
{0.35 0 0 0 0.35 0 0 0 0.35 -1.00 -1.00 1.00}
{0.35 0 0 0 0.35 0 0 0 0.35 -1.00 -1.00 -1.00}
}
100 0 0 0 1 1
]
[3dOctahedron ; by Alex Matulich
{1 1 1 1 1 1}
{
{0.40 0 0 0 0.40 0 0 0 0.40 0.00 0.00 1.00}
{0.40 0 0 0 0.40 0 0 0 0.40 1.00 0.00 0.00}
{0.40 0 0 0 0.40 0 0 0 0.40 0.00 1.00 0.00}
{0.40 0 0 0 0.40 0 0 0 0.40 -1.00 0.00 0.00}
{0.40 0 0 0 0.40 0 0 0 0.40 0.00 -1.00 0.00}
{0.40 0 0 0 0.40 0 0 0 0.40 0.00 0.00 -1.00}
}
100 0 -50 0 1 1
]
[3dDuodecahedron ; by Alex Matulich
{1 1 1 1 1 1 1 1 1 1 1 1}
{
{0.28 0 0 0 0.28 0 0 0 0.28 0.00 0.00 0.96}
{0.28 0 0 0 0.28 0 0 0 0.28 0.00 0.85 0.43}
{0.28 0 0 0 0.28 0 0 0 0.28 0.81 0.26 0.43}
{0.28 0 0 0 0.28 0 0 0 0.28 -0.81 0.26 0.43}
{0.28 0 0 0 0.28 0 0 0 0.28 0.50 -0.69 0.43}
{0.28 0 0 0 0.28 0 0 0 0.28 -0.50 -0.69 0.43}
{0.28 0 0 0 0.28 0 0 0 0.28 0.50 0.69 -0.43}
{0.28 0 0 0 0.28 0 0 0 0.28 -0.50 0.69 -0.43}
{0.28 0 0 0 0.28 0 0 0 0.28 0.81 -0.26 -0.43}
{0.28 0 0 0 0.28 0 0 0 0.28 -0.81 -0.26 -0.43}
{0.28 0 0 0 0.28 0 0 0 0.28 0.00 -0.85 -0.43}
{0.28 0 0 0 0.28 0 0 0 0.28 0.00 0.00 -0.96}
}
150 0 -50 0 1 1
]
[Dragon
{1 1 1 1} ;p=probability
{
{ 0.5 -0.5 0 0.5 0.5 0 0 0 0 0 0 0}
{-0.5 -0.5 0 0.5 -0.5 0 0 0 0 1 0 0}
{ 1 0 0 0 1 0 0 0 0.98 0 0 0.04}
{ 1 0 0 0 1 0 0 0 0.98 0 0 -0.04}
} ;d=Drehmatrix
300 ;sk=Skala
-100 ;x0=xorigin
0 ;y0=yorigin
0 ;z0=zorigin
1 ;cf=colorFactor
1 ;cf2=colorFactor2
]
]
ignore
[ foreach (Files "*.ifs)
[ ifsload ?
dat=(List [][][][][][][][])
dat.1=?
dat.2=p
dat.3=d
dat.4=sk
dat.5=x0
dat.6=y0
dat.7=1
dat.8=1
queue "data dat
]
]
ifsframe=(Frame [][IFSframe]
wxdefault_frame_style+wxstay_on_top
[0 520][100 500])
ifslistbox=(ListBox ifsframe [IFS Demos][]
[ odemoNr=demoNr
demoNr=(first ListBoxSelections)+1
throw "nextDemo
])
bTrafoMode=(Button ifsframe [&Trafomode][trafomode=not trafomode])
bStillImage=(Button ifsframe [&Still Image]
[noRefresh rotating=not rotating throw "still])
bQuit=(Button ifsframe [&Quit][throw "stopping])
bs=BoxSizer wxvertical
BoxSizerAdd bs ifslistbox 2000 wxexpand 0
BoxSizerAdd bs bTrafoMode 100 wxexpand 0
BoxSizerAdd bs bStillImage 100 wxexpand 0
BoxSizerAdd bs bQuit 100 wxexpand 0
FrameSetSizer ifsframe bs
FrameSetClientSize ifsframe 100 450
foreach data
[ ListBoxAppend ifslistbox (Word (?).1)
]
initgraph
demonr=1
odemonr=1
running=true
catch "stopping
[ while [running]
[ catch "nextDemo
[ Ntrafo=Int count data.demonr.2
dat=deepCopy data.odemonr
Ntrafo=Int lcm Ntrafo count dat.2
dat.8=Ntrafo/count dat.2
dat.9=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
z0=dat.7
cf=dat.8
cf2=dat.9
initprobabilities
x=rSeqFA 0 0 maxii
y=rSeqFA 0 0 maxii
z=rSeqFA 0 0 maxii
ifsiterate
on=n
od1=d1
od2=d2
od3=d3
od4=d4
od5=d5
od6=d6
od7=d7
od8=d8
od9=d9
od10=d10
od11=d11
od12=d12
opa=pa
osk=sk
ox0=x0
oy0=y0
oZ0=z0
skw=sk
x0w=x0
y0w=y0
z0w=z0
ocf=cf
ocf2=cf2
dat=deepCopy data.demonr
dat.8=Ntrafo/count dat.2
dat.9=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
z0=dat.7
cf=dat.8
cf2=dat.9
initprobabilities
pai=Int (LN n)/LN 2
; pai=maxi2
if demonr != odemonr
[ ifsmorphloop
]
pai=Int (LN n)/LN 2
maxii=Int 2^pai
x=rSeqFA 0 0 maxii
y=rSeqFA 0 0 maxii
z=rSeqFA 0 0 maxii
ifsloop
]
]
]
FrameDestroy ifsframe
notFullScreen
splitScreen
(GC true)
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 readnumber
local "w
w=readWord
if (first w)=="
[ w=bF w
]
output w+0
end
to ifsload filename
local [n di]
openRead filename
setReader filename
n=readnumber+1
p=Array n
d=Array n
for [i 1 n]
[ di=Array 6
for [j 1 6]
[ di.j=readnumber
]
d.i=di
p.i=readnumber
]
sk=readnumber
x0=readnumber-400
y0=300-readnumber
setReader []
close filename
p=p/(max p)
; (pr "p= p)
; (pr "d= d)
; (pr "sk= sk)
; (pr "x0= x0)
; (pr "y0= y0)
end
to ifsload2 filename
openRead filename
setReader filename
repeat 3 [ignore readWord]
x=readList
y=readList
sk=600*(x.2-x.1)
x0=x.1+x.2
y0=y.1+y.2
ignore readWord
n=readnumber
repeat 2 [ignore readWord]
d=Array n
for [i 1 n]
[ l=readList
d.i=listToArray (List l.1 l.4 l.3 l.2 l.5 l.6)
]
repeat 2 [ignore readWord]
p=listToArray readList
setReader []
close filename
init
(pr "p= p)
(pr "d= d)
(pr "sk= sk)
(pr "x0= x0)
(pr "y0= y0)
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
d7=FloatArray m
d8=FloatArray m
d9=FloatArray m
d10=FloatArray m
d11=FloatArray m
d12=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
d7.i=(d.i).7
d8.i=(d.i).8
d9.i=(d.i).9
d10.i=(d.i).10
d11.i=(d.i).11
d12.i=(d.i).12
]
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 ifsloop
local [running]
running=true
while [running]
[ catch "still
[ rotating=true
refresh
clearScreen
while [pai < maxi2]
[ ifsiterate
]
for [i 1 5]
[ ifsiterate
]
(GC true)
if rotating
[ catch "still
[ rotatescene
]
]
if not rotating
[ noRefresh
clearScreen
while [running]
[ ifsiterate
(GC true)
if Key?
[ ch=readChar
setCaseIgnored false
case ch
[ [[Char 27]
setCaseIgnored true
throw "stopping
]
["\ trafomode=not trafomode]
["c clearScreen]
["+ fogdens*=1.2 pr fogdens setFogDensity fogdens]
["- fogdens/=1.2 pr fogdens setFogDensity fogdens]
["S fogstart+=20 pr fogstart setFogRange fogstart fogend]
["s fogstart-=20 pr fogstart setFogRange fogstart fogend]
["E fogend+=20 pr fogend setFogRange fogstart fogend]
["e fogend-=20 pr fogend setFogRange fogstart fogend]
[else running=false]
setCaseIgnored true
]
]
]
]
]
]
noRefresh
end
to ifsmorphloop
w=1
local [running]
running=true
while [running and2 w > 0]
[ ifsiteratemorph
(GC true)
if Key?
[ ch=readChar
case ch
[ [[Char 27] throw "stopping]
["\ trafomode=not trafomode]
["c clearScreen]
[else running=false]
]
]
]
for [i 1 5]
[ ifsiteratemorph
]
end
to initgraph
cS hT
noRefresh
; singleBuffer
disableLighting
disablePointSmooth
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 + d3.p*z + d10.p
yy= d4.p*x + d5.p*y + d6.p*z + d11.p
zz= d7.p*x + d8.p*y + d9.p*z + d12.p
xi= xx*sk+x0
yi= yy*sk+y0
zi= zz*sk+z0
ifElse trafomode
[ setPixelXYZ xi yi zi
; IntArray (mod (FloatArray (p-1))/cf 15)+1
pal.(IntArray
(FloatArray (IntArray (FloatArray p-1)/cf))
*cf2+15)
][
setPixelXYZ xi yi zi pal.Int t
]
ignore [
xb=xi-400
yb=yi-300
for [j 1 [count x]]
[ c=addColorsMod (BitPixel bm xb.j yb.j) pal.Int t
BitSetPixel bm xb.j yb.j c
setPixelXY xi.j yi.j c
]
]
ox=x
oy=y
oz=z
x=xx
y=yy
z=zz
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
z=combine z oz
][
updateGraph
dispatchMessages
]
end
to ifsiteratemorph
w1=1-w
d1w=od1*w+d1*w1
d2w=od2*w+d2*w1
d3w=od3*w+d3*w1
d4w=od4*w+d4*w1
d5w=od5*w+d5*w1
d6w=od6*w+d6*w1
d7w=od7*w+d7*w1
d8w=od8*w+d8*w1
d9w=od9*w+d9*w1
d10w=od10*w+d10*w1
d11w=od11*w+d11*w1
d12w=od12*w+d12*w1
skw=(skw*4+osk*w+sk*w1)/5
x0w=(x0w*4+ox0*w+x0*w1)/5
y0w=(y0w*4+oy0*w+y0*w1)/5
z0w=(z0w*4+oz0*w+z0*w1)/5
maxx=(max x)
minx=(min x)
maxy=(max y)
miny=(min y)
if maxy-miny != 0
[ skw=(skw*4
+(1-Sin 180*w)*skw
+( Sin 180*w)
*(600/(Sqrt (Sqr maxx-minx)+(Sqr maxy-miny))))/5
]
x0w=(x0w*4
+ (1-Sin 180*w)*x0w
- ( Sin 180*w)*skw*(minx+maxx)/2)/5
y0w=(y0w*4
+ (1-Sin 180*w)*y0w
- ( Sin 180*w)*skw*(miny+maxy)/2)/5
cfw=ocf*w+cf*w1
cf2w=ocf2*w+cf2*w1
maxii=Int 2^pai
x=rSeqFA 0 0 maxii
y=rSeqFA 0 0 maxii
z=rSeqFA 0 0 maxii
for [k pai maxi2Move]
[
if k <= maxi2Move
[ p=pa.k
op_=opa.k
pw=(IntArray (FloatArray op_-1)*w+(FloatArray p-1)*w1)+1
]
for [i 1 2]
[ xx= d1w.pw*x + d2w.pw*y + d3w.pw*z + d10w.pw
yy= d4w.pw*x + d5w.pw*y + d6w.pw*z + d11w.pw
zz= d7w.pw*x + d8w.pw*y + d9w.pw*z + d12w.pw
xi= xx*skw+x0w
yi= yy*skw+y0w
zi= zz*skw+z0w
ifElse trafomode
[ setPixelXYZ xi yi zi
pal.(IntArray
(FloatArray (IntArray (FloatArray pw-1)/cfw))
*cf2w+15)
][
setPixelXYZ xi yi zi pal.Int t
]
x=xx
y=yy
z=zz
ox=x
oy=y
oz=z
pw=rotate pw random maxii
t=(Mod t palsize)+1
]
ifElse k < maxi2Move
[ x=combine x ox
y=combine y oy
z=combine z oz
pa.k=rotate p random maxii
opa.k=rotate op_ random maxii
maxii=Int 2^k
][
if Key? [break]
]
]
updateGraph
dispatchMessages
clearScreen
if w > 0
[ w=w-0.01
if w <=0
[ w=0
]
]
end