discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: [OpenSCAD] children() and extra unwanted evaluations

N
Neon22
Sun, Mar 6, 2016 5:30 AM

I can't work out how to do it.
I can premake a list of random numbers. E.g.

// sequence of float rands for when symmetry required
rand_seq_length = 300;  // make longer if run out.
seeds = rands(0, 65535, rand_seq_length, master_seed);

but inside a random function I want to either step through using an index,
or consume the list by popping (for example).

but I can't work out how to alter another variable inside a function as a
side effect.

E.g.
seed_idx = 0;
function randff() = seeds[seed_idx]; // but autoincrement seed_idx each time
this functon is called.
// or
function randff() = [ some list decomation trick that modifies seeds ];

I suspect I'm thinking about the problem incorrectly :(

--
View this message in context: http://forum.openscad.org/children-and-extra-unwanted-evaluations-tp16291p16298.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

I can't work out how to do it. I can premake a list of random numbers. E.g. // sequence of float rands for when symmetry required rand_seq_length = 300; // make longer if run out. seeds = rands(0, 65535, rand_seq_length, master_seed); but inside a random function I want to either step through using an index, or consume the list by popping (for example). but I can't work out how to alter another variable inside a function as a side effect. E.g. seed_idx = 0; function randff() = seeds[seed_idx]; // but autoincrement seed_idx each time this functon is called. // or function randff() = [ some list decomation trick that modifies seeds ]; I suspect I'm thinking about the problem incorrectly :( -- View this message in context: http://forum.openscad.org/children-and-extra-unwanted-evaluations-tp16291p16298.html Sent from the OpenSCAD mailing list archive at Nabble.com.
NH
nop head
Sun, Mar 6, 2016 10:02 AM

I am not sure what your problem is exactly but if you want a number of
random decisions that don't vary during a run why can't you simply have a
global variable for each one? I.e. if you have lots of modules like
randcyl(), have a global variable for each one?

On 6 March 2016 at 05:30, Neon22 mschafer@wireframe.biz wrote:

I can't work out how to do it.
I can premake a list of random numbers. E.g.

// sequence of float rands for when symmetry required
rand_seq_length = 300;  // make longer if run out.
seeds = rands(0, 65535, rand_seq_length, master_seed);

but inside a random function I want to either step through using an index,
or consume the list by popping (for example).

but I can't work out how to alter another variable inside a function as a
side effect.

E.g.
seed_idx = 0;
function randff() = seeds[seed_idx]; // but autoincrement seed_idx each
time
this functon is called.
// or
function randff() = [ some list decomation trick that modifies seeds ];

I suspect I'm thinking about the problem incorrectly :(

--
View this message in context:
http://forum.openscad.org/children-and-extra-unwanted-evaluations-tp16291p16298.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

I am not sure what your problem is exactly but if you want a number of random decisions that don't vary during a run why can't you simply have a global variable for each one? I.e. if you have lots of modules like randcyl(), have a global variable for each one? On 6 March 2016 at 05:30, Neon22 <mschafer@wireframe.biz> wrote: > I can't work out how to do it. > I can premake a list of random numbers. E.g. > > // sequence of float rands for when symmetry required > rand_seq_length = 300; // make longer if run out. > seeds = rands(0, 65535, rand_seq_length, master_seed); > > but inside a random function I want to either step through using an index, > or consume the list by popping (for example). > > but I can't work out how to alter another variable inside a function as a > side effect. > > E.g. > seed_idx = 0; > function randff() = seeds[seed_idx]; // but autoincrement seed_idx each > time > this functon is called. > // or > function randff() = [ some list decomation trick that modifies seeds ]; > > I suspect I'm thinking about the problem incorrectly :( > > > > -- > View this message in context: > http://forum.openscad.org/children-and-extra-unwanted-evaluations-tp16291p16298.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
N
Neon22
Sun, Mar 6, 2016 10:26 AM

excellent question but my simplified example was just that. here's a bit of
code as an example.

module cylinder_protrusions(length, r1, r2, nprotrusions, seed=Gseed,
excess=1.5)  {
if (verbose) {echo("cylinder_protusions");}
intersection() {
// cyl(length, r1 * excess, r2 * excess, true);
cylindrical_thing(length, r1 * excess, r2 * excess, seed);
//
union() {
for (i = [0:nprotrusions]) {
h = ((randn(80,seed) + 20) / 100.0) * length;
z = -((length - h) / 2.0) * (randn(100,seed) / 100.0);
x = min(r1, r2) * randf(0.2,seed);
angle = randf(360.0,seed);
translate([0, 0, z])
rotate([0, 0, angle])
cube(size=[x, max(r1, r2) * 3, h], center=true);
}
}
}
}

as you can see there are two integer random number requests and two floating
point ones.
There are hundreds of these so annotating every single one is going to be
hard.
I'll do it - but I'm looking for a simpler way.

The current seed based mech is almost working and that's in the code above.
It uses two rand functions like this for now:

function randn(n, myseed=false) = floor(rands(0,n,1, (myseed) ? myseed :
rands(0,65535,1)[0])[0]);
function randf(n, myseed=false) = rands(0,n*1000,1, (myseed) ? myseed :
rands(0,65535,1)[0])[0] / 1000.0;

I'd rather remove the seed argument and handle it all in the rand function
itself.
The approach I'm using here is no good if you like a model and do an F6 - it
makes a completely diff model.
So I want to use a master_seed approach and the user can change this to
generate a new sequence of rands for use in the model construction...

--
View this message in context: http://forum.openscad.org/children-and-extra-unwanted-evaluations-tp16291p16301.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

excellent question but my simplified example was just that. here's a bit of code as an example. module cylinder_protrusions(length, r1, r2, nprotrusions, seed=Gseed, excess=1.5) { if (verbose) {echo("cylinder_protusions");} intersection() { // cyl(length, r1 * excess, r2 * excess, true); cylindrical_thing(length, r1 * excess, r2 * excess, seed); // union() { for (i = [0:nprotrusions]) { h = ((randn(80,seed) + 20) / 100.0) * length; z = -((length - h) / 2.0) * (randn(100,seed) / 100.0); x = min(r1, r2) * randf(0.2,seed); angle = randf(360.0,seed); translate([0, 0, z]) rotate([0, 0, angle]) cube(size=[x, max(r1, r2) * 3, h], center=true); } } } } as you can see there are two integer random number requests and two floating point ones. There are hundreds of these so annotating every single one is going to be hard. I'll do it - but I'm looking for a simpler way. The current seed based mech is almost working and that's in the code above. It uses two rand functions like this for now: function randn(n, myseed=false) = floor(rands(0,n,1, (myseed) ? myseed : rands(0,65535,1)[0])[0]); function randf(n, myseed=false) = rands(0,n*1000,1, (myseed) ? myseed : rands(0,65535,1)[0])[0] / 1000.0; I'd rather remove the seed argument and handle it all in the rand function itself. The approach I'm using here is no good if you like a model and do an F6 - it makes a completely diff model. So I want to use a master_seed approach and the user can change this to generate a new sequence of rands for use in the model construction... -- View this message in context: http://forum.openscad.org/children-and-extra-unwanted-evaluations-tp16291p16301.html Sent from the OpenSCAD mailing list archive at Nabble.com.
NH
nop head
Sun, Mar 6, 2016 11:09 AM

Oddly this is an example where force Goldfeather makes F5 fail and turning
it off makes it work.

I have had it turned on for a long time now, I can't remember what didn't
work with it off.

On 6 March 2016 at 10:02, nop head nop.head@gmail.com wrote:

I am not sure what your problem is exactly but if you want a number of
random decisions that don't vary during a run why can't you simply have a
global variable for each one? I.e. if you have lots of modules like
randcyl(), have a global variable for each one?

On 6 March 2016 at 05:30, Neon22 mschafer@wireframe.biz wrote:

I can't work out how to do it.
I can premake a list of random numbers. E.g.

// sequence of float rands for when symmetry required
rand_seq_length = 300;  // make longer if run out.
seeds = rands(0, 65535, rand_seq_length, master_seed);

but inside a random function I want to either step through using an index,
or consume the list by popping (for example).

but I can't work out how to alter another variable inside a function as a
side effect.

E.g.
seed_idx = 0;
function randff() = seeds[seed_idx]; // but autoincrement seed_idx each
time
this functon is called.
// or
function randff() = [ some list decomation trick that modifies seeds ];

I suspect I'm thinking about the problem incorrectly :(

--
View this message in context:
http://forum.openscad.org/children-and-extra-unwanted-evaluations-tp16291p16298.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Oddly this is an example where force Goldfeather makes F5 fail and turning it off makes it work. I have had it turned on for a long time now, I can't remember what didn't work with it off. On 6 March 2016 at 10:02, nop head <nop.head@gmail.com> wrote: > I am not sure what your problem is exactly but if you want a number of > random decisions that don't vary during a run why can't you simply have a > global variable for each one? I.e. if you have lots of modules like > randcyl(), have a global variable for each one? > > > On 6 March 2016 at 05:30, Neon22 <mschafer@wireframe.biz> wrote: > >> I can't work out how to do it. >> I can premake a list of random numbers. E.g. >> >> // sequence of float rands for when symmetry required >> rand_seq_length = 300; // make longer if run out. >> seeds = rands(0, 65535, rand_seq_length, master_seed); >> >> but inside a random function I want to either step through using an index, >> or consume the list by popping (for example). >> >> but I can't work out how to alter another variable inside a function as a >> side effect. >> >> E.g. >> seed_idx = 0; >> function randff() = seeds[seed_idx]; // but autoincrement seed_idx each >> time >> this functon is called. >> // or >> function randff() = [ some list decomation trick that modifies seeds ]; >> >> I suspect I'm thinking about the problem incorrectly :( >> >> >> >> -- >> View this message in context: >> http://forum.openscad.org/children-and-extra-unwanted-evaluations-tp16291p16298.html >> Sent from the OpenSCAD mailing list archive at Nabble.com. >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> > >