|
|
|
(Compiled with Asymptote version 1.84svn-r4619)
|
|
import three;
settings.render=0;
// The available directions of steps
triple[] dirs={X,-X,Y,-Y,Z,-Z};
dirs.cyclic=true;
struct walk
{
triple[] nodes;
pen[] p;
}
// Comput the nodes of the path
walk randWalk(real Srnd(), int n, pen[] p={currentpen})
{
p.cyclic=true;
walk ow;
triple pos=O, tpos;
for (int i=0; i < n; ++i) {
int R=round(Srnd());
tpos=pos+dirs[R];
ow.nodes.push(tpos);
ow.p.push(p[R]);
pos=tpos;
}
return ow;
}
walk randWalk(int Srnd(), int n, pen[] p={currentpen})
{
real R(){ return Srnd();}
return randWalk(R,n,p);
}
void drawWalk(walk walk)
{
triple camera=currentprojection.camera;
if(currentprojection.infinity)
camera *= max(abs(minbound(walk.nodes)),abs(maxbound(walk.nodes)));
real[][] depth;
for(int i=0; i < walk.nodes.length-1; ++i) {
real d=abs(camera-0.5*(walk.nodes[i]+walk.nodes[i+1]));
depth.push(new real[] {d,i});
}
depth=sort(depth);
triple M=walk.nodes[round(depth[0][1])];
triple m=walk.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]);
// dot(walk.nodes[i],walk.p[i]);
draw(walk.nodes[i]--walk.nodes[i+1],abs(walk.nodes[i]-m)/abs(M-m)*(walk.p[i]+walk.p[i+1]));
}
}
size(18cm);
currentprojection=orthographic((0.5,0.5,1));
drawWalk(randWalk(rand,50000,new pen[]{red, blue, green, yellow, purple}));
shipout(bbox(3mm,Fill));
Mots-clefs : Random, struct
|
|
|
(Compiled with Asymptote version 1.84svn-r4619)
|
|
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));
Mots-clefs : array, Function (creating), Loop/for/while, Random
|
|
|
(Compiled with Asymptote version 1.87svn-r4652)
|
|
import tube;
import graph3;
import palette;
size(12cm,0);
currentprojection=perspective(1,1,1);
int e=1;
real x(real t) {return cos(t)+2*cos(2t);}
real y(real t) {return sin(t)-2*sin(2t);}
real z(real t) {return 2*e*sin(3t);}
path3 p=scale3(2)*graph(x,y,z,0,2pi,50,operator ..)&cycle;
pen[] pens=Rainbow(15);
pens.push(black);
for (int i=pens.length-2; i >= 0 ; --i)
pens.push(pens[i]);
path sec=subpath(Circle(0,1.5,2*pens.length),0,pens.length);
coloredpath colorsec=coloredpath(sec, pens,colortype=coloredNodes);
draw(tube(p,colorsec));
Mots-clefs : Graph (3D), palette, Shading (3D), tube