|
|
/*
IFS example for Steve McAvoys
by Luke Beeby, with all credit to the Stone Soup Group
*/
#include "colors.inc"
#include "transforms.inc"
/*
The following IFS samples were copy+pasted from the file fractint.ifs
from the fractint docs:
...
3D IFS definitions are a bit different. The name is followed by (3D) in
the definition file, and each line of the definition contains 13
numbers: a b c d e f g h i j k l p, defining:
matrix vector prob
|a b c| |j| p
|d e f| |k|
|g h i| |l|
...
where p is the probabiltiy of that transformation occuring at each iteration
*/
//3dTetrahedron (3D) by Alex Matulich
#declare IFS_3dTetrahedron = array[4][13]
{
{0.50, 0, 0, 0, 0.50, 0, 0, 0, 0.50, 0.00, 0.00, 1.00,
0.25}
{0.50, 0, 0, 0, 0.50, 0, 0, 0, 0.50, 0.00, 0.87, -0.50,
0.25}
{0.50, 0, 0, 0, 0.50, 0, 0, 0, 0.50, -0.87, -0.50, -0.50,
0.25}
{0.50, 0, 0, 0, 0.50, 0, 0, 0, 0.50, 0.87, -0.50, -0.50,
0.25}
}
#declare IFS_3d5Tetrahedron =array[5][13] { // by Alex Matulich
{0.44, 0, 0, 0, 0.44, 0 ,0 ,0 ,0.44 , 0.00 , 0.00 , 1.00
,0.20}
{0.44, 0, 0, 0, 0.44, 0 ,0 ,0 ,0.44 , 0.00 , 0.87 ,-0.50
,0.20}
{0.44, 0, 0, 0, 0.44, 0 ,0 ,0 ,0.44 ,-0.87 ,-0.50 ,-0.50
,0.20}
{0.44, 0, 0, 0, 0.44, 0 ,0 ,0 ,0.44 , 0.87 ,-0.50 ,-0.50
,0.20}
{0.44, 0, 0, 0, 0.44, 0 ,0 ,0 ,0.44 , 0.00 , 0.00 , 0.00
,0.20}
}
//3dfern (3D)
#declare IFS_3dfern = array[4][13]
{
{ .00, .00, 0, .0, .18, .0, 0, 0.0, 0.00, 0, 0.0, 0, .01}
{ .85, .00, 0, .0, .85, .1, 0, -0.1, 0.85, 0, 1.6, 0, .85}
{ .20, -.2, 0, .2, .20, .0, 0, 0.0, 0.30, 0, 0.8, 0, .07}
{-.20, .20, 0, .2, .20, .0, 0, 0.0, 0.30, 0, 0.8, 0, .07}
}
//3dDuodecahedron (3D) by Alex Matulich
#declare IFS_3dDuodecahedron = array[12][13]
{
{0.28, 0, 0, 0, 0.28, 0, 0, 0, 0.28, 0.00, 0.00, 0.96,
0.09}
{0.28, 0, 0, 0, 0.28, 0, 0, 0, 0.28, 0.00, 0.85, 0.43,
0.08}
{0.28, 0, 0, 0, 0.28, 0, 0, 0, 0.28, 0.81, 0.26, 0.43,
0.08}
{0.28, 0, 0, 0, 0.28, 0, 0, 0, 0.28, -0.81, 0.26, 0.43,
0.09}
{0.28, 0, 0, 0, 0.28, 0, 0, 0, 0.28, 0.50, -0.69, 0.43,
0.08}
{0.28, 0, 0, 0, 0.28, 0, 0, 0, 0.28, -0.50, -0.69, 0.43,
0.08}
{0.28, 0, 0, 0, 0.28, 0, 0, 0, 0.28, 0.50, 0.69, -0.43,
0.09}
{0.28, 0, 0, 0, 0.28, 0, 0, 0, 0.28, -0.50, 0.69, -0.43,
0.08}
{0.28, 0, 0, 0, 0.28, 0, 0, 0, 0.28, 0.81, -0.26, -0.43,
0.08}
{0.28, 0, 0, 0, 0.28, 0, 0, 0, 0.28, -0.81, -0.26, -0.43,
0.09}
{0.28, 0, 0, 0, 0.28, 0, 0, 0, 0.28, 0.00, -0.85, -0.43,
0.08}
{0.28, 0, 0, 0, 0.28, 0, 0, 0, 0.28, 0.00, 0.00, -0.96,
0.08}
}
//the data to use
#declare IFS_Data = IFS_3dTetrahedron;
//number of blob components
#declare MaxIter = 3000;
//a random stream
#declare nRand = seed(0);
//starting point. The overall fractal shape appears to be independant
//of where it starts, though I haven't checked in any detail.
#declare Point = <0,0,0>;
//make the fractal
blob
{
threshold 1
#declare Iter = 0;
#while (Iter < MaxIter)
//get random number
#local rNum = rand(nRand);
//return random index
//based on pre-defined probabilities
#local index = 0;
#while (rNum > IFS_Data[index][12])
#local rNum = rNum-IFS_Data[index][12];
#local index = index+1;
#end
//construct matrix
//note this could be handled more efficiently elsewhere
#local Trans = transform{matrix
<IFS_Data[index][0],IFS_Data[index][1],
IFS_Data[index][2],
IFS_Data[index][3],IFS_Data[index][4],
IFS_Data[index][5],
IFS_Data[index][6],IFS_Data[index][7],
IFS_Data[index][8],
IFS_Data[index][9],IFS_Data[index][10],
IFS_Data[index][11]> }
//transform the point
#local NewPoint = vtransform(Point,Trans);
//place a component
sphere
{
Point, 0.2, 0.15
}
#declare Point = NewPoint;
//iterate
#declare Iter = Iter+1;
#end
pigment{White}
rotate z*120
rotate y*30
}
camera
{
location<0,5,-6>
look_at <0,0,0>
angle 35
}
light_source
{
<0,0,0>
colour White*2
}
light_source
{
<-30,10,-10>
colour rgb<0.5,0.5,0.6>
}
light_source
{
<30,5,10>
colour rgb<0.6,0.5,0.4>
}
background{Gray40}
Post a reply to this message
|
|