Change of position/debugging

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

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
Matthias12345
Posts: 1
Joined: Fri Nov 27, 2009 11:32 am

Change of position/debugging

Post by Matthias12345 »

Hello everyone,
I just started experimenting with ContextFreeArt and so my practicing designs are nothing special yet.
I wanted to create a meadow of flowers.
I have problems understanding the way the movement works though. I move around in my START rule, but is there a way, I can move in one of those child rules resulting in a change of position in the START rule?
For example, once the program has completed a flower, I want the position to be moved to the right, so the flowers don't overlap. How can that be done?
Most of the changes I make are just trial and error. It would be perfect if I could slowly move through the program, so I learn to understand which command does what. Is there a way to do that?
Not part of this program, but is there a way to interact between the background and the thing being printed on it? Like, can I have the object react to the background, for example blue background plus yellow object results in green object?
Oh, of course like everybody I would love more randomness.
And then, what about variables?
Matthias
Blumenwiese.png
Blumenwiese.png (24.04 KiB) Viewed 9612 times

Code: Select all

startshape START 
rule START {
10 * {x 6}	 WALK {x 4}
}
 
rule WALK 1 { CIRCLE {} WALK { x 3  y 1} }
rule WALK 1 { SQUARE {} WALK { x 3 y -1} }
rule WALK 0.3 { BLUME{ x 3} }

//flower
rule BLUME {
5 * {y 1} SQUARE {x  0 y 1 h 120 sat 1 b 1}
STENGEL {y 5}
}

// stem
rule STENGEL 1{
SQUARE {x 0 y 1 h 120 sat 1 b 1}
STENGEL {x 0 y 1  }
}
rule STENGEL 0.2 {
BLAETTER {}
3 * {y 1 } SQUARE {x 0 y 1 h 120 sat 1 b 1}
STENGEL {x 0 y 1  }
}
rule STENGEL 0.1 {
BLUETE {}
}

//leaves left and right
rule BLAETTER 0.5 {
BLATT {r 60  h 120 sat 1 b 1 z 1}
}
rule BLAETTER 0.5 {
BLATT {r -60  h 120 sat 1 b 1 z 1}
}

//blossoms
rule BLUETE {
CIRCLE {s 2 h  rand_static (180,420) sat 1 b 1 z 3}
6* {r 60} { BLATT { h rand_static (180,420) sat 1 b 1  z 2}}
}
rule BLUETE {
CIRCLE {s 2 h  rand_static (180,420) sat 1 b 1 z 3}
6* {r 60} { BLATT { h rand_static (180,420) sat 1 b 1  z 2}}
}

path BLATT {
MOVETO{}
CURVEREL{x 0 y 4  x1 2  y1 2}
CURVEREL{x 0 y -4  x1 -2 y1 -2}
//STROKE{ width 0.3}
FILL {}
}

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

Re: Change of position/debugging

Post by MtnViewJohn »

Variables and more randomness are coming in the next version. I actually have them working in my development build.

But, no the child rule cannot affect the parent rule in any way. That is what context-free grammars are all about. Context Free grammars are not little programs. The WALK rule does not execute 10 times while the START rule is executing. Instead, ten copies of the WALK rule are queued up to execute some time after the START rule finishes executing. Since START completes before WALK ever starts the WALK rules cannot affect the START rule.

There is no debugger for single-stepping Context Free grammars because they are not program-like. There is an execution engine that executes one rule at a time and a pool of shapes-to-be-executed. Executing a rule generates some number of primitives (SQUARE, CIRCLE, paths, etc), that are drawn immediately on the canvas bitmap; and non-primitive shapes, that are tossed into the shape pool. That said, I have been thinking of having a BREAKPOINT shape so that you can step through a particular rule.

As for your meadow flowers. The way people typically solve the overlapping problem is for your START rule to invoke WALK only once and have your BLUME rule invoke WALK at a non-overlapping position. This leads to an infinite loop which you break by having an empty WALK rule:

Code: Select all

WALK 0.01 {}
The downside of this technique is that you have to control over how many flowers are drawn before the loop terminates in the empty WALK rule.

Post Reply