Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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;
share|improve this question

1 Answer 1

up vote 4 down vote accepted

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;
share|improve this answer
    
Thanks. Its working now. But then why did this work for the first circle? –  suresh Nov 11 '11 at 7:03
    
@suresh Because the first circle has its center in the origin; your code fills each time that circle. –  egreg Nov 11 '11 at 8:02
    
@suresh: because the first circle is not being shifted at all (origin == (0,0)). –  Aditya Nov 11 '11 at 8:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.