discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

how to randomness different loops?

RW
Raymond West
Sun, Oct 16, 2022 5:20 PM

I generate a block of 'strands', each strand has a random factor applied
to its width. How can I create a duplicate of it such that the ends are
fixed, but the points in between are random. The example code the
strands do not  change for each iteration of block, which can lead to
repeating pattern when joined up. If I do not use a seed, then the ends
are different for each iteration, and will not align.

if you run one block, with len= 80, then that will show more or less
what I am trying to explain it should look like, apart from the
endpoints of the blocks in the tessellated version.

module strand(ysep,see){  // rand at 20

      ty=ysep+10+rands(-2,2,1,see)[0];
      by=ysep+rands(-2,2,1,see)[0];

         b=[0,ty];
          c=[for (j=[1:1:(len/2)-1]) [j*20,ysep+10+rands(-2,2,1)[0] ]];
           d= [(len/2)*20,ty];
            e=[(len/2)*20,by];
             f=[for
(j=[(len/2)+2:1:len])[(len-j+1)*20,ysep++rands(-2,2,1)[0]]];
              g=[0,by] ;
          p=concat([b],c,[d],[e],f,[g]);
       polygon(p);
           }

module block(){
  for (j=[0:1:ns-1])
        strand(sepj,j7);
}

ns=100; // number of strands
sep=18; // strand separation

len= 20;  // length of strand

block();
translate([200,0,0])block();
translate([400,0,0])block();
translate([600,0,0])block();

I generate a block of 'strands', each strand has a random factor applied to its width. How can I create a duplicate of it such that the ends are fixed, but the points in between are random. The example code the strands do not  change for each iteration of block, which can lead to repeating pattern when joined up. If I do not use a seed, then the ends are different for each iteration, and will not align. if you run one block, with len= 80, then that will show more or less what I am trying to explain it should look like, apart from the endpoints of the blocks in the tessellated version. module strand(ysep,see){  // rand at 20       ty=ysep+10+rands(-2,2,1,see)[0];       by=ysep+rands(-2,2,1,see)[0];          b=[0,ty];           c=[for (j=[1:1:(len/2)-1]) [j*20,ysep+10+rands(-2,2,1)[0] ]];            d= [(len/2)*20,ty];             e=[(len/2)*20,by];              f=[for (j=[(len/2)+2:1:len])[(len-j+1)*20,ysep++rands(-2,2,1)[0]]];               g=[0,by] ;           p=concat([b],c,[d],[e],f,[g]);        polygon(p);            } module block(){   for (j=[0:1:ns-1])         strand(sep*j,j*7); } ns=100; // number of strands sep=18; // strand separation len= 20;  // length of strand block(); translate([200,0,0])block(); translate([400,0,0])block(); translate([600,0,0])block();
JB
Jordan Brown
Mon, Oct 17, 2022 1:39 PM

I am not completely following what you are trying to do, but I think
what you are saying is that you want a random wavy line, and then you
want to attach a random wavy line onto the end of it, and another, and
so on, and you want the ends of those lines to connect.

The best answer would seem to be to generate the entire wavy line in one
operation, rather than in segments.

Failing that, it would depend on exactly how you're generating your
waviness.  So far, your problem is that your random end point isn't the
same as the random start point on the next one, right?

So, perhaps to point out the obvious, your start point for the next
segment can't be random.

One answer would be to do what model railroaders do when they want to
have individual people build modules for a layout, and want the modules
to interconnect https://www.nmra.org/introduction-layout-modules
have the interconnection points not be random at all.  Assuming that
your waviness is around a zero point, you could have all segments start
and end at the zero point.  But if you do an vertical array of these
strands, I suspect that would be a visible pattern.

Another approach would be to plan out the whole line in advance, so that
you know where the start/end points are before you start building
anything else.  But mostly that seems equivalent to generating the
entire line in one pass.

I am not completely following what you are trying to do, but I think what you are saying is that you want a random wavy line, and then you want to attach a random wavy line onto the end of it, and another, and so on, and you want the ends of those lines to connect. The best answer would seem to be to generate the entire wavy line in one operation, rather than in segments. Failing that, it would depend on exactly how you're generating your waviness.  So far, your problem is that your random end point isn't the same as the random start point on the next one, right? So, perhaps to point out the obvious, your start point for the next segment can't be random. One answer would be to do what model railroaders do when they want to have individual people build modules for a layout, and want the modules to interconnect <https://www.nmra.org/introduction-layout-modules>:  have the interconnection points not be random at all.  Assuming that your waviness is around a zero point, you could have all segments start and end at the zero point.  But if you do an vertical array of these strands, I suspect that would be a visible pattern. Another approach would be to plan out the whole line in advance, so that you know where the start/end points are before you start building anything else.  But mostly that seems equivalent to generating the entire line in one pass.
BL
Bryan Lee
Mon, Oct 17, 2022 5:09 PM

So if I'm understanding this correctly, you want the endpoints of strand_1
to be the start points of strand_2?

I'm pretty sure that in order to do this in OpenSCAD you will need to
generate those end points outside of your loop.

One way to do this is to generate an array of starting point rands in
"block()" or "main" and pass "start_point[j]" and "start_point[j+1]" into
strand() also.  These would be used by strand as it's start and end points.

You could also generate a list of rands in "main"
SEED=42284;
start_point_array=rands(-2,2,ns+1,SEED);

and just have block() also pass j into strand(),
so then each itteration of strand() uses that j to lookup it's own start
and end points.

Thus Raymond West hast written on Sun, Oct 16, 2022 at 06:20:26PM +0100, and, according to prophecy, it shall come to pass that:

I generate a block of 'strands', each strand has a random factor applied to
its width. How can I create a duplicate of it such that the ends are fixed,
but the points in between are random. The example code the strands do not 
change for each iteration of block, which can lead to repeating pattern when
joined up. If I do not use a seed, then the ends are different for each
iteration, and will not align.

if you run one block, with len= 80, then that will show more or less what I
am trying to explain it should look like, apart from the endpoints of the
blocks in the tessellated version.

module strand(ysep,see){  // rand at 20

      ty=ysep+10+rands(-2,2,1,see)[0];
      by=ysep+rands(-2,2,1,see)[0];

         b=[0,ty];
          c=[for (j=[1:1:(len/2)-1]) [j*20,ysep+10+rands(-2,2,1)[0] ]];
           d= [(len/2)*20,ty];
            e=[(len/2)*20,by];
             f=[for
(j=[(len/2)+2:1:len])[(len-j+1)*20,ysep++rands(-2,2,1)[0]]];
              g=[0,by] ;
          p=concat([b],c,[d],[e],f,[g]);
       polygon(p);
           }

module block(){
  for (j=[0:1:ns-1])
        strand(sepj,j7);
}

ns=100; // number of strands
sep=18; // strand separation

len= 20;  // length of strand

block();
translate([200,0,0])block();
translate([400,0,0])block();
translate([600,0,0])block();


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

So if I'm understanding this correctly, you want the endpoints of strand_1 to be the start points of strand_2? I'm pretty sure that in order to do this in OpenSCAD you will need to generate those end points outside of your loop. One way to do this is to generate an array of starting point rands in "block()" or "main" and pass "start_point[j]" and "start_point[j+1]" into strand() also. These would be used by strand as it's start and end points. You could also generate a list of rands in "main" SEED=42284; start_point_array=rands(-2,2,ns+1,SEED); and just have block() also pass j into strand(), so then each itteration of strand() uses that j to lookup it's own start and end points. Thus Raymond West hast written on Sun, Oct 16, 2022 at 06:20:26PM +0100, and, according to prophecy, it shall come to pass that: > I generate a block of 'strands', each strand has a random factor applied to > its width. How can I create a duplicate of it such that the ends are fixed, > but the points in between are random. The example code the strands do not  > change for each iteration of block, which can lead to repeating pattern when > joined up. If I do not use a seed, then the ends are different for each > iteration, and will not align. > > if you run one block, with len= 80, then that will show more or less what I > am trying to explain it should look like, apart from the endpoints of the > blocks in the tessellated version. > > > module strand(ysep,see){  // rand at 20 > >       ty=ysep+10+rands(-2,2,1,see)[0]; >       by=ysep+rands(-2,2,1,see)[0]; > >          b=[0,ty]; >           c=[for (j=[1:1:(len/2)-1]) [j*20,ysep+10+rands(-2,2,1)[0] ]]; >            d= [(len/2)*20,ty]; >             e=[(len/2)*20,by]; >              f=[for > (j=[(len/2)+2:1:len])[(len-j+1)*20,ysep++rands(-2,2,1)[0]]]; >               g=[0,by] ; >           p=concat([b],c,[d],[e],f,[g]); >        polygon(p); >            } > > module block(){ >   for (j=[0:1:ns-1]) >         strand(sep*j,j*7); > } > > ns=100; // number of strands > sep=18; // strand separation > > len= 20;  // length of strand > > block(); > translate([200,0,0])block(); > translate([400,0,0])block(); > translate([600,0,0])block(); > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
M
mikeonenine@web.de
Tue, Oct 18, 2022 2:27 AM

Methinks it should be possible to do occasional random droplets of dirty black, hot engine oil splashing against the viewport from behind and running down into a puddle at the bottom. Delicious!

(Sorry, but my formative years were before the anthropocene had been given a name.)

Methinks it should be possible to do occasional random droplets of dirty black, hot engine oil splashing against the viewport from behind and running down into a puddle at the bottom. Delicious! (Sorry, but my formative years were before the anthropocene had been given a name.)
GH
gene heskett
Tue, Oct 18, 2022 3:42 AM

On 10/17/22 22:29, mikeonenine@web.de wrote:

Methinks it should be possible to do occasional random droplets of dirty black, hot engine oil splashing against the viewport from behind and running down into a puddle at the bottom. Delicious!

(Sorry, but my formative years were before the anthropocene had been given a name.)

Mine were about that far back, I made it to 88 back on the 4th.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Cheers, Gene Heskett.

"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.

On 10/17/22 22:29, mikeonenine@web.de wrote: > Methinks it should be possible to do occasional random droplets of dirty black, hot engine oil splashing against the viewport from behind and running down into a puddle at the bottom. Delicious! > > (Sorry, but my formative years were before the anthropocene had been given a name.) Mine were about that far back, I made it to 88 back on the 4th. > > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org Cheers, Gene Heskett. -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author, 1940) If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis Genes Web page <http://geneslinuxbox.net:6309/>
M
mikeonenine@web.de
Tue, Oct 18, 2022 4:10 AM

gene heskett wrote:

Mine were about that far back, I made it to 88 back on the 4th.

Congrats! I’m only somewhere between 71 and 72 (not quite sure where). Hope I’ll be able to keep up with things like OpenSCAD when I’m 88!

gene heskett wrote: > > Mine were about that far back, I made it to 88 back on the 4th. Congrats! I’m only somewhere between 71 and 72 (not quite sure where). Hope I’ll be able to keep up with things like OpenSCAD when I’m 88!
HL
Hans L
Tue, Oct 18, 2022 5:44 AM

The trick to tile-able noise is to use a seed that incorporates a modulo.
To tile in one direction, something like:
rands(min,max,1, base_seed + mod(position, positions_until_repeat))

I have some sample code which creates a 2D tile-able noise (opposite edges
of heightmap match), in the following gist:
https://gist.github.com/thehans/35aa000d9a833c160a9f93bd3df25edf
(it also does bicubic interpolation between points, but that's another
topic ;) )

Hans

On Mon, Oct 17, 2022 at 11:11 PM mikeonenine@web.de wrote:

gene heskett wrote:

Mine were about that far back, I made it to 88 back on the 4th.

Congrats! I’m only somewhere between 71 and 72 (not quite sure where).
Hope I’ll be able to keep up with things like OpenSCAD when I’m 88!


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

The trick to tile-able noise is to use a seed that incorporates a modulo. To tile in one direction, something like: rands(min,max,1, base_seed + mod(position, positions_until_repeat)) I have some sample code which creates a 2D tile-able noise (opposite edges of heightmap match), in the following gist: https://gist.github.com/thehans/35aa000d9a833c160a9f93bd3df25edf (it also does bicubic interpolation between points, but that's another topic ;) ) Hans On Mon, Oct 17, 2022 at 11:11 PM <mikeonenine@web.de> wrote: > gene heskett wrote: > > Mine were about that far back, I made it to 88 back on the 4th. > > Congrats! I’m only somewhere between 71 and 72 (not quite sure where). > Hope I’ll be able to keep up with things like OpenSCAD when I’m 88! > > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
RW
Ray West
Tue, Oct 18, 2022 12:13 PM

Thanks for the replies, I'll try and show a bit more explanation. I've
extracted the relevant code from my  more complex overall solution
attempt, and I've attached it and a svg (the svg produced by the scad
code.)

Looking at the svg, the first block of strands have the end points set
equal, and when a number of blocks are created and joined, the fact that
the endpoints are equal is not apparent  The scad script generates that
image. However, I've a suspicion that for certain values of sep, and
range of rands, in the construction of the connected blocks, then the
repeated constant ends would be visible across the group of blocks. I'm
aiming at a general solution, not one that works for certain values.

If you comment out the fixed ty and by, and uncomment the first pair,
(in the strand module) then the blocks have the random end points, but
they do not persist for each block, and gives 'steps' when the blocks
are aligned.

I may be wrong, but it appears that once a seed is generated for random
numbers, it applies to every instant of rands.

If the length of strands is increased to 1000, say, then it shows what I
would like to achieve by joining ten blocks of length 100.

I could generate a list of rands for ty and by, and increment through
when the block is created, but having a choice of random seeds would be
nice.

I may be missing the obvious. While I'm in winge mode, it's an
irritation that importing an svg that has just been exported it arrives
in a different location.

Thanks for the replies, I'll try and show a bit more explanation. I've extracted the relevant code from my  more complex overall solution attempt, and I've attached it and a svg (the svg produced by the scad code.) Looking at the svg, the first block of strands have the end points set equal, and when a number of blocks are created and joined, the fact that the endpoints are equal is not apparent  The scad script generates that image. However, I've a suspicion that for certain values of sep, and range of rands, in the construction of the connected blocks, then the repeated constant ends would be visible across the group of blocks. I'm aiming at a general solution, not one that works for certain values. If you comment out the fixed ty and by, and uncomment the first pair, (in the strand module) then the blocks have the random end points, but they do not persist for each block, and gives 'steps' when the blocks are aligned. I may be wrong, but it appears that once a seed is generated for random numbers, it applies to every instant of rands. If the length of strands is increased to 1000, say, then it shows what I would like to achieve by joining ten blocks of length 100. I could generate a list of rands for ty and by, and increment through when the block is created, but having a choice of random seeds would be nice. I may be missing the obvious. While I'm in winge mode, it's an irritation that importing an svg that has just been exported it arrives in a different location.
J
jon
Tue, Oct 18, 2022 12:29 PM

Ray:

I did not read your code, but when you say the "end points set equal",
is the thickness the same, or are both the thickness and the angle the
same?  Are you seeing places where the two ends are in the same
location, but the trajectory of the two pieces are so different that the
joint is obvious?  Do you need to get the two end points to go at the
same angle?

Jon

On 10/18/2022 8:13 AM, Ray West wrote:

Thanks for the replies, I'll try and show a bit more explanation. I've
extracted the relevant code from my  more complex overall solution
attempt, and I've attached it and a svg (the svg produced by the scad
code.)

Looking at the svg, the first block of strands have the end points set
equal, and when a number of blocks are created and joined, the fact
that the endpoints are equal is not apparent  The scad script
generates that image. However, I've a suspicion that for certain
values of sep, and range of rands, in the construction of the
connected blocks, then the repeated constant ends would be visible
across the group of blocks. I'm aiming at a general solution, not one
that works for certain values.

If you comment out the fixed ty and by, and uncomment the first pair,
(in the strand module) then the blocks have the random end points, but
they do not persist for each block, and gives 'steps' when the blocks
are aligned.

I may be wrong, but it appears that once a seed is generated for
random numbers, it applies to every instant of rands.

If the length of strands is increased to 1000, say, then it shows what
I would like to achieve by joining ten blocks of length 100.

I could generate a list of rands for ty and by, and increment through
when the block is created, but having a choice of random seeds would
be nice.

I may be missing the obvious. While I'm in winge mode, it's an
irritation that importing an svg that has just been exported it
arrives in a different location.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Ray: I did not read your code, but when you say the "end points set equal", is the thickness the same, or are both the thickness and the angle the same?  Are you seeing places where the two ends are in the same location, but the trajectory of the two pieces are so different that the joint is obvious?  Do you need to get the two end points to go at the same angle? Jon On 10/18/2022 8:13 AM, Ray West wrote: > Thanks for the replies, I'll try and show a bit more explanation. I've > extracted the relevant code from my  more complex overall solution > attempt, and I've attached it and a svg (the svg produced by the scad > code.) > > Looking at the svg, the first block of strands have the end points set > equal, and when a number of blocks are created and joined, the fact > that the endpoints are equal is not apparent  The scad script > generates that image. However, I've a suspicion that for certain > values of sep, and range of rands, in the construction of the > connected blocks, then the repeated constant ends would be visible > across the group of blocks. I'm aiming at a general solution, not one > that works for certain values. > > If you comment out the fixed ty and by, and uncomment the first pair, > (in the strand module) then the blocks have the random end points, but > they do not persist for each block, and gives 'steps' when the blocks > are aligned. > > I may be wrong, but it appears that once a seed is generated for > random numbers, it applies to every instant of rands. > > If the length of strands is increased to 1000, say, then it shows what > I would like to achieve by joining ten blocks of length 100. > > I could generate a list of rands for ty and by, and increment through > when the block is created, but having a choice of random seeds would > be nice. > > I may be missing the obvious. While I'm in winge mode, it's an > irritation that importing an svg that has just been exported it > arrives in a different location. > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
RW
Raymond West
Tue, Oct 18, 2022 12:42 PM

Hi Jon,

The best way to understand what I am trying to explain, is probably to
run the code, and maybe zoom in, or alter the values. Exactly as it is,
I can not see any endpoint artefacts/vertical lines, etc., but I can
envisage that with different values, 'vertical lines/joins' would be
visible.

On 18/10/2022 13:29, jon wrote:

Ray:

I did not read your code, but when you say the "end points set equal",
is the thickness the same, or are both the thickness and the angle the
same?  Are you seeing places where the two ends are in the same
location, but the trajectory of the two pieces are so different that
the joint is obvious?  Do you need to get the two end points to go at
the same angle?

Jon

On 10/18/2022 8:13 AM, Ray West wrote:

Thanks for the replies, I'll try and show a bit more explanation.
I've extracted the relevant code from my  more complex overall
solution attempt, and I've attached it and a svg (the svg produced by
the scad code.)

Looking at the svg, the first block of strands have the end points
set equal, and when a number of blocks are created and joined, the
fact that the endpoints are equal is not apparent The scad script
generates that image. However, I've a suspicion that for certain
values of sep, and range of rands, in the construction of the
connected blocks, then the repeated constant ends would be visible
across the group of blocks. I'm aiming at a general solution, not one
that works for certain values.

If you comment out the fixed ty and by, and uncomment the first pair,
(in the strand module) then the blocks have the random end points,
but they do not persist for each block, and gives 'steps' when the
blocks are aligned.

I may be wrong, but it appears that once a seed is generated for
random numbers, it applies to every instant of rands.

If the length of strands is increased to 1000, say, then it shows
what I would like to achieve by joining ten blocks of length 100.

I could generate a list of rands for ty and by, and increment through
when the block is created, but having a choice of random seeds would
be nice.

I may be missing the obvious. While I'm in winge mode, it's an
irritation that importing an svg that has just been exported it
arrives in a different location.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Hi Jon, The best way to understand what I am trying to explain, is probably to run the code, and maybe zoom in, or alter the values. Exactly as it is, I can not see any endpoint artefacts/vertical lines, etc., but I can envisage that with different values, 'vertical lines/joins' would be visible. On 18/10/2022 13:29, jon wrote: > Ray: > > I did not read your code, but when you say the "end points set equal", > is the thickness the same, or are both the thickness and the angle the > same?  Are you seeing places where the two ends are in the same > location, but the trajectory of the two pieces are so different that > the joint is obvious?  Do you need to get the two end points to go at > the same angle? > > Jon > > > On 10/18/2022 8:13 AM, Ray West wrote: >> Thanks for the replies, I'll try and show a bit more explanation. >> I've extracted the relevant code from my  more complex overall >> solution attempt, and I've attached it and a svg (the svg produced by >> the scad code.) >> >> Looking at the svg, the first block of strands have the end points >> set equal, and when a number of blocks are created and joined, the >> fact that the endpoints are equal is not apparent The scad script >> generates that image. However, I've a suspicion that for certain >> values of sep, and range of rands, in the construction of the >> connected blocks, then the repeated constant ends would be visible >> across the group of blocks. I'm aiming at a general solution, not one >> that works for certain values. >> >> If you comment out the fixed ty and by, and uncomment the first pair, >> (in the strand module) then the blocks have the random end points, >> but they do not persist for each block, and gives 'steps' when the >> blocks are aligned. >> >> I may be wrong, but it appears that once a seed is generated for >> random numbers, it applies to every instant of rands. >> >> If the length of strands is increased to 1000, say, then it shows >> what I would like to achieve by joining ten blocks of length 100. >> >> I could generate a list of rands for ty and by, and increment through >> when the block is created, but having a choice of random seeds would >> be nice. >> >> I may be missing the obvious. While I'm in winge mode, it's an >> irritation that importing an svg that has just been exported it >> arrives in a different location. >> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org