2

The following macro draws a black circle only on the first invocation. The remaining three circles are unfilled. Where am I going wrong?

def big(expr z) = 
begingroup
save a;
path a;
a = fullcircle scaled 3mm;
fill a withcolor black;
draw a shifted z;
endgroup
enddef;

beginfig(1)

big(origin); %black circle drawn
big((1cm,0)); % unfilled circle
big((2.5cm,0)); % unfilled circle
big((3cm,0)); % unfilled circle

endfig;
end;

1 Answer 1

5

The first command

fill a withcolor black;

draws a filled circle centered at origin. The second command

draw a shifted z;

draws the circles shifted by z. What you want is to also shift the filled circle:

fill a shifted z withcolor black;
draw a shifted z;

or, more simply:

def big(expr z) = 
    begingroup
    save a; path a;
    a = fullcircle shifted z scaled 3mm;
    fill a withcolor black;
    draw a;
    endgroup
enddef;
3
  • Thanks. Its working now. But then why did this work for the first circle?
    – suresh
    Nov 11, 2011 at 7:03
  • 1
    @suresh Because the first circle has its center in the origin; your code fills each time that circle.
    – egreg
    Nov 11, 2011 at 8:02
  • @suresh: because the first circle is not being shifted at all (origin == (0,0)).
    – Aditya
    Nov 11, 2011 at 8:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .