import graph;
unitsize(1.5cm);
real dt = 0.04;
int n = 0;
void ship() {
write(n);
shipout(outprefix() + format("-%04d", n));
++n;
}
pen fix = rgb(0.3, 0, 0.7)+linewidth(2);
pen trans = rgb(0.7, 0, 0.3)+linewidth(2);
string pilabel(real x) {
int n = floor(2*x/pi+0.5);
if(n % 2 == 0) {
return "$"+(n!=2 ? format("%d", n#2) : "")+"\pi$";
} else {
return "$\frac{"+(n!=1 ? format("%d", n) : "")+"\pi}2$";
}
}
xaxis(Label("$x$", EndPoint, 2*E), 0, 5*pi+0.4, LeftTicks(pilabel, n=3, Step=pi/2, NoZero), EndArrow);
yaxis(Label("$y$", EndPoint, 2*N), -1.4, 1.4, LeftTicks(n=2, Step=1), EndArrow);
path cl = box(truepoint(SW), truepoint(NE));
draw(cl, invisible);
draw(graph(cos, 0, 2*pi), fix);
clip(cl);
for(real t = 0; t+dt/2 < 1; t += dt) {
ship();
}
for(real t = 0; t+dt/2 < 2; t += dt) {
save();
draw(shift(t*pi, 0)*graph(cos, 0, 2*pi), trans);
clip(cl);
ship();
restore();
}
save();
draw(graph(cos, 2*pi, 4*pi), fix);
clip(cl);
for(real t = 0; t+dt/2 < 2; t += dt) {
save();
draw(shift(t*pi, 0)*graph(cos, 2*pi, 4*pi), trans);
clip(cl);
ship();
restore();
}
save();
draw(graph(cos, 4*pi, 6*pi), fix);
clip(cl);
for(real t = 0; t+dt/2 < 2; t += dt) {
save();
draw(shift(t*pi, 0)*graph(cos, 4*pi, 6*pi), trans);
clip(cl);
ship();
restore();
}
for(real t = 0; t+dt/2 < 1; t += dt) {
ship();
}
for(real t = 0; t+dt/2 < 2; t += dt) {
save();
draw(shift(-t*pi, 0)*graph(cos, 6*pi, 8*pi), trans);
clip(cl);
ship();
restore();
}
restore();
for(real t = 0; t+dt/2 < 2; t += dt) {
save();
draw(shift(-t*pi, 0)*graph(cos, 4*pi, 6*pi), trans);
clip(cl);
ship();
restore();
}
restore();
for(real t = 0; t+dt/2 < 2; t += dt) {
save();
draw(shift(-t*pi, 0)*graph(cos, 2*pi, 4*pi), trans);
clip(cl);
ship();
restore();
}