"Fossies" - the Fresh Open Source Software Archive

Member "asymptote-2.61/examples/SierpinskiGasket.asy" (18 Nov 2019, 849 Bytes) of package /linux/misc/asymptote-2.61.src.tgz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 size(200);
    2 import palette;
    3 import three;
    4 currentprojection=perspective(8,2,1);
    5     
    6 triple[] M={(0,0,1),1/3*(sqrt(8),0,-1),
    7             1/3*((sqrt(8))*Cos(120),(sqrt(8))*Sin(120),-1),
    8             1/3*((sqrt(8))*Cos(240),(sqrt(8))*Sin(240),-1)};
    9     
   10 int level=5;
   11     
   12 surface s;
   13     
   14 void recur(triple p, real u, int l) {
   15   if(l < level)
   16     for(triple V : M)
   17       recur(p+u*V,u/2,l+1);
   18   else
   19     for(triple V : M) {
   20       s.append(surface((p+u*(V+M[0]))--(p+u*(V+M[1]))--(p+u*(V+M[2]))--cycle));
   21       s.append(surface((p+u*(V+M[0]))--(p+u*(V+M[2]))--(p+u*(V+M[3]))--cycle));
   22       s.append(surface((p+u*(V+M[0]))--(p+u*(V+M[3]))--(p+u*(V+M[1]))--cycle));
   23       s.append(surface((p+u*(V+M[3]))--(p+u*(V+M[2]))--(p+u*(V+M[1]))--cycle));
   24     }
   25 }
   26     
   27 recur(O,0.5,1);
   28     
   29 s.colors(palette(s.map(zpart),Rainbow()));
   30     
   31 draw(s,render(merge=true));