targeting x and y coordinates
Moderators: MtnViewJohn, chris, mtnviewmark
targeting x and y coordinates
Hi,
Is there a way to control in any iterative rule such that the shape does not go beyond a particular x or y coordinate? ... similar in a way that we target colors. In a way the control I am looking for is like a size directive but one that is applicable within an object not for the whole drawing?
Or another way of stating my need is to create a triangle and fill it with some random placed shapes ... all within the triangle limits.
Thanks for any suggestions,
RR
Is there a way to control in any iterative rule such that the shape does not go beyond a particular x or y coordinate? ... similar in a way that we target colors. In a way the control I am looking for is like a size directive but one that is applicable within an object not for the whole drawing?
Or another way of stating my need is to create a triangle and fill it with some random placed shapes ... all within the triangle limits.
Thanks for any suggestions,
RR
Targetting a shape
It is possible within the current code - you just need to scale shapes towards the edges and corners of the target shape. By default this approach creates the carpet-like textures seen in many designs in the gallery, but if you let the expansion terminate with some probability then instead of a texture you will get whatever shape you put in that rule. This creates a sort of space-filling fractal. I used a trick of this sort to get nice textured squares in the cubes of my crystals designs. Here are two examples:
and one using a different subdivision of the triangle:
FWIW you could include both of the above T rules, and maybe others, depending on the effect you want.
.. and of course if you want things to look a little more random, throw in some rules like
to jiggle things around a bit. I added such rules in my "infested" design in the gallery.
Code: Select all
startshape S
rule S{
SQUARE { z -999 s 2 b .9 }
10* {} T{ b 1 sat 1}
}
rule T{
CIRCLE { x .33333 y .33333 s 1 alpha -0.8}
T [x 1 y 1 s 0.5 x -1 y -1 h 0]
T [x -1 y 1 s 0.5 x 1 y -1 h 20]
T [x 1 y -1 s 0.5 x -1 y 1 h 40 ]
T [r 180 x -1 y -1 s 0.5 x 1 y 1 h 60]
}
rule T .9 {
SQUARE { x .33333 y .33333 r 45 s 0.7 }
}
Code: Select all
startshape S
rule S{
SQUARE { z -999 s 2 b .9 }
10*{} T{ b 1 sat 1}
}
rule T{
CIRCLE { x .33333 y .33333 s 1 alpha -0.8}
T [r 135 s 0.707 x -1 y -1 h -50]
T [r -135 s 0.707 x -1 y -1 h 50]
}
rule T {
SQUARE { x .33333 y .33333 r 45 s 0.7 }
}
.. and of course if you want things to look a little more random, throw in some rules like
Code: Select all
rule T{ T{s 0.9 x .1 y .1} }
thanks K.
Now I get it. Let me re-phrase it. In the rules that get called from the parent rule you are off-setting the x and y coordinates to ensure that it stays towards one corner. Right?
What I could not understand though is the
You seem to be offsetting it first by 1, 1 and then set back by -1,-1. I am a little baffled there.
But yes, with a little experimentation on this I may be able to get where i want.
Thanks,
RR
Now I get it. Let me re-phrase it. In the rules that get called from the parent rule you are off-setting the x and y coordinates to ensure that it stays towards one corner. Right?
What I could not understand though is the
Code: Select all
T [x 1 y 1 s 0.5 x -1 y -1 h 0]
But yes, with a little experimentation on this I may be able to get where i want.
Thanks,
RR
- MtnViewJohn
- Site Admin
- Posts: 882
- Joined: Fri May 06, 2005 2:26 pm
- Location: Mountain View, California
- Contact:
The -1, -1 offset occurs after the scale by 0.5. So the offset is scaled by 0.5 too. When the shape adjustments are in square brackets [] they are applied serially. When the shape adjustments are in curly brackets {} they are reordered so that offsets are done first, then rotations, then scales, then skews, and last flips.RR wrote:thanks K.
Now I get it. Let me re-phrase it. In the rules that get called from the parent rule you are off-setting the x and y coordinates to ensure that it stays towards one corner. Right?
What I could not understand though is theYou seem to be offsetting it first by 1, 1 and then set back by -1,-1. I am a little baffled there.Code: Select all
T [x 1 y 1 s 0.5 x -1 y -1 h 0]
But yes, with a little experimentation on this I may be able to get where i want.
Thanks,
RR
Thanks, J. I guess that saves the effort of calculation when you wish to move one unit when down-sizing.
Part of my query is related to curvature objects - like a vase. I would like to fill it with some design within the constraints of the boundary. I experimented by drawing a curved object (using path commands) and then calling a rule which draws using standard shapes. But I found that it just paints the whole curved object in the color set with no shape drawn.
I deduce that from a path you cannot call any rule or use any standard shape. If so, is there a way out for my vase-problem?
thanks,
RR
p.s please bear I am new to CFDG but very excited
Part of my query is related to curvature objects - like a vase. I would like to fill it with some design within the constraints of the boundary. I experimented by drawing a curved object (using path commands) and then calling a rule which draws using standard shapes. But I found that it just paints the whole curved object in the color set with no shape drawn.
I deduce that from a path you cannot call any rule or use any standard shape. If so, is there a way out for my vase-problem?
thanks,
RR
p.s please bear I am new to CFDG but very excited
- MtnViewJohn
- Site Admin
- Posts: 882
- Joined: Fri May 06, 2005 2:26 pm
- Location: Mountain View, California
- Contact:
I think that the only way to fill a complex shape with a design is through careful placement of the design elements. You could use z order to cause parts of the design that fall outside of your vase to be covered up by other shapes. There is no clipping function in Context Free to force shapes to only be drawn within some boundary.
Yes, paths cannot call rules or other paths. Although it might be nice for paths to be able to call sub-paths, where sub-paths are like paths but do not contain STROKE or FILL commands.
Yes, paths cannot call rules or other paths. Although it might be nice for paths to be able to call sub-paths, where sub-paths are like paths but do not contain STROKE or FILL commands.
reason for double offset
Yes, the reason I used
was so that I easily read that this implements a 0.5 scaling towards (1,1), and that I can easily change the scaling factor (on the original or a duplicated version of the rule) without having to adjust both the scaling factor and the (x,y) offsets. Also once you have seen something like this, it is easier to read at a glance what it does. If we had macro language (preprocessor or interpreter) then some of this would be easier, but the variables/constants/parameterised rules that are on various wishlists will make this easier to do, and read.
The approach used in the triangle will work for any convex polygon, but you may need to adjust scaling factors, probabilities to get something that gives you the right coverage without taking millennia to draw.
As for filling more complicated shapes, John's suggestion is what I would use, with a bit of trial and error. Circular parts you can handle by something like and you can get other curves from an almost-straight spiral of diminishing blobs of some random variety - something like
Have fun.
- AK
Code: Select all
T [x 1 y 1 s 0.5 x -1 y -1 h 0]
The approach used in the triangle will work for any convex polygon, but you may need to adjust scaling factors, probabilities to get something that gives you the right coverage without taking millennia to draw.
As for filling more complicated shapes, John's suggestion is what I would use, with a bit of trial and error. Circular parts you can handle by something like
Code: Select all
90 * {r 4} SOMERULE{}
Code: Select all
rule A { X{} A{ r 1 s 0.9 } }
- AK