Page 1 of 1

zig-zag lines and positioning

Posted: Tue Jan 13, 2009 6:51 am
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

Re: zig-zag lines and positioning

Posted: Tue Jan 13, 2009 8:03 am
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.

Posted: Tue Jan 13, 2009 7:16 pm
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

Posted: Tue Jan 13, 2009 9:57 pm
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.

Posted: Wed Jan 14, 2009 5:14 am
by RR
perfect, pakin. Thanks

Posted: Wed Jan 14, 2009 2:27 pm
by MtnViewJohn
And thank you pakin for adding all that information to that wiki page.