zig-zag lines and positioning

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

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
RR
Posts: 10
Joined: Mon Jan 12, 2009 4:20 am

zig-zag lines and positioning

Post by RR »

Hi,

I have got hooked to CFA in the last two days and have been trying to get a hang of the way this works. To test my skills I was trying a zig-zag figure and got stumped.

Fundamentally, when shapes are drawn is there a concept of a current position? e.g. if I draw a set of squares that span across the width of the canvas and then draw a CIRCLE it draws it at the "original point" rather than at the point where the squares have ended.

I would appreciate if someone could clarify for me:

1. What is the starting point for any set of shapes?

2. Is there a way I can position when using standard shapes like SQUARE, CIRCLE, TRIANGLE?

My code (which does not work for zig-zag line is)

Code: Select all

startshape STRIPES

rule STRIPES {
	dash{}
	slash{r 181}
}

rule dash {
	100 * {x -1} SQUARE{}
}

rule backslash {
	100 * {x -1} SQUARE{hue 0 sat 1 b 1}
}

rule slash {
	100 * {x 1} SQUARE{hue 100 sat 1 b 1}
	backslash{ r 181}
}
Thanks,

RR

User avatar
pakin
Posts: 43
Joined: Sat Apr 21, 2007 8:59 pm
Location: United States
Contact:

Re: zig-zag lines and positioning

Post by pakin »

RR wrote:1. What is the starting point for any set of shapes?
The origin -- (0,0). Note, however, that if a rule is drawn shifted, the coordinate system changes so any rules or primitives that that rule invokes will have a different notion of where the origin lies.
RR wrote:2. Is there a way I can position when using standard shapes like SQUARE, CIRCLE, TRIANGLE?
Yes. Both primitives and the rules you define yourself can be positioned by placing x and y offsets within the curly braces that immediately follow them:

Code: Select all

CIRCLE { x 100 }

do_something_nifty { x 10 y 45 }
In the preceding example, if do_something_nifty draws a SQUARE { }, the square will appear at position (0,0) in do_something_nifty's coordinate system, which is position (10,45) in the caller's coordinate system.

RR
Posts: 10
Joined: Mon Jan 12, 2009 4:20 am

Post by RR »

Thanks Pakin.

Understanding further from what you have written. if do_something_nifty had two objects. One a square and a second a circle (say with an x-coordinate shift of 5), do you mean that the square would appear at position (0,0) and the circle at (5,0) of the new coordinate system which is (10,45)?

Let me try that out,

Tks,

RR

User avatar
pakin
Posts: 43
Joined: Sat Apr 21, 2007 8:59 pm
Location: United States
Contact:

Post by pakin »

RR wrote:Understanding further from what you have written. if do_something_nifty had two objects. One a square and a second a circle (say with an x-coordinate shift of 5), do you mean that the square would appear at position (0,0) and the circle at (5,0) of the new coordinate system which is (10,45)?
Yes, the shapes' centers will appear at those coordinates. See also the bottom of the Primitive Shapes page in the wiki for an illustration of the coordinates of other points on the primitive shapes.

RR
Posts: 10
Joined: Mon Jan 12, 2009 4:20 am

Post by RR »

perfect, pakin. Thanks

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

Post by MtnViewJohn »

And thank you pakin for adding all that information to that wiki page.

Post Reply