Tiling with Asymptote – fig0010

Category: Asymptote,Examples 2D,TilingPh. Ivaldi @ 12 h 06 min

Figure 0001
(Compiled with Asymptote version 1.87svn-r4652)
    
size(10cm,0);

picture pavehexagonal(int depth=1)
{
  picture opic;
  path hexa=polygon(6);
  pair center;
  real a,ap,r,rp,r_d=180/pi;

  for(int j=0; j<depth; ++j)
    {
      for (int i=1; i<=6; ++i)
        {
          a=i*60-30;
          r=j*sqrt(3);
          center=r*(rotate(a)*(1,0));
          filldraw(opic, shift(center)*hexa, j/depth*.8red+(1-j/depth)*.8*blue);
          //Uncomment to see centers of hexagons
          dot(opic, shift(center)*midpoint(point(hexa,0)--point(hexa,3)));
          //Uncomment to see circles passing by centers
          //draw(opic, scale(r)*unitcircle, j/depth*red+(1-j/depth)*blue);
          rp=r;
          ap=0;
          for (real k=0; k<j-1; ++k)
            {
              r=sqrt((1.5*(j-1 - k))^2 + 3/4*(j+1 + k)^2);
              ap+=r_d*acos((rp^2 + r^2 - 3)/(2*r*rp));
              center=r*(rotate(a + ap)*(1,0));
              filldraw(opic, shift(center)*hexa, j/depth*.8*red+(1-j/depth)*.8*blue);
              //Uncomment to see the centers of hexagons
              //dot(opic, shift(center)*midpoint(point(hexa,0)--point(hexa,3)));
              rp=r;
              //Uncomment to see circles passing by centers
              //draw(opic, scale(r)*unitcircle, j/depth*red+(1-j/depth)*blue);
            }
        }
    }
  return opic;
}


add(pavehexagonal(7));

Étiquettes : , ,


Tiling with Asymptote – fig0020

Category: Asymptote,Examples 2D,TilingPh. Ivaldi @ 13 h 06 min

Figure 0002
(Compiled with Asymptote version 1.87svn-r4652)
    
size(6cm,0);

//Circular paving with the unit hexagonal picture "hexa"
picture pavehexagonal(picture hexa, int depth=1)
{
  picture opic;
  pair center;
  real a,ap,r,rp,r_d=180/pi;

  add(opic, hexa);

  for(int j=0; j<depth; ++j)
    {
      for (int i=1; i<=6; ++i)
        {
          a=i*60-30;
          r=j*sqrt(3);
          center=r*(rotate(a)*(1,0));
          add(opic, shift(center)*hexa);
          rp=r;
          ap=0;
          for (real k=0; k<j-1; ++k)
            {
              r=sqrt((1.5*(j-1 - k))^2 + 3/4*(j+1 + k)^2);
              ap+=r_d*acos((rp^2 + r^2 - 3)/(2*r*rp));
              center=r*(rotate(a + ap)*(1,0));
              add(opic, shift(center)*hexa);
              rp=r;
            }
        }
    }
  return opic;
}

picture hexa;
fill(hexa, polygon(6));
path inh=(0,0)--(.6,sqrt(3)/4)--(.5,sqrt(3)/2)--cycle;

for(int i=0; i<6; ++i)
  {
    fill(hexa, rotate(60*i)*inh,.5red);
  }

draw(hexa, inh);
add(rotate(45)*pavehexagonal(hexa,10));
clip(scale(10)*shift(-.5,-.5)*unitsquare);

Étiquettes : ,


Tiling with Asymptote – fig0030

Category: Asymptote,Examples 2D,TilingPh. Ivaldi @ 14 h 06 min

Figure 0003
(Compiled with Asymptote version 1.87svn-r4652)
    
size(10cm,0);

transform r60=rotate(60);

pair A=(sqrt(3)/2,-.5);
pair B=r60*A, C=r60*B, D=r60*C, E=r60*D, F=r60*E;

path AB=A{dir(90)}..(.6,.5)..B{dir(0)};
path DE=shift(E-A)*reverse(AB);
path BC=B{dir(45)}..(.75,.7){dir(150)}..{dir(135)}(.65,.75){dir(70)}..(.5,1.25)..C{dir(255)};
path EF=shift(F-B)*reverse(BC);
path CD=C{dir(255)}..(-.4,.5){dir(200)}..D{dir(160)};
path FA=shift(A-C)*reverse(CD);

draw(A--B--C--D--E--F--cycle,linewidth(2pt));
draw(AB,2pt+.8red);
draw(DE,2pt+.8red);
draw(BC,2pt+.8blue);
draw(EF,2pt+.8blue);
draw(CD,2pt+.8green);
draw(FA,2pt+.8green);

picture hexa;
picture eye;

filldraw(hexa,AB--BC--CD--DE--EF--FA--cycle,black,white);
filldraw(eye,rotate(5)*xscale(.4)*unitcircle,white);
filldraw(hexa,subpath(AB,1,2)--subpath(BC,0,2){dir(225)}..{dir(245)}cycle,.1red+yellow,white);
draw(hexa,point(BC,0.1){dir(115)}.. (.8,.55) ..(.6,.65){dir(180)},yellow+grey);
filldraw(eye,rotate(5)*xscale(.4)*unitcircle,white);
fill(eye,rotate(5)*shift(0,-.1)*xscale(.25)*scale(.5)*unitcircle);
add(hexa,shift(.6,.9)*scale(.1)*eye);

add(shift(3,0)*hexa);

Étiquettes : , ,


Tiling with Asymptote – fig0040

Category: Asymptote,Examples 2D,TilingPh. Ivaldi @ 15 h 06 min

Figure 0004
(Compiled with Asymptote version 1.87svn-r4652)
    
size(15cm,0);

transform r60=rotate(60);
picture hexa;
picture eye;

pair A=(sqrt(3)/2,-.5);
pair B=r60*A, C=r60*B, D=r60*C, E=r60*D, F=r60*E;

//Body - corps
path AB=A{dir(90)}..(.6,.5)..B{dir(0)};
path DE=shift(E-A)*reverse(AB);
path BC=B{dir(45)}..(.75,.7){dir(150)}..{dir(135)}(.65,.75){dir(70)}..(.5,1.25)..C{dir(255)};
path EF=shift(F-B)*reverse(BC);
path CD=C{dir(255)}..(-.4,.5){dir(200)}..D{dir(160)};
path FA=shift(A-C)*reverse(CD);

filldraw(hexa,AB--BC--CD--DE--EF--FA--cycle,black,white);

//Nozzle - bec
filldraw(hexa,subpath(AB,1,2)--subpath(BC,0,2){dir(225)}..{dir(245)}cycle,.1red+yellow,white);
draw(hexa,point(BC,0.1){dir(115)}.. (.8,.55) ..(.6,.65){dir(180)},yellow+grey);

//Eye - oeil
filldraw(eye,rotate(5)*xscale(.4)*unitcircle,white);
filldraw(eye,rotate(5)*xscale(.4)*unitcircle,white);
fill(eye,rotate(5)*shift(0,-.1)*xscale(.25)*scale(.5)*unitcircle);
add(hexa,shift(.6,.9)*scale(.1)*eye);

//Circular paving with the unit hexagonal picture "hexa"
picture pavehexagonal(picture hexa, int depth=1)
{
  picture opic;
  pair center;
  real a,ap,r,rp,r_d=180/pi;

  add(opic, hexa);

  for(int j=0; j<depth; ++j)
    {
      for (int i=1; i<=6; ++i)
 {
   a=i*60-30;
   r=j*sqrt(3);
   center=r*(rotate(a)*(1,0));
   add(opic, shift(center)*hexa);
   rp=r;
   ap=0;
   for (real k=0; k<j-1; ++k)
     {
       r=sqrt((1.5*(j-1 - k))^2 + 3/4*(j+1 + k)^2);
       ap+=r_d*acos((rp^2 + r^2 - 3)/(2*r*rp));
       center=r*(rotate(a + ap)*(1,0));
       add(opic, shift(center)*hexa);
       rp=r;
     }
 }
    }
  return opic;
}

add(pavehexagonal(rotate(30)*hexa,3));

Étiquettes :


Tiling with Asymptote – fig0050

Category: Asymptote,Examples 2D,TilingPh. Ivaldi @ 16 h 06 min

Figure 0005
(Compiled with Asymptote version 1.87svn-r4652)
    
size(10cm,0);

transform r60=rotate(60);
picture hexa;

pair A=(1,0);
pair B=r60*A, C=r60*B, D=r60*C, E=r60*D, F=r60*E;

real ad=30;
real tensio=.15;
path AB=A {dir(120-ad)} .. shift(tensio*dir(30))*midpoint(A--B)  .. B {dir(120+ad)};
path BC=reverse(rotate(240,B)*AB);
path CD=reverse(rotate(240,C)*BC);
path DE=reverse(rotate(240,D)*CD);
path EF=reverse(rotate(240,E)*DE);
path FA=reverse(rotate(240,F)*EF);

real lux=-.3, sq=sqrt(3)/2;
radialshade(hexa,AB--BC--CD--DE--EF--FA--cycle,
            lightgrey,(lux*sq,lux/2),0,
            grey,(lux*sq,lux/2),1+abs(lux));

//Circular paving with the unit hexagonal picture "hexa"
picture pavehexagonal(picture hexa, int depth=1)
{
  picture opic;
  pair center;
  real a,ap,r,rp,r_d=180/pi;

  add(opic, hexa);

  for(int j=0; j<depth; ++j)
    {
      for (int i=1; i<=6; ++i)
 {
   a=i*60-30;
   r=j*sqrt(3);
   center=r*(rotate(a)*(1,0));
   add(opic, shift(center)*hexa);
   rp=r;
   ap=0;
   for (real k=0; k<j-1; ++k)
     {
       r=sqrt((1.5*(j-1 - k))^2 + 3/4*(j+1 + k)^2);
       ap+=r_d*acos((rp^2 + r^2 - 3)/(2*r*rp));
       center=r*(rotate(a + ap)*(1,0));
       add(opic, shift(center)*hexa);
       rp=r;
     }
 }
    }
  return opic;
}

add(pavehexagonal(hexa,4));

Étiquettes :


Tiling with Asymptote – fig0060

Category: Asymptote,Examples 2D,TilingPh. Ivaldi @ 17 h 06 min

Figure 0006
(Compiled with Asymptote version 1.87svn-r4652)
    
size(10cm,0);

transform r60=rotate(60);

pair A=(1,0);
pair B=r60*A, C=r60*B, D=r60*C, E=r60*D, F=r60*E;

real ad=30;
real tensio=.25;
path AB=A {dir(120-ad)} .. shift(tensio*dir(30))*midpoint(A--B)  .. B {dir(120+ad)};
path BC=reverse(rotate(240,B)*AB);
path CD=reverse(rotate(240,C)*BC);
path DE=reverse(rotate(240,D)*CD);
path EF=reverse(rotate(240,E)*DE);
path FA=reverse(rotate(240,F)*EF);
path pth1=AB--BC--CD--DE--EF--FA;

real tensio=.5;
path AB=A {dir(120-ad)} .. shift(tensio*dir(30))*midpoint(A--B)  .. B {dir(120+ad)};
path BC=reverse(rotate(240,B)*AB);
path CD=reverse(rotate(240,C)*BC);
path DE=reverse(rotate(240,D)*CD);
path EF=reverse(rotate(240,E)*DE);
path FA=reverse(rotate(240,F)*EF);
path pth2=AB--BC--CD--DE--EF--FA;


//Circular paving with the unit hexagonal picture "hexa"
picture pavehexagonal(picture hexa, int depth=1)
{
  picture opic;
  pair center;
  real a,ap,r,rp,r_d=180/pi;

  add(opic, hexa);

  for(int j=0; j<depth; ++j)
    {
      for (int i=1; i<=6; ++i)
 {
   a=i*60-30;
   r=j*sqrt(3);
   center=r*(rotate(a)*(1,0));
   add(opic, shift(center)*hexa);
   rp=r;
   ap=0;
   for (real k=0; k<j-1; ++k)
     {
       r=sqrt((1.5*(j-1 - k))^2 + 3/4*(j+1 + k)^2);
       ap+=r_d*acos((rp^2 + r^2 - 3)/(2*r*rp));
       center=r*(rotate(a + ap)*(1,0));
       add(opic, shift(center)*hexa);
       rp=r;
     }
 }
    }
  return opic;
}

picture hexa, hexat;

real lux=-.3, sq=sqrt(3);
radialshade(hexa,pth1--cycle,
            lightgrey,(lux*sq/2,lux/2),0,
            grey,(lux*sq/2,lux/2),1+abs(lux));


add(hexat,scale(1/(3*sq))*pavehexagonal(hexa,5));
clip(hexat,pth2--cycle);
draw(hexat,pth2);
add(pavehexagonal(hexat,4));

Étiquettes : ,


Tiling with Asymptote – fig0070

Category: Asymptote,Examples 2D,TilingPh. Ivaldi @ 18 h 06 min

Figure 0007
(Compiled with Asymptote version 1.87svn-r4652)
    
/*Author: Guillaume Connan */
size(10cm,0);

void zigzag(int k)
{
  real t=180/k;
  pair o=(0,0), m=dir(t),
    n=rotate(180-2*t,m)*o,
    b=rotate(4*t-180,n)*m,
    c=rotate(180-6*t,b)*n,
    nn=reflect(o,b)*n;

  path lo=m--n--b--nn--cycle,
    p=o--m--n--b--c--cycle,
    pp=reflect(o,b)*p;

  for (int i=0; i <= k; ++i){
    filldraw(rotate(2*t*i,o)*p,.5*(red+blue));
    filldraw(rotate(2*t*i,o)*pp,0.25(red+blue));
    filldraw(rotate(2*t*i,o)*lo,(red+blue));
  }
}

zigzag(25);
shipout(bbox(3mm,2mm+miterjoin+black,FillDraw(0.5*blue)));

Étiquettes : , , ,


L-System with Asymptote – fig0200

Category: Asymptote,L-SystemPh. Ivaldi @ 14 h 40 min

Figure 0020
(Compiled with Asymptote version 1.84svn-r4619)
    
/* Pavage P3 de Penrose
  Drawing the Penrose tiling P3 */
import Lsystem;
size(8cm,0);

string[][] rules={
  {"6","8F++9F----7F[-8F----6F]++"},
  {"7","+8F--9F[---6F--7F]+"},
  {"8","-6F++7F[+++8F++9F]-"},
  {"9","--8F++++6F[+9F++++7F]--7F"},
  {"F",""}
};

Lsystem Penrose=Lsystem("[7]++[7]++[7]++[7]++[7]", rules, La=36);
Penrose.iterate(4);
draw(Penrose.paths(), linewidth(bp));

shipout(bbox(2mm, FillDraw(lightyellow,linewidth(1mm))));

Étiquettes : ,


L-System with Asymptote – fig0210

Category: Asymptote,L-SystemPh. Ivaldi @ 15 h 40 min

Figure 0021
(Compiled with Asymptote version 1.84svn-r4619)
    
/* Pavage de Penrose
  Source */
import Lsystem;
size(8cm,0);

string[][] rules={
  {"W", "YF++ZF----XF[-YF----WF]++"},
  {"X", "+YF--ZF[---WF--XF]+"},
  {"Y", "-WF++XF[+++YF++ZF]-"},
  {"Z", "--YF++++WF[+ZF++++XF]--XF"},
  {"F", ""}
};

Lsystem Penrose=Lsystem("++ZF----XF-YF----WF",rules,La=36);

Penrose.iterate(4);
draw(Penrose.paths(), linewidth(bp));

shipout(bbox(2mm, FillDraw(lightyellow,linewidth(1mm))));

Étiquettes : ,


L-System with Asymptote – fig0220

Category: Asymptote,L-SystemPh. Ivaldi @ 16 h 40 min

Figure 0022
(Compiled with Asymptote version 1.84svn-r4619)
    
/* Double pavage de Penrose
  Source */
import Lsystem;
size(8cm,0);

string[][] rules={
  {"W", "YF++ZF----XF[-YF----WF]++"},
  {"X", "+YF--ZF[---WF--XF]+"},
  {"Y", "-WF++XF[+++YF++ZF]-"},
  {"Z", "--YF++++WF[+ZF++++XF]--XF"},
  {"F", ""}
};

Lsystem Penrose=Lsystem("[X][Y]++[X][Y]++[X][Y]++[X][Y]++[X][Y]",rules,La=36);

Penrose.iterate(3);
draw(Penrose.paths(), linewidth(bp));

shipout(bbox(2mm, FillDraw(lightyellow,linewidth(1mm))));

Étiquettes : ,


Official Asymptote example – mosaic

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 0 h 57 min

Figure 0145
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
// Calendar example contributed by Jens Schwaiger

// transformations
path similarpath(pair a, pair b, path p) {
  // transform p into a path starting at a and ending at b
  pair first;
  pair last;
  path p_;
  first=point(p,0);
  last=point(p,length(p));
  p_=shift(-first)*p;
  p_=rotate(degrees(b-a))*p_;
  p_=scale(abs(b-a)/abs(last-first))*p_;
  p_=shift(a)*p_;
  return p_;
}

path c_line(path p) {
  // returns the path obtained by adding to p a copy rotated
  // around the endpoint of p by 180 degrees
  // works only if the initial point and the endpoint of p are different
  // a c_line is symetric with respect to the center of 
  // the straight line between its endpoints
  //
  return p..rotate(180,point(p,length(p)))*reverse(p);
}

path tounitcircle(path p, int n=300) {
  // the transformation pair x --> x/sqrt(1+abs(x)^2)
  // is a bijection from the plane to the open unitdisk
  real l=arclength(p);
  path ghlp;
  for(int i=0; i <= n; ++i) {
    real at=arctime(p,l/n*i);
    pair phlp=point(p,at);
    real trhlp=1/(1+abs(phlp)^2)^(1/2);
    ghlp=ghlp--trhlp*phlp;
  }
  if(cyclic(p)) {ghlp=ghlp--cycle;}
  return ghlp;
}

void centershade(picture pic=currentpicture, path p, pen in, pen out,
                 pen drawpen=currentpen) { 
  pair center=0.5(max(p)+min(p));
  real radius=0.5abs(max(p)-min(p));
  radialshade(pic,p,in,center,0,out,center,radius);
  draw(pic,p,drawpen);
}

pair zentrum(path p) {return 0.5(min(p)+max(p));}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

real scalefactor=19/13; // For output: height=scalefactor*width
real outputwidth=13cm;
picture kalender;// at first we produce a calendar for february 2006
texpreamble("\usepackage[latin1]{inputenc}");
size(outputwidth,0);
real yc=0.5;
pair diff=(-3.5,5*yc);
pen farbe(int j) {
  pen hlp=0.8white;
  if(j % 7 == 6) {hlp=red+white;}
  return hlp;}

// farbe=German word for color
path kasten=yscale(yc)*unitsquare;
// Kasten is a German word meaning something like box
path Gkasten=shift((0,2*yc)+diff)*xscale(7)*yscale(2)*kasten;
path tage[]= new path[7]; // Tag=day
string wochentag[]={"MO","DI","MI","DO","FR","SA","SO"};
path[][] bx= new path[6][7];
string[][] entry= new string[6][7];
bool[][] holiday=new bool[6][7];

// Now the necessary information for February 2006
int start=2;
int days=28;
for(int i=0; i < entry.length; ++i) {
  for(int j=0; j < entry[0].length; ++j) {
    int day=i*7+j-start+1;
    entry[i][j]=(day > 0 && day <= days ? (string) day : "");
    holiday[i][j]=false;
  }
}

for(int j=0; j < 7; ++j) {
  tage[j]=shift((j,yc)+diff)*kasten; 
  filldraw(tage[j],farbe(j),black+2bp);
  label(wochentag[j],zentrum(tage[j]),Palatino());
  for(int i=0; i < 6; ++i) {bx[i][j]=shift((j,-yc*i)+diff)*kasten;
    filldraw(bx[i][j],farbe(j),black+2bp);
    if(holiday[i][j]) {filldraw(bx[i][j],farbe(6),black+2bp);};
  };
};
filldraw(Gkasten,0.3white,black+2bp); 
for(int j=0; j < 7; ++j)
  for(int i=0; i < 6 ; ++i) {label(entry[i][j],zentrum(bx[i][j]),Palatino());}
label("\Huge Februar 2006",zentrum(Gkasten),Palatino()+white); 
// Zentrum=center; Februar=february
add(kalender,currentpicture);
erase();

// Now the mosaic is constructed
pair a[]=new pair[4];
path p[]=new path[4];
path q[]=new path[4];
path kontur[]=new path[5];
picture temppic;

a[1]=(0,0);
a[2]=(1,0);
a[3]=(0,1); // a triangle with abs(a[2]-a[1])=abs(a[3]-a[1]
            // and a right angle at a[1];
q[1]=(0,0){dir(-20)}::{dir(20)}(0.2,0){dir(-140)}..{dir(0)}(0.3,-0.2){dir(0)}..
{dir(140)}(0.4,0){dir(20)}..{dir(-20)}(1,0);
q[2]=(0,0){dir(20)}..{dir(-20)}(0.8,0){dir(-140)}..{dir(0)}(0.9,-0.3){dir(0)}..
{dir(140)}(1,0);
q[2]=c_line(q[2]);
p[1]=similarpath(a[1],a[2],q[1]);// arbitrary path from a[1] to a[2]
p[2]=similarpath(a[2],a[3],q[2]);// arbitrary c_line from a[2] to a[3]
p[3]=rotate(90,a[1])*reverse(p[1]);//
kontur[1]=p[1]..p[2]..p[3]..cycle;// first tile
kontur[2]=rotate(90,a[1])*kontur[1];// second
kontur[3]=rotate(180,a[1])*kontur[1];// third
kontur[4]=rotate(270,a[1])*kontur[1];// fourth
pair tri=2*(interp(a[2],a[3],0.5)-a[1]);
pair trii=rotate(90)*tri;
// translations of kontur[i], i=1,2,3,4, with respect to
// j*tri+k*trii
// fill the plane

for(int j=-4; j < 4; ++j)
  for(int k=-4; k < 4; ++k) {
    transform tr=shift(j*tri+k*trii);
    for(int i=1; i < 5; ++i) {
      centershade(temppic,tr*kontur[i],(1-i/10)*white,
                  (1-i/10)*chartreuse,black+2bp);
    }
  }
  
// Now we produce the bijective images inside 
// a suitably scaled unitcircle            
for(int k=-1; k < 2; ++k)
  for(int l=-1; l < 2; ++l) {
    transform tr=shift(k*tri+l*trii);
    for(int i=1; i < 5; ++i) {
      centershade(temppic,scale(2.5)*tounitcircle(tr*kontur[i],380),
                  (1-i/10)*white,(1-i/10)*orange,black+2bp);
    }
  }         
          
add(temppic); 

// We clip the picture to a suitable box 
pair piccenter=0.5*(temppic.min()+temppic.max());
pair picbox=temppic.max()-temppic.min();
real picwidth=picbox.x;
transform trialtrans=shift(0,-1.5)*shift(piccenter)*yscale(scalefactor)*
  scale(0.25picwidth)*shift((-0.5,-0.5))*identity();
clip(trialtrans*unitsquare);

// add the calendar at a suitable position
add(kalender.fit(0.75*outputwidth),interp(point(S),point(N),1/13)); 

Étiquettes :


Official Asymptote example – shadedtiling

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 15 h 57 min

Figure 0195
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
size(0,100);
import patterns;

real d=4mm;
picture tiling;
path square=scale(d)*unitsquare;
axialshade(tiling,square,white,(0,0),black,(d,d));
fill(tiling,shift(d,d)*square,blue);
add("shadedtiling",tiling);

filldraw(unitcircle,pattern("shadedtiling"));


Étiquettes : , , ,


Official Asymptote example – soccerball

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 0 h 57 min

Figure 0208
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
import graph3; 
size(400); 
currentlight.background=palegreen;

defaultrender=render(compression=Zero,merge=true);

real c=(1+sqrt(5))/2; 
 
triple[] z={(c,1,0),(-c,1,0),(-c,-1,0),(c,-1,0)}; 
triple[] x={(0,c,1),(0,-c,1),(0,-c,-1),(0,c,-1)}; 
triple[] y={(1,0,c),(1,0,-c),(-1,0,-c),(-1,0,c)}; 
 
triple[][] Q={
  {z[0],y[1],x[3],x[0],y[0],z[3]},
  {z[1],x[0],x[3],y[2],z[2],y[3]},
  {z[2],z[1],y[2],x[2],x[1],y[3]},
  {z[3],z[0],y[0],x[1],x[2],y[1]},
  {x[0],x[3],z[1],y[3],y[0],z[0]},
  {x[1],x[2],z[2],y[3],y[0],z[3]},
  {x[2],x[1],z[3],y[1],y[2],z[2]},
  {x[3],x[0],z[0],y[1],y[2],z[1]},
  {y[0],y[3],x[1],z[3],z[0],x[0]},
  {y[1],y[2],x[2],z[3],z[0],x[3]},
  {y[2],y[1],x[3],z[1],z[2],x[2]},
  {y[3],y[0],x[0],z[1],z[2],x[1]} 
}; 
 
path3 p=arc(O,Q[0][0],Q[0][1]); 
real R=abs(point(p,reltime(p,1/3))); 
 
triple[][] P;
for(int i=0; i < Q.length; ++i){
  P[i]=new triple[] ; 
  for(int j=0; j < Q[i].length; ++j){
    P[i][j]=Q[i][j]/R; 
  } 
} 
 
surface sphericaltriangle(triple center, triple A, triple B, triple C,
                          int nu=3, int nv=nu) {
  path3 tri1=arc(center,A,B); 
  path3 tri2=arc(center,A,C); 
  path3 tri3=arc(center,B,C); 
  triple tri(pair p) {
    path3 cr=arc(O,relpoint(tri2,p.x),relpoint(tri3,p.x)); 
    return relpoint(cr,p.y); 
  }; 
 
  return surface(tri,(0,0),(1-sqrtEpsilon,1),nu,nv,Spline); 
} 
 
for(int i=0; i < P.length; ++i){
  triple[] pentagon=sequence(new triple(int k) {
      path3 p=arc(O,P[i][0],P[i][k+1]); 
      return point(p,reltime(p,1/3)); 
    },5); 
  pentagon.cyclic=true; 
  draw(sequence(new path3(int k) {
        return arc(O,pentagon[k],pentagon[k+1]);},5),linewidth(2pt)); 
  triple M=unit(sum(pentagon)/5); 
  for(int i=0; i < 5; ++i){
    surface sf=sphericaltriangle(O,pentagon[i],M,pentagon[i+1]); 
    draw(sf,black); 
  } 
} 
 
for(int i=0; i < P.length; ++i){
  for(int j=1; j <= 5; ++j){
    triple K=P[i][0]; 
    triple A=P[i][j]; 
    triple B=P[i][(j % 5)+1]; 
    path3[] p={arc(O,K,A),arc(O,A,B),arc(O,B,K)}; 
    draw(subpath(p[0],reltime(p[0],1/3),reltime(p[0],2/3)),linewidth(4pt)); 
    triple[] hexagon={point(p[0],reltime(p[0],1/3)),
                      point(p[0],reltime(p[0],2/3)),
                      point(p[1],reltime(p[1],1/3)),
                      point(p[1],reltime(p[1],2/3)),
                      point(p[2],reltime(p[2],1/3)),
                      point(p[2],reltime(p[2],2/3))}; 
    hexagon.cyclic=true; 
    triple M=unit(sum(hexagon)/6); 
    for(int i=0; i < 6; ++i){
      surface sf=sphericaltriangle(O,hexagon[i],M,hexagon[i+1]); 
      draw(sf,white); 
    } 
  } 
}

Étiquettes : , , , , , ,


Official Asymptote example – tile

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 2 h 57 min

Figure 0235
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
size(0,90);
import patterns;

add("tile",tile());
add("filledtilewithmargin",tile(6mm,4mm,red,Fill),(1mm,1mm),(1mm,1mm));
add("checker",checker());
add("brick",brick());

real s=2.5;
filldraw(unitcircle,pattern("tile"));
filldraw(shift(s,0)*unitcircle,pattern("filledtilewithmargin"));
filldraw(shift(2s,0)*unitcircle,pattern("checker"));
filldraw(shift(3s,0)*unitcircle,pattern("brick"));

Étiquettes : , , ,