rule randomization dependent on grammar source ?

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

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
stelf
Posts: 4
Joined: Sun Oct 17, 2010 2:37 am

rule randomization dependent on grammar source ?

Post by stelf »

Hi,

background: I'm using the Ubuntu CFDG build with some scripting stuff of mine.

What I'm essentially try to get is to produce a series of images that animate parameters of some rules in a CFDG. As long as there are no non-deterministic rules (i.e. rules with the same name) everything goes okay - i get the same image.

But even when non-deterministic rules are present I get different image even with the same random seed. I've expected that providing the same random seed will kind-of 'force' the random generator to pick the same rules. The parameters that i'm trying to animate are rotation and size, but it seems that even trying to animate color will result in different rules picked.

Is this a design decision? I was not expecting that changing the color has anything to do with size/rotation etc. of the image and generally - with the selection of same-named rules.

Any clue ? Would appreciate any feedback.

best.

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

Re: rule randomization dependent on grammar source ?

Post by MtnViewJohn »

Yes, the random number seed is salted with an "entropy" value that is derived from the text of the cfdg file. Any change to the cfdg file will change the variations, even meaningless changes like changing '0.5' to '.5'. Adding or removing white space has no effect, so you can reformat the cfdg file as you wish.

Why do we do this? Context Free does not use a single, global random number generator. Instead each instance of a shape has its own random number seed. We use the venerable, but not so great, 48-bit linear congruent generator. Each shape instance passes a tweaked version of its seed to its child shape instances. This is all done so that you can render a given variation at a different resolution and get the same image, only with more detail.

Say you wanted to make a poster of a cfdg file. You would need a 10,000 x 10,000 pixel image. But when you are scanning for a good variation you want to render at, say, 500 x 500. With a global random number generator changing the resolution would completely change the variation. With local random number generators the variation looks about the same at all resolutions.

The 48-bit random number seed is salted with "entropy" because otherwise it doesn't work very well. The variations are all boring. We can't use a better random number generator because they all use lots of memory for state and we would need each shape instance to store its own state. And there can be millions of shapes. So we use the barely adequate 48-bit LCG algorithm and tweak it to keep it interesting.

Now in the next version of Context Free there will be global and local variables and you can change their value without affecting the "entropy". The entropy will be derived from the variable's name, not its value. There will be ways to animate designs using changing variables.

stelf
Posts: 4
Joined: Sun Oct 17, 2010 2:37 am

Re: rule randomization dependent on grammar source ?

Post by stelf »

I'm speculating with the possibilities of having some CFDG parameters animated in sequence of frames that would form a movie. I've successfully animated non-deterministic CFDGs, since there's no random. But it would be way more appealing if i can animate say the rotation or hue of self-similar images and non-deterministic grammars. Trouble is there's no CFDG parameter forcing random seed to be only the '-m' parameter.

Here's the script I'm trying to use to produce the series (this one uses Guigui's "Soft Simmer" CFDG) :

Code: Select all

use strict;

my $asd = <<XXXX

startshape D
background{b -1}
 
rule D  {
    D{s .42}S{z 30}
}
rule S {
    CIR{}
    6*{r 60 sat .12 hue 3  }{CIR[s.42 y .6 z 1 s 1 b .5]S[s.39
y .69 sat .2 b .3 z 1]}
}
rule S {
    CIR{}
    5*{r 72 sat .12 hue 3 }{CIR[s.42 y .6 z 1 s 1 b .5]S[s.39
y .69 sat .2 b .3 z 1]}
}
rule S {
    CIR{}
    4*{r 90 sat .12 hue 3 }{CIR[s.42 y .6 z 1 s 1 b .5]S[s.39
y .69 sat .2 b .3 z 1]}
}
rule S {
    CIR{}
    3*{r 120 sat .12 hue 3 }{CIR[s.42 y .6 z 1 s 1 b
.5]S[s.39 y .69 sat .2 b .3 z 1 r __LARO__ ]}
}
rule S {
    CIR{}
    2*{r 180 sat .12 hue 3 }{CIR[s.42 y .6 z 1 s 1 b
.5]S[s.39 y .69 sat .2 b .3 z 1 r __LARO__  ]}
}
 
rule CIR {CIRCLE{}}

XXXX
;


my $i = 0.2;
my $j = 0;

for ($i = 1; $i < 180 ; $i += 0.5 ) {
  my $x;
  $j++;
  $x = $asd;
  $x =~ s/__LARO__/$i/egx;
  
  open (OFILE, '>cur.cfdg');
  print OFILE $x;
  close (OFILE);

  my $jj = $j;
  $jj = '0'.$jj if $jj < 100;
  $jj = '0'.$jj if $jj < 10;

  system("cfdg","cur.cfdg","output$jj.png","-v FLOW","-m 32768" );  
} 

Post Reply