Mirror like effect

Let the developers know what you think of the software and what can be done to either improve the CFDG language or the Context Free program.

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
momo
Posts: 53
Joined: Tue Jul 19, 2005 5:08 am

Mirror like effect

Post by momo »

At the moment seems not to be possible to have symmetric designs when using random rules.

Code: Select all

startshape SCENE

rule SCENE { 
	BRANCH { }
	BRANCH { flip 180 y -2 }
}

rule BRANCH {
	SQUARE { }
	BRANCH { y 1 s 0.99 r 2 }
}

rule BRANCH 0.5 { BRANCH { flip 90 }}
The first and the second BRANCH in SCENE won't look the same as different random values are being used for each one.

I thought it will be cool if we had a mirror like option that worked like the flip one but using the same random values we could have symmetric designs when using random rules.

I'm not sure if this will break the context free grammar or something but i'm sure we could get pretty cool designs with it.

Music2000
Posts: 26
Joined: Mon Oct 10, 2005 3:38 pm
Location: London

Post by Music2000 »

A mirror effect would be cool i think :)

robo git
Posts: 47
Joined: Sat Jul 09, 2005 11:36 pm
Location: looking for his marbles
Contact:

Post by robo git »

When I want mirroring, I use Photoshop ;)

<shrug>

shevegen
Posts: 57
Joined: Wed Jul 06, 2005 5:38 am

Post by shevegen »

Thats cool for you robo git, if you do have a strong opinion about something, maybe you could elaborate more so that others can see why its good to do it in photoshop, or why it is not
good if contextfree would have this feature. ;)


Would mirroring be bad, or would it destroy the context-free part?

I dont know yet, maybe it could be thought of a point far away from the centre of the image, with two symmetrical 2D lines coming to the viewer of an image, that would still be a context free approach to it (i think). Or imagine a butterfly, it looks kinda symmetrical too. Or... a circle or square! (Whee i went down to the base!)

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

Post by MtnViewJohn »

Photoshop won't do the trick if the two mirror halves overlap. The shape-order/shape-Z is lost by the time the shape is rendered to a bitmap. Photoshop won't know whether to composite the left pixel on top of the right or vise versa.

This could be done in a CF-pure manner if we defined a symmetry syntax for drawing a given shape multiple times with a given symmetry. The key would be give each shape the same random number seed so that they would end up exactly the same, other than the symmetry operation.

Code: Select all

rule mirrorFoo {
    2* SYMMETRIC {flip 90} foo {}
} 

rule rot4Foo {
    4* SYMMETRIC {r 90} foo {}
}

rule dihedral4Foo {
    4* SYMMETRIC {r 90} mirrorFoo {}
}
These three rules would draw two, four, and eight copies of shape foo with mirror symmetry, 4-fold rotation symmetry, and 4-fold dihedral symmetry respectively. If shape foo has random elements then the copies of shape foo will all be the same random version of shape foo.

The SYMMETRIC keyword is just a placeholder. I would have to think more about what would be the best syntax. This would not be a very difficult feature to implement.

robo git
Posts: 47
Joined: Sat Jul 09, 2005 11:36 pm
Location: looking for his marbles
Contact:

Post by robo git »

Re Photoshop: I usually render with transparent bkgnd, then layer it for a simple, yet effective look: Works fine with halves overlapping. I don't pretend to retain the z-order; I manually tweak the image for the look I want with masking, multiple layers, and a whole pile of mucking used to achieve apparent z-order overlap.

What you're saying about adding a symmetric (or similar) command: while being a cool look, doesn't that break the CF paradigm? I think it does, as you would need to track how things are mirrored - it becomes effected by the context of the parent object as normal, but then this causes one "child" object to be effected by other child objects (as well as a single axis would double the number of objects being handled, two axis' would quadruple, etc)

In fact, the only way that I can see this not breaking CF is if it was at the whole-image level as a rendering parameter (along with EG "Background" or the proposed "properties")

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

Post by MtnViewJohn »

You are right on both counts robo git: it does violate the CF paradigm and doing it at the whole-image level doesn't. We could add a 'symmetry' parameter like background parameter. When the shapes are streamed to the canvas the symmetry partners could be inserted. Or I could say that I am doing that and then implement the feature using the random number seed hack :wink:, which works and is easy to do.

Another way to do mirroring would be to output the design as an SVG file, which preserves the shape order in vector form. Then you can write a Python or Perl script to take each shape in the SVG file and add its symmetry partners. The modified SVG file can then be rendering as a PNG file and it will have the desired symmetry.

robo git
Posts: 47
Joined: Sat Jul 09, 2005 11:36 pm
Location: looking for his marbles
Contact:

Post by robo git »

....Random number seed hack? I'm missing something here...

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

Post by MtnViewJohn »

MtnViewJohn wrote:The key would be give each shape the same random number seed so that they would end up exactly the same, other than the symmetry operation...

The random number generator for Context Free is not your standard random number sequence generated from a global random number seed. It is tree-like, passed down from parent to child. This is what allows CFDG files to look roughly the same when you change the resolution.

Adjacent shape replacements in a shape rule always get different random numbers derived from the parent shape's random number. This is done to keep the child shapes from looking the same. But if you override this behavior and give the child shapes the same random number then they will look the same.

The point I was making is that the only way to do symmetry without breaking the CF paradigm is to use the CFDG grammar to generate a "sentence" of squares, circles, and triangles and then post-process the sentence to get the desired symmetry. But this post-processing is a pain in the butt and you can get the exact same result by tweaking the CFDG grammar up front to generate a sentence that has the desired symmetry.

This tweak in the random number hack that I mentioned earlier. Right now Context Free kicks of rendering a CFDG file by taking the shape named in the startshape directive, giving it the identity matrix for its affine transform and pushing it onto the render queue. This first shape has a random number that is derived from the variation code. The hackish way to do mirror symmetry is to put two copies of the startshape onto the render queue, one with the identity matrix and one with the reflection matrix, and both with the same random number.

robo git
Posts: 47
Joined: Sat Jul 09, 2005 11:36 pm
Location: looking for his marbles
Contact:

Post by robo git »

Ah yep, I think I understand where you're comming from now, cheers! (And if I've misunderstood, eh - too bad ;) )

raimondious
Posts: 12
Joined: Thu Apr 13, 2006 3:45 pm

Post by raimondious »

The key would be give each shape the same random number seed so that they would end up exactly the same, other than the symmetry operation...
That's clever!

GoldenBanana
Posts: 1
Joined: Sat Oct 07, 2006 3:50 am

Post by GoldenBanana »

Hey guys!
I was trying to do mirror like effect and this is result
-

startshape all

rule all {
part {r 1 s 0.99 }}

rule all {
part {r -1 s 0.99 }}

rule all {
part {r 2 s 0.99 }}

rule all {
part {r -2 s 0.99 }}

rule all {
part {r 3 s 0.99 }}

rule all {
part {r -3 s 0.99 }}


rule part {
CIRCLE { y 20 }
CIRCLE { y -20 }
all {}}

-
Im using context free for 5th day now and im pretty new and I dont know was that what you were trying to do.

GoldenBanana

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

Post by MtnViewJohn »

It is always possible to create mirror or inversion symmetric shapes, like your design. But what momo wanted was to be able to take any shape and mirror it. This violates the context-free paradigm unless you take the entire output of cfdg rendering engine and apply the symmetry operation to it.

Post Reply