# How to fill color between curves in Asymptote

\documentclass[border=5pt]{standalone}
\usepackage{asymptote}

\begin{document}

\begin{asy}
size(5cm);
draw((0,0){up}--{right}(3,3){down}--{left}(1,1){right}--{up}(2,2){left}--{down}(0,0));
draw((0,0){up}..{right}(2,2){left}..{down}(1,1){right}..{up}(3,3){down}..{left}(0,0));
\end{asy}

\end{document}


It produces the following figure:

I want it to produce a figure like this:

P/s: I am a new Asymptote user ...

Use filldraw and the path must be a closed one, so you need to add ..cycle and provide a color as rgb(254,248,128). Note also that the varwidth option which suppresses the extra added width is used to have a symmetric standalone pdf.

\documentclass[border=5pt,varwidth]{standalone}
\usepackage{asymptote}

\begin{document}

\begin{asy}
size(0,150);
defaultpen(linewidth(1pt));
filldraw((0,0){up}..{right}(3,3){down}..{left}(1,1){right}..{up}(2,2){left}..{down}(0,0)..cycle,rgb(254,248,128));
filldraw((0,0){up}..{right}(2,2){left}..{down}(1,1){right}..{up}(3,3){down}..{left}(0,0)..cycle,rgb(128,127,255));
\end{asy}

\end{document}


Update

To add a grid, use add(grid(x,y)); after including import geometry;. You can change linetype, color, width, etc. of the grid. Here is an example:

\begin{asy}
import geometry;
size(0,150);
defaultpen(linewidth(1pt));
filldraw((0,0){up}..{right}(3,3){down}..{left}(1,1){right}..{up}(2,2){left}..{down}(0,0)..cycle,rgb(254,248,128)+opacity(.8));
filldraw((0,0){up}..{right}(2,2){left}..{down}(1,1){right}..{up}(3,3){down}..{left}(0,0)..cycle,rgb(128,127,255)+opacity(.8));
\end{asy}


• Can you use standalone environment for it ? – user173875 Dec 15 '18 at 14:50
• Sure, I edited my answer. – AboAmmar Dec 15 '18 at 14:56
• But, when I load it, there is extra white space on the left. How to fix it? – user173875 Dec 15 '18 at 14:59
• See edited my question ... – user173875 Dec 15 '18 at 15:00
• O.K., you need to provide the option varwidth to remedy this, see my edited answer. – AboAmmar Dec 15 '18 at 15:44

There is no need for varwidth etc. if you use asypictureB, which comes with a couple of other advantages. Most notably, you can smuggle TeX macros in the asymptote code. (Compile e.g. with pdflatex -shell-escape The filldraw command is very nicely explained in the tutorial by Charles Staats, the author of asypictureB.

\documentclass[border=3.14mm]{standalone}
\usepackage{asypictureB}

\begin{document}
\begin{asypicture}{name=fill}
size(0,150);
defaultpen(linewidth(1pt));
filldraw((0,0){up}..{right}(3,3){down}..{left}(1,1){right}..{up}(2,2){left}..{down}(0,0)..cycle,rgb(254,248,128));
filldraw((0,0){up}..{right}(2,2){left}..{down}(1,1){right}..{up}(3,3){down}..{left}(0,0)..cycle,rgb(128,127,255));
\end{asypicture}
\end{document}


• @ArtificialStupidity No. – user121799 Dec 17 '18 at 11:14
• @ArtificialStupidity When you compile it with pdflatex -shell-escape, asy will be automatically called, so you do not have to do it yourself. Smuggling in TeX macros refers to how, for example, I got the beak angle into the asy code in this animation. – user121799 Dec 17 '18 at 11:33