Page 1 of 1

random ranges, weighted random arrays, and local attributes

Posted: Sun Jul 10, 2005 5:35 am
by robo git
Instead of needing to write things like this:

Code: Select all

rule Fred { SomeRule { x 0.1 }}
rule Fred { SomeRule { x 0.2 }}
rule Fred { SomeRule { x 0.3 }}
...
rule Fred { SomeRule { x 0.9 }}
rule Fred { SomeRule { x 1.0 }}
I think it could make for some seriously funky configs in far less space (and more efficiently parsed) if it was, rather then individual objects, somethingn like:

Code: Select all

rule Fred2 { SomeRule { x [0.1 10 0.1] }}
For [a b c] where a is seed, b is quantity, and c is increment, so that [0.1 10 0.1] would give a random number from 0.1 to 1.0 with a step of 0.1 (So 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0)

Another, more flexible approach could be a weighted-array:

Code: Select all

rule Fred3{ SomeRule{ x {0.1 1, 0.2 2, 0.8 8, 0.9, 1.0} } }
This would work like the rule-weightings - indeed behind the scene this may reuse the same code as the rule weightings.

-------------------

"And now for something, completely different."

There has already been talk of passing variables to child objects, and this is something related: Local attribute manipulation

This is just a "grief you're lazy Trav" ease-of-development thing for quicker development of CFDG files. It's not entirely uncommon to see things like:

Code: Select all

SomeRule { x 15 }
SomeRule { x 30 }
SomeRule { x 45 }
...
SomeRule { x 165 }
SomeRule { x 180 }
when the CFDG developer is trying to keep things within a certain proportion, or a fixed-n number of objects need to be added (would be REALLY useful when using i_pix for writing actual text!) and so instead have something like this:

Code: Select all

x [ 15 ]
SomeRule{ /* x passed implicitly, = 15 */ }
x [ 15 ]
SomeRule{ /* x passed implicitly, = 30 */ }
x [ 15 ]
SomeRule{ /* x passed implicitly */ }
x [ 15 ]
SomeRule{ /* x passed implicitly */ }
x [ 15 ]
....
SomeRule{ /* x passed implicitly, = 165 */ }
x [ 15 ]
SomeRule{ /* x passed implicitly, = 180 */ }

//by now we've lost x, so reset to default by:
x []
This could work with x, y, r, b, s and any other - use the same maths model as you would use when passing to a sub-rule, based off a local copy of the parent object attributes that are being updated.

-------------------

I don't know how useful or not these ideas are to others or how complex they are to implement, but I thought I'd throw these into the fray anyway. :D

Cheers!
-Trav