discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

algorithme parameter

A
ashuan
Wed, Oct 25, 2017 3:40 PM

Hello alls,

I have a lot of same objects witch a parameter.
This parameter change the presentation of this object.

I want to configure different kind of algorithme who configure my grid of
object with different values of this parameter.

For example :

I have 9 objets like this :
A    B    C
1
2
3

The first algorithme populate like this :
A    B    C
1    1    1    1
2    1    1    1
3    1    1    1
The second like this :
A    B    C
1    1    1    1
2    2    2    2
3    4    4    4
The third like this :
A    B    C
1    1    2    4
2    1    2    4
3    1    2    4
etc...

I'm use customizer with the algorithme choice and in my code i have
something like that :
if (opengrid == "V") {
for(idxLargeur = [1 : x])
{
hLn = 10;
for(idxLongueur = [1 : y])
{
random_vect[(idxLargeurx)
+ idxLongueur]
= hLn ;
}
}
} else {
min_aleat = opengrid == "S" ? 1 :
opengrid == "M" ? 10 : 7;
max_aleat = opengrid == "S" ? 40 :
opengrid == "M" ? 10 : 15;
random_vect=rands(min_aleat, max_aleat,
(x
y));
}

When i try this, i'm blocked at this line :
random_vect[(idxLargeur*x)
+ idxLongueur]
= hLn ;

How could i do that ?

Thanks

--
Sent from: http://forum.openscad.org/

Hello alls, I have a lot of same objects witch a parameter. This parameter change the presentation of this object. I want to configure different kind of algorithme who configure my grid of object with different values of this parameter. For example : I have 9 objets like this : A B C 1 2 3 The first algorithme populate like this : A B C 1 1 1 1 2 1 1 1 3 1 1 1 The second like this : A B C 1 1 1 1 2 2 2 2 3 4 4 4 The third like this : A B C 1 1 2 4 2 1 2 4 3 1 2 4 etc... I'm use customizer with the algorithme choice and in my code i have something like that : if (opengrid == "V") { for(idxLargeur = [1 : x]) { hLn = 10; for(idxLongueur = [1 : y]) { random_vect[(idxLargeur*x) + idxLongueur] = hLn ; } } } else { min_aleat = opengrid == "S" ? 1 : opengrid == "M" ? 10 : 7; max_aleat = opengrid == "S" ? 40 : opengrid == "M" ? 10 : 15; random_vect=rands(min_aleat, max_aleat, (x*y)); } When i try this, i'm blocked at this line : random_vect[(idxLargeur*x) + idxLongueur] = hLn ; How could i do that ? Thanks -- Sent from: http://forum.openscad.org/
DM
doug moen
Wed, Oct 25, 2017 4:51 PM

OpenSCAD has the syntax of a C-like language, but the semantics are very
different. The = operator is not the assignment operator found in C-like
languages. = defines a variable, it doesn't assign to it (ie, it doesn't
update the current value). You can only define a variable once. If you mess
this up, you often don't get any error messages.

Try something like this:

random_vect = opengrid == "V"
? [for (i=[1:xy]) 10]
: let (min_aleat = opengrid == "S" ? 1 :
opengrid == "M" ? 10 : 7,
max_aleat = opengrid == "S" ? 40 :
opengrid == "M" ? 10 : 15)
rands(min_aleat, max_aleat, x
y);

On 25 October 2017 at 11:40, ashuan laurent.sass@gmail.com wrote:

Hello alls,

I have a lot of same objects witch a parameter.
This parameter change the presentation of this object.

I want to configure different kind of algorithme who configure my grid of
object with different values of this parameter.

For example :

I have 9 objets like this :
A    B    C
1
2
3

The first algorithme populate like this :
A    B    C
1    1    1    1
2    1    1    1
3    1    1    1
The second like this :
A    B    C
1    1    1    1
2    2    2    2
3    4    4    4
The third like this :
A    B    C
1    1    2    4
2    1    2    4
3    1    2    4
etc...

I'm use customizer with the algorithme choice and in my code i have
something like that :
if (opengrid == "V") {
for(idxLargeur = [1 : x])
{
hLn = 10;
for(idxLongueur = [1 : y])
{
random_vect[(idxLargeurx)
+ idxLongueur]
= hLn ;
}
}
} else {
min_aleat = opengrid == "S" ? 1 :
opengrid == "M" ? 10 : 7;
max_aleat = opengrid == "S" ? 40 :
opengrid == "M" ? 10 : 15;
random_vect=rands(min_aleat, max_aleat,
(x
y));
}

When i try this, i'm blocked at this line :
random_vect[(idxLargeur*x)
+ idxLongueur]
= hLn ;

How could i do that ?

Thanks

--
Sent from: http://forum.openscad.org/


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

OpenSCAD has the syntax of a C-like language, but the semantics are very different. The `=` operator is not the assignment operator found in C-like languages. `=` defines a variable, it doesn't assign to it (ie, it doesn't update the current value). You can only define a variable once. If you mess this up, you often don't get any error messages. Try something like this: random_vect = opengrid == "V" ? [for (i=[1:x*y]) 10] : let (min_aleat = opengrid == "S" ? 1 : opengrid == "M" ? 10 : 7, max_aleat = opengrid == "S" ? 40 : opengrid == "M" ? 10 : 15) rands(min_aleat, max_aleat, x*y); On 25 October 2017 at 11:40, ashuan <laurent.sass@gmail.com> wrote: > Hello alls, > > I have a lot of same objects witch a parameter. > This parameter change the presentation of this object. > > I want to configure different kind of algorithme who configure my grid of > object with different values of this parameter. > > For example : > > I have 9 objets like this : > A B C > 1 > 2 > 3 > > The first algorithme populate like this : > A B C > 1 1 1 1 > 2 1 1 1 > 3 1 1 1 > The second like this : > A B C > 1 1 1 1 > 2 2 2 2 > 3 4 4 4 > The third like this : > A B C > 1 1 2 4 > 2 1 2 4 > 3 1 2 4 > etc... > > I'm use customizer with the algorithme choice and in my code i have > something like that : > if (opengrid == "V") { > for(idxLargeur = [1 : x]) > { > hLn = 10; > for(idxLongueur = [1 : y]) > { > random_vect[(idxLargeur*x) > + idxLongueur] > = hLn ; > } > } > } else { > min_aleat = opengrid == "S" ? 1 : > opengrid == "M" ? 10 : 7; > max_aleat = opengrid == "S" ? 40 : > opengrid == "M" ? 10 : 15; > random_vect=rands(min_aleat, max_aleat, > (x*y)); > } > > When i try this, i'm blocked at this line : > random_vect[(idxLargeur*x) > + idxLongueur] > = hLn ; > > How could i do that ? > > Thanks > > > > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
A
ashuan
Thu, Oct 26, 2017 8:43 AM

Thanks for your answer.

Could i try something like this :

if (algo == "V")
{
algovector1
vector1 = ...
}
if (algo == "C")
{
algovector2
vector2 = ...
}
if (algo == "A")
{
algovector3
vector3 = ...
}
finalVector = algo == "V" ? vector1 :
algo == "C" ? vector2 :
algo == "A" ? vector3 : [];

--
Sent from: http://forum.openscad.org/

Thanks for your answer. Could i try something like this : if (algo == "V") { algovector1 vector1 = ... } if (algo == "C") { algovector2 vector2 = ... } if (algo == "A") { algovector3 vector3 = ... } finalVector = algo == "V" ? vector1 : algo == "C" ? vector2 : algo == "A" ? vector3 : []; -- Sent from: http://forum.openscad.org/
A
ashuan
Thu, Oct 26, 2017 9:31 AM

I think my solution are not ok because, i need to make a loop for calculated
each vector values.
In that case, each value could not populate my vector distinctly because the
first affectation block the vector value.

--
Sent from: http://forum.openscad.org/

I think my solution are not ok because, i need to make a loop for calculated each vector values. In that case, each value could not populate my vector distinctly because the first affectation block the vector value. -- Sent from: http://forum.openscad.org/
DM
doug moen
Thu, Oct 26, 2017 12:41 PM

The following syntax won't work, because the definitions of vector1,
vector2 and vector3 are local to the enclosing {...} compound
statement, and are not visible at the top level:

if (algo == "V")
{
algovector1
vector1 = ...
}
if (algo == "C")
{
algovector2
vector2 = ...
}
if (algo == "A")
{
algovector3
vector3 = ...
}
finalVector = algo == "V" ? vector1 :
algo == "C" ? vector2 :
algo == "A" ? vector3 : [];

So your code needs to be structured more like this:

vector1 = ...;
vector2 = ...;
vector3 = ...;
finalVector = algo == "V" ? vector1 :
algo == "C" ? vector2 :
algo == "A" ? vector3 : [];

Or you can move the values of vector1, vector2 and vector3 inside of the ?
: conditional in the definition of finalVector.

If you need to use a loop to construct one of the vectors, then you should
try to use List Comprehension syntax, which allows you to put a 'for' loop
inside of the [...] that constructs a vector.

See the manual:
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions

https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail
Virus-free.
www.avast.com
https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On 26 October 2017 at 05:31, ashuan laurent.sass@gmail.com wrote:

I think my solution are not ok because, i need to make a loop for
calculated
each vector values.
In that case, each value could not populate my vector distinctly because
the
first affectation block the vector value.

--
Sent from: http://forum.openscad.org/


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

The following syntax won't work, because the definitions of `vector1`, `vector2` and `vector3` are local to the enclosing {...} compound statement, and are not visible at the top level: if (algo == "V") { algovector1 vector1 = ... } if (algo == "C") { algovector2 vector2 = ... } if (algo == "A") { algovector3 vector3 = ... } finalVector = algo == "V" ? vector1 : algo == "C" ? vector2 : algo == "A" ? vector3 : []; So your code needs to be structured more like this: vector1 = ...; vector2 = ...; vector3 = ...; finalVector = algo == "V" ? vector1 : algo == "C" ? vector2 : algo == "A" ? vector3 : []; Or you can move the values of vector1, vector2 and vector3 inside of the ? : conditional in the definition of finalVector. If you need to use a loop to construct one of the vectors, then you should try to use List Comprehension syntax, which allows you to put a 'for' loop inside of the [...] that constructs a vector. See the manual: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> Virus-free. www.avast.com <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> On 26 October 2017 at 05:31, ashuan <laurent.sass@gmail.com> wrote: > I think my solution are not ok because, i need to make a loop for > calculated > each vector values. > In that case, each value could not populate my vector distinctly because > the > first affectation block the vector value. > > > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
A
ashuan
Thu, Oct 26, 2017 1:42 PM

Thanks for your help.

I'll try your second solution  like that :

random_vect = 
    opengrid == "S" ? 
        rands(1, 40, nbTot)
    :
    opengrid == "M" ? 
        rands(10, 10, nbTot)
    :
    opengrid == "L" ? 
        rands(7, 15, nbTot)
    : 
    opengrid == "V" ? 
        [ for (idxLargeur = [1 : nbLargeur])
          for (idxLongueur = [1 : nbLongueur])
              if (idxLargeur == 2 && idxLongueur == 3) 30 else 0 //

example with one modification
]
:
[]
;

It seem to work correctly.

--
Sent from: http://forum.openscad.org/

Thanks for your help. I'll try your second solution like that : random_vect = opengrid == "S" ? rands(1, 40, nbTot) : opengrid == "M" ? rands(10, 10, nbTot) : opengrid == "L" ? rands(7, 15, nbTot) : opengrid == "V" ? [ for (idxLargeur = [1 : nbLargeur]) for (idxLongueur = [1 : nbLongueur]) if (idxLargeur == 2 && idxLongueur == 3) 30 else 0 // example with one modification ] : [] ; It seem to work correctly. -- Sent from: http://forum.openscad.org/