Page 1 of 2

color and randomness

Posted: Thu Nov 17, 2005 3:24 pm
by mr wong
I am trying to create flower-like office building floor plans. It works out quite nice so far, but every time I am using colors, no matter if it is a colored circle or a colored background it does not work properly anymore. Why? What am I missing?


Try yourself and uncomment the lines below:




startshape wormhouse
//background { hue 99 sat .1 b 0.9}

rule wormhouse {
draw {}
}

rule draw{
//CIRCLE {x -29.6 y 2 size 74 b 1}
do_circle7{}
//CIRCLE {x -29.6 y 2 size 46 hue 99 sat .25 b 1}
draw{y 53 flip 237}
}

rule draw{
//CIRCLE {x -17.9 y 2 size 50 b 1}
do_circle12{ }
//CIRCLE {x -17.9 y 2 size 22 hue 99 sat .25 b 1}
draw{x 34 y -40 flip 32}
}

rule draw{
//CIRCLE {x -23.7 y 2 size 62 b 1}
do_circle9{}
//CIRCLE {x -23.7 y 2 size 34 hue 99 sat .25 b 1}
draw{y 40 flip 90}
}

rule draw 0.4 {end {}}


rule do_circle12 {
room{}
do_circle12 {size 1 y 3.75 rotate 12}
}
rule do_circle12 0.003 {end{}}

rule do_circle9 {
room{}
do_circle9 {size 1 y 3.75 rotate 9}
}
rule do_circle9 0.006 {end{}}

rule do_circle7 {
room{}
do_circle7 {size 1 y 3.75 rotate 7.2}
}
rule do_circle7 0.003 {end{}}

rule room {
SQUARE{s 0.05 3.75 x 1}
SQUARE{s 6 0.05 y 1.875 x 4}
SQUARE{s 0.2 3.75 x 7}
SQUARE{s 6 0.05 y -1.875 x 4}
SQUARE{s 0.05 3.75 x -1}
SQUARE{s 6 0.05 y 1.875 x -4}
SQUARE{s 0.2 3.75 x -7}
SQUARE{s 6 0.05 y -1.875 x -4}
}

rule end {}

Posted: Fri Nov 18, 2005 12:22 am
by MtnViewJohn
It looks fine to me. I don't see what the problem is.

the problem is

Posted: Fri Nov 18, 2005 1:42 am
by mr wong
the problem is, that on my mac (osX10.3, context free 1.2) if I unquote any of the color statements, the randomness seems to change.

In effect the rule room{} gets called much much less then before. That is the problem. Strange, uh?

Posted: Sat Nov 19, 2005 7:53 am
by MtnViewJohn
Context Free does not use a traditional pseudo-random number generator, one which generates a fixed series of pseudo-random numbers. We used to use one of these but what we saw happening is that people would decide that they like a particular variation of their design and want to render a high resolution version of it. With a standard PRNG, changing the resolution would radically change the image.

Instead, Context Free uses something that you could call a pseudo-random number tree function, which generates random numbers based on the shape tree and details from the cfdg file. This function tends to generate the same image when you change the resolution, but any change to the cfdg file will change the image. So when you insert those CIRCLEs you changes the random number tree. The only way to prevent this is to add shapes to the end of your rules. For some rules this does not produce the desired effect, but for your design it works fine:

Code: Select all

startshape wormhouse
background { hue 99 sat .1 b 0.9}

rule wormhouse {
draw {}
}

rule draw{
do_circle7{}
draw{y 53 flip 237}
CIRCLE {x -29.6 y 2 size 74 b 1}
CIRCLE {x -29.6 y 2 size 46 hue 99 sat .25 b 1}
}

rule draw{
do_circle12{ }
draw{x 34 y -40 flip 32}
CIRCLE {x -17.9 y 2 size 50 b 1}
CIRCLE {x -17.9 y 2 size 22 hue 99 sat .25 b 1}
}

rule draw{
do_circle9{}
draw{y 40 flip 90}
CIRCLE {x -23.7 y 2 size 62 b 1}
CIRCLE {x -23.7 y 2 size 34 hue 99 sat .25 b 1}
}

rule draw 0.4 {end {}}


rule do_circle12 {
room{}
do_circle12 {size 1 y 3.75 rotate 12}
}
rule do_circle12 0.003 {end{}}

rule do_circle9 {
room{}
do_circle9 {size 1 y 3.75 rotate 9}
}
rule do_circle9 0.006 {end{}}

rule do_circle7 {
room{}
do_circle7 {size 1 y 3.75 rotate 7.2}
}
rule do_circle7 0.003 {end{}}

rule room {
SQUARE{s 0.05 3.75 x 1}
SQUARE{s 6 0.05 y 1.875 x 4}
SQUARE{s 0.2 3.75 x 7}
SQUARE{s 6 0.05 y -1.875 x 4}
SQUARE{s 0.05 3.75 x -1}
SQUARE{s 6 0.05 y 1.875 x -4}
SQUARE{s 0.2 3.75 x -7}
SQUARE{s 6 0.05 y -1.875 x -4}
}

rule end {}

please let me rephrase my question:

Posted: Sat Nov 19, 2005 12:45 pm
by mr wong
Thanks for the explanation. Please let me rephrase my orignal question:

The results of the DO_CIRCLE rule vary greatly dependend on wether I have a color command in my program or not. The difference is so serious that I thought it to be really strange. I´d love to post two imagees but I can´t link to them because I don´t have a webpage.

Let me therefore try to describe two images to you, one with color, one from the code without any color commands:

On the black and white image you would see a full circle of rooms - the ROOM rule is called very often.

On the colored image you would see that the ROOM rule is called only a few times so that only 3 to maybe 10 rooms are drawn every time the DO_CIRCLE rule is called.

Nothing else in the program has been changed. Only the color commands were activated. This difference occurs with every random starting number as far as I could see.

Do you have an idea weather this is a special problem with my software / hardware configuration, a bug or something else?

Posted: Sat Nov 19, 2005 12:59 pm
by mr wong
I should add that I think the difference between the two versions of the program to be too big to be only a variation in the random number generator for the two reasons:

1. it occurs with every three digit random starting number
2. the DO_CIRCLE rule is ended in both versions with the same specified weightning of 0.006 so it should look similar

Posted: Sat Nov 19, 2005 4:08 pm
by MtnViewJohn
I have tried your non-color version of wormhouse and my color version of workhouse on both a Windows machine and a Mac and both versions look identical. I do not see a difference between how many rooms do_circle generates between the color and non-color versions. I do see a big difference when the comments are removed from the your non-color version, but that is to be expected.

???

Posted: Sat Nov 19, 2005 5:13 pm
by mr wong
There is a difference i swear, i borrowed some webspace, here are the two images:


Image

Image

Don´t know what to say. Thanks for your time anyway.

Posted: Sat Nov 19, 2005 11:20 pm
by Guest
Wow, that's a huge difference. Are you certain that the color version is the one that I posted and that the same variation code is being used for both the color and non-color images?

yes.

Posted: Sun Nov 20, 2005 5:45 am
by mr wong
yes, i double checked. Btw: I could see no difference in the color version you posted and in my old color version. I have the same problem with both of them. Here is another one, quite similar, very few rooms in the color version. Variaton code is: QSB.

Image
Image

btw

Posted: Sun Nov 20, 2005 5:48 am
by mr wong
btw: Why don´t the color circles overwrite the Rooms? It looks as if the rooms where drawn on top of the circles, which they should not because they have been drawn before :?: *confused*

Posted: Sun Nov 20, 2005 3:51 pm
by MtnViewJohn
When the draw rules are evaluated the do_circle and draw shapes are put back into the evaluate queue but the CIRCLE shapes are drawn immediately. Whenever a rule is evaluated the primitive shapes (SQUARE, CIRCLE, and TRIANGLE) are always drawn immediately and the other shapes are put into the evaluation queue and drawn later.

In general, you have no control over the order that shapes are drawn except that within a rule the primitive shapes are drawn right away, in the order that they appear, and the non-primitive shapes are drawn some time afterward and not necessarily in the order that they appear.

Posted: Mon Nov 21, 2005 8:40 pm
by momo
This one looks fine on linux too. there's no difference between the color and no-color version.

Posted: Tue Nov 22, 2005 9:54 am
by mr wong
then it is a powerbook phenomenon? something with the graphic card maybe?

Posted: Tue Nov 22, 2005 9:05 pm
by MtnViewJohn
Btw: I could see no difference in the color version you posted and in my old color version.

Look more closely. I didn't just uncomment the CIRCLEs in your draw rules, I also moved them to the end of the rule. If you insert the CIRCLEs in the middle of the rule then it changes the pseudo-random number sequence used by the shapes that follow it in the rule. Putting the CIRCLEs at the end of the rule causes the color and non-color versions to have the same pseudo-random number sequence.