Inline substitution of named transforms
Posted: Tue Mar 25, 2008 10:26 pm
Let's say you want to rotate arrows, birds, and lightning at random angles.
The current approach would be to duplicate the entire RandomRotate complex for each subject.
(repeat for birds and lightning)
Or the subjects can be bundled together under one virtual shape leaving the number of each to chance.Either way, RandomRotate cannot distinguish separate subjects.
The above pass transformations by inheritance, but there is another mechanism in CF allowing transformations to enter the system to begin with - the inline adjustments to the parent space before inheritance by the child.
My suggestion is that named rules could act as adjustments, returning their transformations inline, to perform the same job as adjustments using "{}" syntax.
RandomRotate1 can now act as a general purpose library function.
I can think of a few restrictions one might want to simplify implementation, but the most useful aspect could be accommodated fairly elegantly, I expect.
The current approach would be to duplicate the entire RandomRotate complex for each subject.
Code: Select all
rule RandomRotate1 { RandomRotate2 { } }
...
rule RandomRotate6 { RandomRotate7 { r 4 } }
rule RandomRotate7 { DrawArrow { } }
rule DrawRandomArrows { 30*{ b -0.05 z 1 } RandomRotate1 { } }
Or the subjects can be bundled together under one virtual shape leaving the number of each to chance.
Code: Select all
rule RandomRotate1 { RandomRotate2 { } }
...
rule RandomRotate6 { RandomRotate7 { r 4 } }
rule RandomRotate7 { DrawThing { } }
rule DrawRandomThings { 90*{ b -0.05 z 1 } RandomRotate1 { } }
rule DrawThing{DrawArrow { } }
rule DrawThing{DrawBird { } }
rule DrawThing{DrawLightning { } }
The above pass transformations by inheritance, but there is another mechanism in CF allowing transformations to enter the system to begin with - the inline adjustments to the parent space before inheritance by the child.
My suggestion is that named rules could act as adjustments, returning their transformations inline, to perform the same job as adjustments using "{}" syntax.
Code: Select all
rule RandomRotate1 { RandomRotate2 { } }
...
rule RandomRotate6 { RandomRotate7 { r 4 } }
rule RandomRotate7 { RETURN { } }
rule DrawRandomArrows { 30*{ b -0.05 z 1 } DrawArrow RandomRotate1 }
rule DrawRandomBirds { 30*{ b -0.05 z 1 } DrawBird RandomRotate1 }
rule DrawRandomLightning { 30*{ b -0.05 z 1 } DrawLightning RandomRotate1 }
I can think of a few restrictions one might want to simplify implementation, but the most useful aspect could be accommodated fairly elegantly, I expect.