Problem with paths and filling

If you're having trouble using Context Free or don't understand the language, ask for help here.

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
etruscan
Posts: 5
Joined: Fri Apr 11, 2008 6:33 am

Problem with paths and filling

Post by etruscan »

Hi,

I'm trying to make a filled shape using paths - a kind of elephant's trunk shape. I'm tracing it out using the following:

path trunk {
STROKE {width 0.01}
MOVETO {x 0 y -1}
ARCTO {x 0 y 0 r 0.7}
// CLOSEPOLY {}
MOVETO {x 0 y -0.8}
ARCTO{x 0 y -0.3 r 0.5}
MOVETO {x 0 y 0}
LINETO {x 0 y -0.3}
MOVETO {x 0 y -0.8}
LINETO {x 0 y -1}
// FILL {}
}

With FILL {} commented out, it renders the shape I want. If I un-comment FILL {}, I get a flat-sided shape which doesn't correspond to what I traced out - the left-hand side is flat. (Which is the same as un-commenting the CLOSEPOLY {} and commenting the subsequent commands out apart from FILL {}.)

What am I doing wrong? Presumably the software doesn't perceive the boundaries of the shape in the same way as I do. How, if at all, can I make it fill the shape?

Any help is much appreciated! :D

Thanks a lot,

Ben.

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Post by MtnViewJohn »

The STROKE command belongs after the path operation:

Code: Select all

path trunk { 
MOVETO {x 0 y -1} 
ARCTO {x 0 y 0 r 0.7} 
//	CLOSEPOLY {} 
MOVETO {x 0 y -0.8} 
ARCTO{x 0 y -0.3 r 0.5} 
MOVETO {x 0 y 0} 
LINETO {x 0 y -0.3} 
MOVETO {x 0 y -0.8} 
LINETO {x 0 y -1} 
STROKE {width 0.01} 
} 
It is possible to have your shape be a single, connected closed path with miter joins. But you have to make the smaller arc draw clock-wise instead of the default counter-clock-wise:

Code: Select all

path trunk {
MOVETO {x 0 y -1} 
ARCTO {x 0 y 0 r 0.7} 
LINETO {x 0 y -0.3}
ARCTO {x 0 y -0.8 r 0.5 p cw}
CLOSEPOLY{}
STROKE {width 0.01} 
} 

etruscan
Posts: 5
Joined: Fri Apr 11, 2008 6:33 am

Post by etruscan »

That's great - thanks very much! I didn't know about the option to draw clockwise. So it didn't work because I had multiple MOVETO operations which 'interrupted' the definition of a single closed path? If that's right, I think I understand now . . .

. . . thanks again :D

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Post by MtnViewJohn »

That's right. The only way to get joined path segments is to not have a MOVETO between them. The only way to join the beginning to the end is to have a CLOSEPOLY{} at the end.

Post Reply