Asymptote Generalities – fig0720

Category: Asymptote,Examples 2D,GeneralitiesPh. Ivaldi @ 21 h 39 min

Figure 0072
(Compiled with Asymptote version 2.14svn-r5318)
    
size(4cm,4cm);

dot(Label("$A$"),(0,0),S);
draw(E--W,invisible);
draw(N--S,invisible);
shipout(bbox());

Étiquettes : , , , ,


Asymptote Generalities – fig0840

Category: Asymptote,Examples 2D,GeneralitiesPh. Ivaldi @ 9 h 39 min

Figure 0084
(Compiled with Asymptote version 2.14svn-r5318)
    
pair c=0;
label("abc xyz ijk",c,Align,basealign);
label("abc xyz ijk",c,Align,red);
draw(c--(c+(2cm,0))); // This is the baseline.

shipout((scale(3)*currentpicture.fit()));

Étiquettes : , , , ,


Asymptote Generalities – fig1580

Category: Asymptote,Examples 2D,GeneralitiesPh. Ivaldi @ 11 h 39 min

Figure 0157
(Compiled with Asymptote version 2.14svn-r5318)
    
size(0,0);

label(graphic("dali.eps","width=5cm"));
layer();

draw(scale(2cm)*unitcircle,linewidth(.75mm));
shipout(bbox(.25cm,Fill));

Étiquettes : , , , ,


Asymptote Generalities – fig1590

Category: Asymptote,Examples 2D,GeneralitiesPh. Ivaldi @ 12 h 39 min

Figure 0158
(Compiled with Asymptote version 2.14svn-r5318)
    
size(0,0);

label(graphic("dali.eps","width=5cm, bb=60 60 235 205, clip=true"));
shipout(bbox(.25cm,Fill));

Étiquettes : , , ,


Asymptote Generalities – fig1760

Category: Asymptote,Examples 2D,GeneralitiesPh. Ivaldi @ 5 h 39 min

Figure 0175
(Compiled with Asymptote version 2.14svn-r5318)
    
import graph;
size(6cm,0);

path a = polargraph(new real(real t){return t;}, 0, 3pi, operator ..);
path b = polargraph(new real(real t){return 2t;}, 0, 3.75pi, operator ..);

real sharp=40;
path c=relpoint(a,1){relpoint(a,1)-postcontrol(a,length(a)-1)}..{dir(sharp)}relpoint(b,1);

fill(a..c..reverse(b)&cycle,0.8*red);
shipout(bbox(2mm, Fill(0.15*blue)));

Étiquettes : , , , , ,


Asymptote using geometry.asy – fig1160

Category: Asymptote,Examples 2D,geometry.asyPh. Ivaldi @ 1 h 02 min

Figure 0116
(Compiled with Asymptote version 2.14svn-r5318)
    
unitsize(1cm);
import geometry;

point pA = (0,0);
point pB = (5,0);
point pC = (5,5);

dot(pA^^pB^^pC);
draw(pA--pB--pC--cycle);

distance(Label("$x \; \mathrm{cm}$",align=S),pA,pB,3mm);
distance(Label("$y \; \mathrm{cm}$",align=E),pB,pC,3mm);
distance(Label("$z \; \mathrm{cm}$",align=I*dir(pA--pC)),pA,pC,-3mm);

shipout(bbox(xmargin=1mm,invisible));

Étiquettes : , , , , , ,


Asymptote using geometry.asy – fig1170

Category: Asymptote,Examples 2D,geometry.asyPh. Ivaldi @ 2 h 02 min

Figure 0117
(Compiled with Asymptote version 1.92svn-r4817)
    
import geometry; size(8cm);

inversion inv=inversion(1,(-4.5,0));
path g1=inv*line((-1,0),(-1,1)),
g2=inv*line((1,0),(1,1));
fill(g1,lightgrey); draw(g1,linewidth(bp));
unfill(g2); draw(g2,linewidth(bp));

int n=40;
for (int i=-n; i <= n; ++i) {
  path g=inv*circle((point) (0,2*i),1);
  fill(g,(1-abs(i)/n)*yellow);
  draw(g,bp+red); draw(g,blue);
}
shipout(bbox(5mm,Fill(rgb(0.95,0.95,0.8))));

Étiquettes : , , , , ,


Asymptote and opacity – fig0180

Category: Asymptote,Examples 2D,OpacityPh. Ivaldi @ 9 h 54 min

Figure 0018
(Compiled with Asymptote version 1.87svn-r4652)
    
size(4cm,0);
dotfactor*=5;

dot(scale(2)*"A",(0.5,1),5N);

layer();

dot(scale(2)*"B",(1.5,1),5N);
filldraw(scale(2)*unitsquare, lightgray+opacity(.5));

shipout(bbox(5mm,black,RadialShade(lightblue,darkblue)), "pdf");

É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 : , , ,


Official Asymptote example – pdb

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

Figure 0152
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import three;
import cpkcolors;

// A sample Protein Data Bank file for this example is available from
// http://ndbserver.rutgers.edu/ftp/NDB/coordinates/na-biol/100d.pdb1

bool getviews=true;

currentlight=White;
//currentlight=nolight;

size(200);
currentprojection=perspective(30,30,15);

// Uncomment this line for more accurate (but slower) PDF rendering
//dotgranularity=0;

pen chainpen=green;
pen hetpen=purple;

string filename="100d.pdb1";
//string filename=getstring("filename");

string prefix=stripextension(filename);
file data=input(filename);

pen color(string e) 
{
  e=replace(e," ","");
  int n=length(e);
  if(n < 1) return currentpen;
  if(n > 1) e=substr(e,0,1)+downcase(substr(e,1,n-1));
  int index=find(Element == e);
  if(index < 0) return currentpen;
  return rgb(Hexcolor[index]);
}       

// ATOM
string[] name,altLoc,resName,chainID,iCode,element,charge;
int[] serial,resSeq;
real[][] occupancy,tempFactor;

bool newchain=true;

struct bond 
{
  int i,j;
  void operator init(int i, int j) {
    this.i=i;
    this.j=j;
  }
}

bond[] bonds;

struct atom 
{
  string name;
  triple v;
  void operator init(string name, triple v) {
    this.name=name;
    this.v=v;
  }
}

struct chain
{
  int[] serial;
  atom[] a;
}

int[] serials;
chain[] chains;
atom[] atoms;

while(true) {
  string line=data;
  if(eof(data)) break;
  string record=replace(substr(line,0,6)," ","");
  if(record == "TER") {newchain=true; continue;}
  bool ATOM=record == "ATOM";
  bool HETATOM=record == "HETATM";
  int serial;

  atom a;
  if(ATOM || HETATOM) {
    serial=(int) substr(line,6,5);
    a.name=substr(line,76,2);
    a.v=((real) substr(line,30,8),
         (real) substr(line,38,8),
         (real) substr(line,46,8));
  }
  if(ATOM) {
    if(newchain) {
      chains.push(new chain);
      newchain=false;
    }
    chain c=chains[chains.length-1];
    c.serial.push(serial);
    c.a.push(a);
    continue;
  }
  if(HETATOM) {
    serials.push(serial);
    atoms.push(a);
  }
  if(record == "CONECT") {
    int k=0;
    int i=(int) substr(line,6,5);
    while(true) {
      string s=replace(substr(line,11+k,5)," ","");
     if(s == "") break;
      k += 5;
      int j=(int) s;
      if(j <= i) continue;
      bonds.push(bond(i,j));
     }
  }
}

write("Number of atomic chains: ",chains.length);

int natoms;
for(chain c : chains) {
  for(int i=0; i < c.a.length-1; ++i)
    draw(c.a[i].v--c.a[i+1].v,chainpen,currentlight);
  for(atom a : c.a)
    dot(a.v,color(a.name),currentlight);
  natoms += c.a.length;
}

write("Number of chained atoms: ",natoms);
write("Number of hetero atoms: ",atoms.length);

for(atom h : atoms)
  dot(h.v,color(h.name),currentlight);

write("Number of hetero bonds: ",bonds.length);

for(bond b : bonds) {
  triple v(int i) {return atoms[find(serials == i)].v;}
  draw(v(b.i)--v(b.j),hetpen,currentlight);
}

string options;
string viewfilename=prefix+".views";

if(!error(input(viewfilename,check=false)))
  options="3Dviews="+viewfilename;

if(getviews) {
  picture pic;
  add(pic,embed("label",currentpicture,options=options),(0,0),N);
  label(pic,cameralink("label"),(0,0),S,fontsize(12pt));
  shipout(prefix,pic,options=options);
} else
  shipout(prefix,options=options);

Étiquettes : , , , , ,


Official Asymptote example – strokepath

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

Figure 0225
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
path g=scale(100)*unitcircle;
pen p=linewidth(1cm);

frame f;
// Equivalent to draw(f,g,p):
fill(f,strokepath(g,p),red);
shipout("strokepathframe",f);
shipped=false;

size(400);

// Equivalent to draw(g,p):
add(new void(frame f, transform t) {
    fill(f,strokepath(t*g,p),red);
  });
currentpicture.addPath(g,p);


Étiquettes : , ,