🔗Asymptote Gallery Tagged by “Function creation” #99
đź”—fractales-fig001

Show fractales/fig0010.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Surveys | Fractals
Tags : #Function (creating) | #Fractals | #Recursion | #Transform | #Picture
// From documentation of Asymptote size(250); real a=3; real b=4; real c=hypot(a,b); transform ta=shift(c,c)*rotate(-aCos(a/c))*scale(a/c)*shift(-c); transform tb=shift(0,c)*rotate(aCos(b/c))*scale(b/c); picture Pythagorean(int n) { picture pic; fill(pic,scale(c)*unitsquare,1/(n+1)*green+n/(n+1)*brown); if(n == 0) return pic; picture branch=Pythagorean(--n); add(pic,ta*branch); add(pic,tb*branch); return pic; } add(Pythagorean(12));
đź”—fractales-fig002

Show fractales/fig0020.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Surveys | Fractals
Tags : #Fractals | #Recursion | #Transform | #Function (creating)
size(10cm,0); transform scale(pair center, real k) { return shift(center)*scale(k)*shift(-center); } path trk=(0,0)--(0,1); void tree(path p, int n, real a=30, real b=40, real r=.75) { if (n!=0) { pair h=point(p,length(p)); transform tb=rotate(180-b,h)*scale(h,r); transform ta=rotate(-180+a,h)*scale(h,r); draw(p,n/3+1/(n+1)*green+n/(n+1)*brown); tree(tb*reverse(p),n-1,a,b,r); tree(ta*reverse(p),n-1,a,b,r); } } tree(trk,12,a=25,b=40,r=.75);
đź”—fractales-fig003

Show fractales/fig0030.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Surveys | Fractals
Tags : #Fractals | #Recursion | #Transform | #Picture | #Function (creating)
// Barnsley's fern // Fougère de Barnsley size(5cm,0); real ab=85, ac=-5; real rc=.85, rb=-.31; path trk=(0,0)--(0,1); transform ta=shift(0,1)*rotate(ab)*scale(rb); transform tb=shift(0,1)*rotate(-ab)*scale(rb); transform tc=shift(0,1)*rotate(ac)*scale(rc); picture fern(int n) { picture opic; draw(opic,trk^^ta*trk^^tb*trk^^tc*trk); if (n==0) return opic; picture branch=fern(n-1); add(opic,branch); add(opic,ta*branch); add(opic,tb*branch); add(opic,tc*branch); return opic; } add(fern(6));
đź”—fractales-fig006

Show fractales/fig0060.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Surveys | Fractals
Tags : #Fractals | #Recursion | #Random | #Function (creating)
//From documentation of Asymptote size(10cm); // Draw Sierpinski triangle with top vertex A, side s, and depth q. void Sierpinski(pair A, real s, int q, bool top=true, bool randcolor=false) { pair B=A-(1,sqrt(2))*s/2; pair C=B+s; if(top) draw(A--B--C--cycle); if (randcolor) { filldraw((A+B)/2--(B+C)/2--(A+C)/2--cycle, (.33*rand()/randMax*red+.33*rand()/randMax*green+.33*rand()/randMax*blue)); } else draw((A+B)/2--(B+C)/2--(A+C)/2--cycle); if(q > 0) { Sierpinski(A,s/2,q-1,false,randcolor); Sierpinski((A+B)/2,s/2,q-1,false,randcolor); Sierpinski((A+C)/2,s/2,q-1,false,randcolor); } } Sierpinski((0,1), 1, 5, randcolor=true);
đź”—generalities-fig099

Show generalities/fig0990.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Examples 2D | Generalities
Tags : #Basis | #Size | #Path | #Circle | #Function creation
size(6cm,0); //Return Circle AB diameter path circle(pair A, pair B) { return shift(midpoint(A--B))*scale(abs(A-B)/2)*unitcircle; } pair A=(0,0), B=(1,0), C=(2,0); path cleAB=circle(A,B); path cleAC=circle(A,C); for(real t=0; t<length(cleAB); t+=0.01) fill(circle(point(cleAB,t),point(cleAC,t)));
đź”—generalities-fig152

Show generalities/fig1530.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Examples 2D | Generalities
Tags : #Basis | #Path | #Transform/scale/shift/rotate | #Circle | #Function creation
size(0,0); pair inversion(pair O, real k, pair M) { return (O + k*unit(M-O)/abs(M-O)); } guide inversion(pair O, real k, path M) { guide opath=inversion(O,k,point(M,0)); for (real i=0; i<=length(M); i+=length(M)/100) opath = opath .. inversion(O,k,point(M,i)); return opath .. cycle; } real u=10cm; path [] p; path A = scale(u)*unitcircle; path B = scale(3)*A; pair z = rotate(10)*(5u,0); draw(inversion( z, 2*u^2, A ),linewidth(1pt)); draw(inversion( z, 2*u^2, B ),linewidth(1pt)); p[0] = shift(2u,0)*scale(u)*unitcircle; for (int i=0; i<=5; ++i) { if (i!=0) p[i] = rotate(360/6)*p[i-1]; draw(inversion( z, 2 (u^2), p[i] )); }
đź”—generalities-fig153

Show generalities/fig1540.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Examples 2D | Generalities
Tags : #Basis | #Path | #Function creation | #Loop/for/while
size(10cm,0); path unitpolygon(int n) { guide opath; for (int i=1; i<=n; ++i) opath=opath--rotate((i-1)*360/n)*E; return opath--cycle; } for (int i=3; i<9; ++i) draw(shift(2.5*(i%3),-2.5*quotient(i,3))*unitpolygon(i));
đź”—generalities-fig161

Show generalities/fig1620.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Examples 2D | Generalities
Tags : #Basis | #Circle | #Loop/for/while | #Function creation
size(6cm,0); pair A=2expi(pi/2); pair homography(pair z) { return (z^2+A)/(z+2); } guide image; pair tpt; draw(unitcircle); for(real t=0; t<length(unitcircle);t+=.05) { tpt=homography(point(unitcircle,t)); image=image..tpt; draw(point(unitcircle,t)--tpt,dotted); } draw(image..cycle,red);
đź”—generalities-fig176

Show generalities/fig1770.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Examples 2D | Generalities
Tags : #Basis | #Circle | #Intersection | #Function creation
size(6cm,0); import math; pair A=(0,0), B=(1,.5); path cle=shift(1.75,2.5)*unitcircle; pair pt, ptp; pair project(pair pt, pair A, pair B) { return extension(pt,pt-dir(90+degrees(A-B,false)),A,B); } draw(A--B); draw(cle); for (real t=0; t<=4; t+=.01) { pt=point(cle,t); ptp=project(pt,A,B); dot(ptp, red); draw(pt--ptp,dotted); }
đź”—generalities-fig180

Show generalities/fig1810.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Examples 2D | Generalities
Tags : #Basis | #Circle | #Geometry | #Intersection | #Function creation
size(6cm,0); import math; pair project(pair pt, pair A, pair B) { return extension(pt,pt-dir(90+degrees(A-B,false)),A,B); } pair ecenter(pair A, pair B, pair C) { return extension(A, A+rotate(90)*dir(A--B,A--C), B, B+rotate(90)*dir(B--A,B--C)); } path ecircle(pair A, pair B, pair C) { return shift(ecenter(A,B,C))*scale(abs(ecenter(A,B,C)-project(ecenter(A,B,C),B,C)))*unitcircle; } pair A=(0,0), B=(3,0), C=(3,4); path tr=A--B--C--cycle; draw(ecircle(A,B,C)); draw(ecircle(B,C,A)); pen p=linewidth(1pt); drawline(A,B, p); drawline(A,C, p); drawline(B,C, p);
đź”—randomwalk-fig001

Show randomwalk/fig0010.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Surveys | Random Walk (3D)
Tags : #Random | #Function (creating) | #Array | #Loop/for/while
import three; settings.render=0; // The available directions of steps triple[] dirs={X,-X,Y,-Y,Z,-Z}; dirs.cyclic=true; // Return the nodes of the path triple[] randWalk(real Srnd(), int n) { triple[] randPath; triple camera=1e10*currentprojection.camera; triple pos=O, tpos; int R; for (int i=0; i < n; ++i) { R=round(Srnd()); tpos=pos+dirs[R]; randPath.push(tpos); pos=tpos; } return randPath; } triple[] randWalk(int Srnd(), int n) { real R(){ return Srnd();} return randWalk(R,n); } void drawWalk(triple[] nodes, pen p=white) { triple camera=currentprojection.camera; if(currentprojection.infinity) camera *= max(abs(minbound(nodes)),abs(maxbound(nodes))); real[][] depth; for(int i=0; i < nodes.length-1; ++i) { real d=abs(camera-0.5*(nodes[i]+nodes[i+1])); depth.push(new real[] {d,i}); } depth=sort(depth); triple M=nodes[round(depth[0][1])]; triple m=nodes[round(depth[depth.length-1][1]+1)]; // Draw from farthest to nearest while(depth.length > 0) { real[] a=depth.pop(); int i=round(a[1]); draw(nodes[i]--nodes[i+1],abs(nodes[i]-m)/abs(M-m)*p); } } size(18cm); currentprojection=orthographic((1,1,1)); drawWalk(randWalk(rand,50000),cyan); shipout(bbox(3mm,Fill));
đź”—tiling-fig001

Show tiling/fig0010.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Surveys | Tiling
Tags : #Tiling | #Function (creating) | #Picture
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));
đź”—various-fig002

Show various/fig0200.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Miscellaneous
Tags : #Loop/for/while | #Fill/Unfill | #Basis | #Function (creating)
size(10cm); path g=box((-1,-1),(1,1)); pen [] col= new pen[]{gray,yellow}; path pairToSquare(pair pt){ return pt -- I*pt -- -pt -- -I*pt --cycle; } int nb=10; for (int i=0; i<nb; ++i) { filldraw(g,col[i%2]); g=pairToSquare(relpoint(g,1/16)); }