|
![](/i/fill.gif) |
Ok
min_sides: the minimum number of sides your cristal will have
max_sides: the maximum;
diam: the edges are on a circle of diameter diam
height: the heigth of the crown
var: the variance of the points
top: the absolute topmost points
rand_seed... welll
ex:
mesh_cristal(4,7, 1, 3, 0.1, 4, s)
produces a cristal of 4 to 7 faces, contained in a cylinder of diameter 1,
that have its pointy end starting at 3 +- 0.1, and culminates at 4.
Same with the two-ended version
best,
S.
#macro mesh_cristal(min_sides,max_sides,diam, height,var,top,rand_seed)
#local nb_sides = min_sides+floor (0.5 +
(max_sides-min_sides)*rand(rand_seed) );
#declare angles = array [ nb_sides ]; // angles
#declare bases = array [ nb_sides ];
#declare mi_hauteurs = array [ nb_sides ];
#declare sommets = array [ nb_sides] ;
// some random values
#local i=0;
#while (i<nb_sides)
#declare angles[i]=rand(rand_seed) * 360;
#declare i=i+1;
#end
// sort them
#local i=0;
#while (i < nb_sides - 1 )
#local j=i+1;
#while (j < nb_sides )
#if (angles[i]>angles[j])
#local temp = angles[i];
#declare angles[i]=angles[j];
#declare angles[j]=temp;
#end //if
#declare j=j+1;
#end // while (j
#declare i=i+1;
#end // while (i
#local i=0;
#while (i<nb_sides)
#declare bases[i] = vrotate( < 0,0,diam>, <0,angles[i],0 >);
#declare mi_hauteurs[i]=bases[i]+<0,height+rand(rand_seed)*var,0>;
#declare i=i+1;
#end
mesh
{
#local i=0;
#while (i<nb_sides)
triangle { bases[i],mi_hauteurs[i],mi_hauteurs[mod(i+1,nb_sides)] }
triangle { bases[i],bases[mod(i+1,nb_sides)],
mi_hauteurs[mod(i+1,nb_sides)] }
#declare i=i+1;
#end
#declare sommets = bases ;
#local random_vect = vrotate(<0,0,10>,rand(rand_seed)*360); // some
vector in the x-z plane
#local random_angle = rand(rand_seed)*15;
#local i=0;
#while (i<nb_sides)
#declare sommets[i]=vaxis_rotate(sommets[i]/2,random_vect,random_angle)
+ <0,top,0>;
#declare i=i+1;
#end
#local i=0;
#while (i<nb_sides)
triangle { sommets[i],mi_hauteurs[i],mi_hauteurs[mod(i+1,nb_sides)] }
triangle { sommets[i],sommets[mod(i+1,nb_sides)],
mi_hauteurs[mod(i+1,nb_sides)] }
#declare i=i+1;
#end
#local i=0;
#while (i<nb_sides)
triangle { bases[0],bases[i],bases[mod(i+1,nb_sides)] }
triangle { sommets[0],sommets[i],sommets[mod(i+1,nb_sides)] }
#declare i=i+1;
#end
} // mesh
#end // macro
//////////////////////////////////////////////////////////////
#macro two_ended_mesh_cristal(min_sides,max_sides,diam,
height,var,top,rand_seed)
#local nb_sides = min_sides+floor (0.5 +
(max_sides-min_sides)*rand(rand_seed) );
#declare angles = array [ nb_sides ]; // angles
#declare bases = array [ nb_sides ];
#declare mi_hauteurs = array [ nb_sides ];
#declare mi_profondeurs = array[ nb_sides ];
#declare sommets = array [ nb_sides ] ;
#declare fonds = array [ nb_sides ];
// some random values
#local i=0;
#while (i<nb_sides)
#declare angles[i]=rand(rand_seed) * 360;
#declare i=i+1;
#end
// sort them
#local i=0;
#while (i < nb_sides - 1 )
#local j=i+1;
#while (j < nb_sides )
#if (angles[i]>angles[j])
#local temp = angles[i];
#declare angles[i]=angles[j];
#declare angles[j]=temp;
#end //if
#declare j=j+1;
#end // while (j
#declare i=i+1;
#end // while (i
#local i=0;
#while (i<nb_sides)
#declare bases[i] = vrotate( < 0,0,diam>, <0,angles[i],0 >);
#declare mi_hauteurs[i]=bases[i]+<0,height+rand(rand_seed)*var,0>;
#declare mi_profondeurs[i]=bases[i]-<0,height+rand(rand_seed)*var,0>;
#declare i=i+1;
#end
mesh
{
#local i=0;
#while (i<nb_sides)
triangle {
mi_profondeurs[i],mi_hauteurs[i],mi_hauteurs[mod(i+1,nb_sides)] }
triangle { mi_profondeurs[i],mi_profondeurs[mod(i+1,nb_sides)],
mi_hauteurs[mod(i+1,nb_sides)] }
#declare i=i+1;
#end
// sommets
#declare sommets = bases ;
#local random_vect = vrotate(<0,0,10>,rand(rand_seed)*360); // some
vector in the x-z plane
#local random_angle = rand(rand_seed)*15;
#local i=0;
#while (i<nb_sides)
#declare sommets[i]=vaxis_rotate(sommets[i]/2,random_vect,random_angle)
+ <0,top,0>;
#declare i=i+1;
#end
#local i=0;
#while (i<nb_sides)
triangle { sommets[i],mi_hauteurs[i],mi_hauteurs[mod(i+1,nb_sides)] }
triangle { sommets[i],sommets[mod(i+1,nb_sides)],
mi_hauteurs[mod(i+1,nb_sides)] }
#local i=i+1;
#end
#local i=0;
#while (i<nb_sides)
triangle { sommets[0],sommets[i],sommets[mod(i+1,nb_sides)] }
#local i=i+1;
#end
// fonds
#declare fonds = bases ;
#local random_vect = vrotate(<0,0,10>,rand(rand_seed)*360); // some
vector in the x-z plane
#local random_angle = rand(rand_seed)*15;
#local i=0;
#while (i<nb_sides)
#declare fonds[i]=vaxis_rotate(fonds[i]/2,random_vect,random_angle) -
<0,top,0>;
#local i=i+1;
#end
#local i=0;
#while (i<nb_sides)
triangle {
fonds[i],mi_profondeurs[i],mi_profondeurs[mod(i+1,nb_sides)] }
triangle { fonds[i],mi_profondeurs[mod(i+1,nb_sides)],
fonds[mod(i+1,nb_sides)] }
#local i=i+1;
#end
#local i=0;
#while (i<nb_sides)
triangle { fonds[0],fonds[i],fonds[mod(i+1,nb_sides)] }
#local i=i+1;
#end
} // mesh
#end // macro
Post a reply to this message
|
![](/i/fill.gif) |