color and randomness
Moderators: MtnViewJohn, chris, mtnviewmark
color and randomness
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 {}
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 {}
- MtnViewJohn
- Site Admin
- Posts: 882
- Joined: Fri May 06, 2005 2:26 pm
- Location: Mountain View, California
- Contact:
the problem is
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?
In effect the rule room{} gets called much much less then before. That is the problem. Strange, uh?
- MtnViewJohn
- Site Admin
- Posts: 882
- Joined: Fri May 06, 2005 2:26 pm
- Location: Mountain View, California
- Contact:
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:
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:
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?
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?
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
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
- MtnViewJohn
- Site Admin
- Posts: 882
- Joined: Fri May 06, 2005 2:26 pm
- Location: Mountain View, California
- Contact:
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.
- MtnViewJohn
- Site Admin
- Posts: 882
- Joined: Fri May 06, 2005 2:26 pm
- Location: Mountain View, California
- Contact:
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.
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.
- MtnViewJohn
- Site Admin
- Posts: 882
- Joined: Fri May 06, 2005 2:26 pm
- Location: Mountain View, California
- Contact:
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.