K
kipplebits
Thu, May 7, 2020 9:07 PM
Hello all, I've been playing with laser engraving recently. I'm still not
done figuring it all out(using laserGRBL), although I've done a few test
cuts now, and discovered a good workflow using openSCAD and GIMP; and I get
pretty accurate results. Ideally my engraver would let me import my own
g-codes, although I haven't figured that out yet. I have however had pretty
good success converting my svg's to black&white png images and then sending
to the engraver. I seem to be having some trouble now though designing a 2d
grid for my engraving table. One thing is OpenSCAD seams to do a good job of
closing off all my polygons automatically. I think this shouldn't really be
a problem if I split my design into separate vertical and horizontal
components, although I was also having some problems with figuring out the
proper way to write my for loops so they compile, and don't give me blank
output. ...I updated to latest release, and some of my problems
disappeared(conditionals inside points array declaration), although I'm
still sort of baffled about some things. Like these 2 examples:
this code outputs vertical bars:
width = 35;
length = 50;
toggle_a = [0, 1, 1, 0];
toggle_b = [0, 0, 1, 1];
verti_points = [
for(i=[0:2:width])//{
for(j=[0:1:3])//{
[(10i+10toggle_b[j]), (10lengthtoggle_a[j])]
//}
//}
];
polygon(points=verti_points);
this code does not output anything:
width = 35;
length = 50;
toggle_a = [0, 1, 1, 0];
toggle_b = [0, 0, 1, 1];
verti_points = [[0,0]];
for(i=[0:2:width]){
for(j=[0:1:3]){
verti_points = concat(verti_points, [[(10i+10toggle_b[j]),
(10lengthtoggle_a[j])]]);
}
}
polygon(points=verti_points);
So why does my second code snip deliver no output, while the first gives me
vertical bars? Aren't they logically equivalent? Maybe I'm just not doing it
the right way? I hate to import a generated array...
...and as of writing this I realize there is a sort trivial solution for
this:
width = 35;
length = 50;
for(i=[0:2:length]){
translate(v = [0, i10, 0]){
square(size = [width10, 10], center = true/false);
}
}
...Still, suppose I'm not making things out of squares or circles; how do I
nest conditionals and loops and append points to my list? can i not concat
point to an existing array? I guess I'm just wondering if there could be a
little more documentation about flow-control(with perhaps some simple
examples), and also maybe some extra operators like while() ...and maybe
switch()?
p.s. I like the jingle bells on the new release ;P
--
Sent from: http://forum.openscad.org/
Hello all, I've been playing with laser engraving recently. I'm still not
done figuring it all out(using laserGRBL), although I've done a few test
cuts now, and discovered a good workflow using openSCAD and GIMP; and I get
pretty accurate results. Ideally my engraver would let me import my own
g-codes, although I haven't figured that out yet. I have however had pretty
good success converting my svg's to black&white png images and then sending
to the engraver. I seem to be having some trouble now though designing a 2d
grid for my engraving table. One thing is OpenSCAD seams to do a good job of
closing off all my polygons automatically. I think this shouldn't really be
a problem if I split my design into separate vertical and horizontal
components, although I was also having some problems with figuring out the
proper way to write my for loops so they compile, and don't give me blank
output. ...I updated to latest release, and some of my problems
disappeared(conditionals inside points array declaration), although I'm
still sort of baffled about some things. Like these 2 examples:
this code outputs vertical bars:
width = 35;
length = 50;
toggle_a = [0, 1, 1, 0];
toggle_b = [0, 0, 1, 1];
verti_points = [
for(i=[0:2:width])//{
for(j=[0:1:3])//{
[(10*i+10*toggle_b[j]), (10*length*toggle_a[j])]
//}
//}
];
polygon(points=verti_points);
this code does not output anything:
width = 35;
length = 50;
toggle_a = [0, 1, 1, 0];
toggle_b = [0, 0, 1, 1];
verti_points = [[0,0]];
for(i=[0:2:width]){
for(j=[0:1:3]){
verti_points = concat(verti_points, [[(10*i+10*toggle_b[j]),
(10*length*toggle_a[j])]]);
}
}
polygon(points=verti_points);
So why does my second code snip deliver no output, while the first gives me
vertical bars? Aren't they logically equivalent? Maybe I'm just not doing it
the right way? I hate to import a generated array...
...and as of writing this I realize there is a sort trivial solution for
this:
width = 35;
length = 50;
for(i=[0:2:length]){
translate(v = [0, i*10, 0]){
square(size = [width*10, 10], center = true/false);
}
}
...Still, suppose I'm not making things out of squares or circles; how do I
nest conditionals and loops and append points to my list? can i not concat
point to an existing array? I guess I'm just wondering if there could be a
little more documentation about flow-control(with perhaps some simple
examples), and also maybe some extra operators like while() ...and maybe
switch()?
p.s. I like the jingle bells on the new release ;P
--
Sent from: http://forum.openscad.org/
JB
Jordan Brown
Thu, May 7, 2020 10:27 PM
On 5/7/2020 2:07 PM, kipplebits wrote:
...Still, suppose I'm not making things out of squares or circles; how do I
nest conditionals and loops and append points to my list? can i not concat
point to an existing array?
You can't.
In general, once you've set the value of a "variable", you can't change
it. They're really more constants than variables. The picture is a bit
more complicated than that - for instance, you can set a new value
inside some kinds of blocks - but that's the way to think about it.
In particular, what you're trying to do is sort of equivalent to this:
x = 0;
for (i = [1:10]) {
x = x + 1;
echo("looping", x);
}
echo("done", x);
... which produces this output:
ECHO: "looping", 1
ECHO: "looping", 1
ECHO: "looping", 1
ECHO: "looping", 1
ECHO: "looping", 1
ECHO: "looping", 1
ECHO: "looping", 1
ECHO: "looping", 1
ECHO: "looping", 1
ECHO: "looping", 1
ECHO: "done", 0
because the "x=x+1" takes the x that was defined outside the loop, adds
one to it, and puts the result (always one) into an x that is for that
iteration of the loop.
And then after the loop, you're seeing the outside-the-loop x again.
On 5/7/2020 2:07 PM, kipplebits wrote:
> ...Still, suppose I'm not making things out of squares or circles; how do I
> nest conditionals and loops and append points to my list? can i not concat
> point to an existing array?
You can't.
In general, once you've set the value of a "variable", you can't change
it. They're really more constants than variables. The picture is a bit
more complicated than that - for instance, you can set a new value
inside some kinds of blocks - but that's the way to think about it.
In particular, what you're trying to do is sort of equivalent to this:
x = 0;
for (i = [1:10]) {
x = x + 1;
echo("looping", x);
}
echo("done", x);
... which produces this output:
ECHO: "looping", 1
ECHO: "looping", 1
ECHO: "looping", 1
ECHO: "looping", 1
ECHO: "looping", 1
ECHO: "looping", 1
ECHO: "looping", 1
ECHO: "looping", 1
ECHO: "looping", 1
ECHO: "looping", 1
ECHO: "done", 0
because the "x=x+1" takes the x that was defined outside the loop, adds
one to it, and puts the result (always one) into an x that is for that
iteration of the loop.
And then after the loop, you're seeing the outside-the-loop x again.
TP
Torsten Paul
Thu, May 7, 2020 10:46 PM
You can't modify already assigned vectors, but you can
declare them using multiple expression and function
calls, e.g:
function right() = [ for (a = [20:-5:-20]) [18 + abs(a%10), a] ];
points = [
// top
for (a = [0:5:360]) [a / 10 - 18, 5 * sin(a) + 20],
// right
each right(),
// bottom
for (a = [360:-5:0]) [a / 10 - 18, 2 * sin(5 * a) - 20],
// left
[-20, -20],
[-15, 0],
[-20, 20]
];
polygon(points);
For more details, see List Comprehensions topic in the manual
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions
ciao,
Torsten.
You can't modify already assigned vectors, but you can
declare them using multiple expression and function
calls, e.g:
function right() = [ for (a = [20:-5:-20]) [18 + abs(a%10), a] ];
points = [
// top
for (a = [0:5:360]) [a / 10 - 18, 5 * sin(a) + 20],
// right
each right(),
// bottom
for (a = [360:-5:0]) [a / 10 - 18, 2 * sin(5 * a) - 20],
// left
[-20, -20],
[-15, 0],
[-20, 20]
];
polygon(points);
For more details, see List Comprehensions topic in the manual
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions
ciao,
Torsten.
KB
kipple bits
Fri, May 8, 2020 7:03 AM
...Right, Thank! ...I think I was actually already doing this
subconsciously, although I guess I was working a little outside of my
comfort zone, and got turned around. ...Also probably didn't help that I
was using a 3 year old build.(up to date now!) ...i guess the problem in my
example was related to scope then; I think in most programing
languages(c++, java) a for loop carries the same scope as it's
surroundings... ...also vectors/arrays are not static... ...kind of a
curveball ;P
OpenSCAD is sort of strange if you are used to c++ or java. how would you
classify OpenSCAD as a programing language? what other language would you
say it is most like?
https://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Pure
...Haskell?
Anyway I think I'm straightened out now, Thanks! hopefully I won't decide
to import code snips into my scad files again.
On Thu, May 7, 2020 at 6:46 PM Torsten Paul Torsten.Paul@gmx.de wrote:
You can't modify already assigned vectors, but you can
declare them using multiple expression and function
calls, e.g:
function right() = [ for (a = [20:-5:-20]) [18 + abs(a%10), a] ];
points = [
// top
for (a = [0:5:360]) [a / 10 - 18, 5 * sin(a) + 20],
// right
each right(),
// bottom
for (a = [360:-5:0]) [a / 10 - 18, 2 * sin(5 * a) - 20],
// left
[-20, -20],
[-15, 0],
[-20, 20]
];
polygon(points);
For more details, see List Comprehensions topic in the manual
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions
ciao,
Torsten.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
...Right, Thank! ...I think I was actually already doing this
subconsciously, although I guess I was working a little outside of my
comfort zone, and got turned around. ...Also probably didn't help that I
was using a 3 year old build.(up to date now!) ...i guess the problem in my
example was related to scope then; I think in most programing
languages(c++, java) a for loop carries the same scope as it's
surroundings... ...also vectors/arrays are not static... ...kind of a
curveball ;P
OpenSCAD is sort of strange if you are used to c++ or java. how would you
classify OpenSCAD as a programing language? what other language would you
say it is most like?
https://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Pure
...Haskell?
Anyway I think I'm straightened out now, Thanks! hopefully I won't decide
to import code snips into my scad files again.
On Thu, May 7, 2020 at 6:46 PM Torsten Paul <Torsten.Paul@gmx.de> wrote:
> You can't modify already assigned vectors, but you can
> declare them using multiple expression and function
> calls, e.g:
>
>
> function right() = [ for (a = [20:-5:-20]) [18 + abs(a%10), a] ];
>
> points = [
> // top
> for (a = [0:5:360]) [a / 10 - 18, 5 * sin(a) + 20],
> // right
> each right(),
> // bottom
> for (a = [360:-5:0]) [a / 10 - 18, 2 * sin(5 * a) - 20],
> // left
> [-20, -20],
> [-15, 0],
> [-20, 20]
> ];
>
> polygon(points);
>
>
> For more details, see List Comprehensions topic in the manual
> https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions
>
> ciao,
> Torsten.
>
> _______________________________________________
> OpenSCAD mailing list
> Discuss@lists.openscad.org
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
MB
Max Bond
Fri, May 8, 2020 10:20 AM
I would place OpenSCAD solidly in the functional camp.
t helps to understand that OpenSCAD is actually a fairly thin layer over
OpenCSG; if you take a look at some "compiled" code using Design -> Display
CSG Tree, you'll see that OpenSCAD's output is a static structure in an
"assembly language" not too different from OpenSCAD itself. OpenCSG doesn't
have any concept of variables or of mutating state. Those quirks propagate
up the stack into OpenSCAD.
It can take a big adjustment to learn to think in OpenSCAD, but I've found
that programming in this environment forces me to have a discipline that's
made me a better programmer in other languages.
Best of luck!
On Fri, May 8, 2020 at 1:04 AM kipple bits kipplebits@gmail.com wrote:
...Right, Thank! ...I think I was actually already doing this
subconsciously, although I guess I was working a little outside of my
comfort zone, and got turned around. ...Also probably didn't help that I
was using a 3 year old build.(up to date now!) ...i guess the problem in my
example was related to scope then; I think in most programing
languages(c++, java) a for loop carries the same scope as it's
surroundings... ...also vectors/arrays are not static... ...kind of a
curveball ;P
OpenSCAD is sort of strange if you are used to c++ or java. how would you
classify OpenSCAD as a programing language? what other language would you
say it is most like?
https://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Pure
...Haskell?
Anyway I think I'm straightened out now, Thanks! hopefully I won't decide
to import code snips into my scad files again.
On Thu, May 7, 2020 at 6:46 PM Torsten Paul Torsten.Paul@gmx.de wrote:
You can't modify already assigned vectors, but you can
declare them using multiple expression and function
calls, e.g:
function right() = [ for (a = [20:-5:-20]) [18 + abs(a%10), a] ];
points = [
// top
for (a = [0:5:360]) [a / 10 - 18, 5 * sin(a) + 20],
// right
each right(),
// bottom
for (a = [360:-5:0]) [a / 10 - 18, 2 * sin(5 * a) - 20],
// left
[-20, -20],
[-15, 0],
[-20, 20]
];
polygon(points);
For more details, see List Comprehensions topic in the manual
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions
ciao,
Torsten.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
I would place OpenSCAD solidly in the functional camp.
t helps to understand that OpenSCAD is actually a fairly thin layer over
OpenCSG; if you take a look at some "compiled" code using Design -> Display
CSG Tree, you'll see that OpenSCAD's output is a static structure in an
"assembly language" not too different from OpenSCAD itself. OpenCSG doesn't
have any concept of variables or of mutating state. Those quirks propagate
up the stack into OpenSCAD.
It can take a big adjustment to learn to think in OpenSCAD, but I've found
that programming in this environment forces me to have a discipline that's
made me a better programmer in other languages.
Best of luck!
On Fri, May 8, 2020 at 1:04 AM kipple bits <kipplebits@gmail.com> wrote:
> ...Right, Thank! ...I think I was actually already doing this
> subconsciously, although I guess I was working a little outside of my
> comfort zone, and got turned around. ...Also probably didn't help that I
> was using a 3 year old build.(up to date now!) ...i guess the problem in my
> example was related to scope then; I think in most programing
> languages(c++, java) a for loop carries the same scope as it's
> surroundings... ...also vectors/arrays are not static... ...kind of a
> curveball ;P
>
> OpenSCAD is sort of strange if you are used to c++ or java. how would you
> classify OpenSCAD as a programing language? what other language would you
> say it is most like?
> https://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Pure
> ...Haskell?
>
> Anyway I think I'm straightened out now, Thanks! hopefully I won't decide
> to import code snips into my scad files again.
>
> On Thu, May 7, 2020 at 6:46 PM Torsten Paul <Torsten.Paul@gmx.de> wrote:
>
>> You can't modify already assigned vectors, but you can
>> declare them using multiple expression and function
>> calls, e.g:
>>
>>
>> function right() = [ for (a = [20:-5:-20]) [18 + abs(a%10), a] ];
>>
>> points = [
>> // top
>> for (a = [0:5:360]) [a / 10 - 18, 5 * sin(a) + 20],
>> // right
>> each right(),
>> // bottom
>> for (a = [360:-5:0]) [a / 10 - 18, 2 * sin(5 * a) - 20],
>> // left
>> [-20, -20],
>> [-15, 0],
>> [-20, 20]
>> ];
>>
>> polygon(points);
>>
>>
>> For more details, see List Comprehensions topic in the manual
>> https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions
>>
>> ciao,
>> Torsten.
>>
>> _______________________________________________
>> OpenSCAD mailing list
>> Discuss@lists.openscad.org
>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>>
> _______________________________________________
> OpenSCAD mailing list
> Discuss@lists.openscad.org
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
NH
nop head
Fri, May 8, 2020 10:31 AM
Another way to think of it is that OpenSCAD script is not a program, it is
a description of some geometric objects. When you describe
something static nothing about it changes during the description, so no
variables are needed.
It is also like maths in that x = x +1 does not make sense.
On Fri, 8 May 2020 at 11:21, Max Bond max.o.bond@gmail.com wrote:
I would place OpenSCAD solidly in the functional camp.
t helps to understand that OpenSCAD is actually a fairly thin layer over
OpenCSG; if you take a look at some "compiled" code using Design -> Display
CSG Tree, you'll see that OpenSCAD's output is a static structure in an
"assembly language" not too different from OpenSCAD itself. OpenCSG doesn't
have any concept of variables or of mutating state. Those quirks propagate
up the stack into OpenSCAD.
It can take a big adjustment to learn to think in OpenSCAD, but I've found
that programming in this environment forces me to have a discipline that's
made me a better programmer in other languages.
Best of luck!
On Fri, May 8, 2020 at 1:04 AM kipple bits kipplebits@gmail.com wrote:
...Right, Thank! ...I think I was actually already doing this
subconsciously, although I guess I was working a little outside of my
comfort zone, and got turned around. ...Also probably didn't help that I
was using a 3 year old build.(up to date now!) ...i guess the problem in my
example was related to scope then; I think in most programing
languages(c++, java) a for loop carries the same scope as it's
surroundings... ...also vectors/arrays are not static... ...kind of a
curveball ;P
OpenSCAD is sort of strange if you are used to c++ or java. how would you
classify OpenSCAD as a programing language? what other language would you
say it is most like?
https://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Pure
...Haskell?
Anyway I think I'm straightened out now, Thanks! hopefully I won't decide
to import code snips into my scad files again.
On Thu, May 7, 2020 at 6:46 PM Torsten Paul Torsten.Paul@gmx.de wrote:
You can't modify already assigned vectors, but you can
declare them using multiple expression and function
calls, e.g:
function right() = [ for (a = [20:-5:-20]) [18 + abs(a%10), a] ];
points = [
// top
for (a = [0:5:360]) [a / 10 - 18, 5 * sin(a) + 20],
// right
each right(),
// bottom
for (a = [360:-5:0]) [a / 10 - 18, 2 * sin(5 * a) - 20],
// left
[-20, -20],
[-15, 0],
[-20, 20]
];
polygon(points);
For more details, see List Comprehensions topic in the manual
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions
ciao,
Torsten.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Another way to think of it is that OpenSCAD script is not a program, it is
a description of some geometric objects. When you describe
something static nothing about it changes during the description, so no
variables are needed.
It is also like maths in that x = x +1 does not make sense.
On Fri, 8 May 2020 at 11:21, Max Bond <max.o.bond@gmail.com> wrote:
> I would place OpenSCAD solidly in the functional camp.
>
> t helps to understand that OpenSCAD is actually a fairly thin layer over
> OpenCSG; if you take a look at some "compiled" code using Design -> Display
> CSG Tree, you'll see that OpenSCAD's output is a static structure in an
> "assembly language" not too different from OpenSCAD itself. OpenCSG doesn't
> have any concept of variables or of mutating state. Those quirks propagate
> up the stack into OpenSCAD.
>
> It can take a big adjustment to learn to think in OpenSCAD, but I've found
> that programming in this environment forces me to have a discipline that's
> made me a better programmer in other languages.
>
> Best of luck!
>
> On Fri, May 8, 2020 at 1:04 AM kipple bits <kipplebits@gmail.com> wrote:
>
>> ...Right, Thank! ...I think I was actually already doing this
>> subconsciously, although I guess I was working a little outside of my
>> comfort zone, and got turned around. ...Also probably didn't help that I
>> was using a 3 year old build.(up to date now!) ...i guess the problem in my
>> example was related to scope then; I think in most programing
>> languages(c++, java) a for loop carries the same scope as it's
>> surroundings... ...also vectors/arrays are not static... ...kind of a
>> curveball ;P
>>
>> OpenSCAD is sort of strange if you are used to c++ or java. how would you
>> classify OpenSCAD as a programing language? what other language would you
>> say it is most like?
>> https://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Pure
>> ...Haskell?
>>
>> Anyway I think I'm straightened out now, Thanks! hopefully I won't decide
>> to import code snips into my scad files again.
>>
>> On Thu, May 7, 2020 at 6:46 PM Torsten Paul <Torsten.Paul@gmx.de> wrote:
>>
>>> You can't modify already assigned vectors, but you can
>>> declare them using multiple expression and function
>>> calls, e.g:
>>>
>>>
>>> function right() = [ for (a = [20:-5:-20]) [18 + abs(a%10), a] ];
>>>
>>> points = [
>>> // top
>>> for (a = [0:5:360]) [a / 10 - 18, 5 * sin(a) + 20],
>>> // right
>>> each right(),
>>> // bottom
>>> for (a = [360:-5:0]) [a / 10 - 18, 2 * sin(5 * a) - 20],
>>> // left
>>> [-20, -20],
>>> [-15, 0],
>>> [-20, 20]
>>> ];
>>>
>>> polygon(points);
>>>
>>>
>>> For more details, see List Comprehensions topic in the manual
>>> https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions
>>>
>>> ciao,
>>> Torsten.
>>>
>>> _______________________________________________
>>> OpenSCAD mailing list
>>> Discuss@lists.openscad.org
>>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>>>
>> _______________________________________________
>> OpenSCAD mailing list
>> Discuss@lists.openscad.org
>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>>
> _______________________________________________
> OpenSCAD mailing list
> Discuss@lists.openscad.org
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
AG
Alex Gibson
Fri, May 8, 2020 10:40 AM
When talking to people with some technical background I’m often describing OpenSCAD as like building a web page by typing raw HTML.
This then makes it easy for them to imagine the layers of use:
-It’s easy to make a simple thing, like a web page from the 90’s
-It’s a HORRIBLE way to make something sophisticated like a modern web page from scratch – it would normally be the wrong tool
-
EXCEPT if you need to make something very specific happen, or you need a greater control of the moving parts than you get by using a plug-in.
-
And that sections of pre-written code can be imported and then used with great control – making much more sophisticated things faster without going insane making them from scratch.
Alex Gibson
admg consulting
edumaker limited
· Project management
· Operations & Process improvement
· 3D Printing
From: Discuss [mailto:discuss-bounces@lists.openscad.org] On Behalf Of nop head
Sent: 08 May 2020 11:32
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] 2D SVG concat(points, [point]) no output, loops&conditionals, vector declarations
Another way to think of it is that OpenSCAD script is not a program, it is a description of some geometric objects. When you describe something static nothing about it changes during the description, so no variables are needed.
It is also like maths in that x = x +1 does not make sense.
On Fri, 8 May 2020 at 11:21, Max Bond max.o.bond@gmail.com wrote:
I would place OpenSCAD solidly in the functional camp.
t helps to understand that OpenSCAD is actually a fairly thin layer over OpenCSG; if you take a look at some "compiled" code using Design -> Display CSG Tree, you'll see that OpenSCAD's output is a static structure in an "assembly language" not too different from OpenSCAD itself. OpenCSG doesn't have any concept of variables or of mutating state. Those quirks propagate up the stack into OpenSCAD.
It can take a big adjustment to learn to think in OpenSCAD, but I've found that programming in this environment forces me to have a discipline that's made me a better programmer in other languages.
Best of luck!
On Fri, May 8, 2020 at 1:04 AM kipple bits kipplebits@gmail.com wrote:
...Right, Thank! ...I think I was actually already doing this subconsciously, although I guess I was working a little outside of my comfort zone, and got turned around. ...Also probably didn't help that I was using a 3 year old build.(up to date now!) ...i guess the problem in my example was related to scope then; I think in most programing languages(c++, java) a for loop carries the same scope as it's surroundings... ...also vectors/arrays are not static... ...kind of a curveball ;P
OpenSCAD is sort of strange if you are used to c++ or java. how would you classify OpenSCAD as a programing language? what other language would you say it is most like? https://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Pure ...Haskell?
Anyway I think I'm straightened out now, Thanks! hopefully I won't decide to import code snips into my scad files again.
On Thu, May 7, 2020 at 6:46 PM Torsten Paul Torsten.Paul@gmx.de wrote:
You can't modify already assigned vectors, but you can
declare them using multiple expression and function
calls, e.g:
function right() = [ for (a = [20:-5:-20]) [18 + abs(a%10), a] ];
points = [
// top
for (a = [0:5:360]) [a / 10 - 18, 5 * sin(a) + 20],
// right
each right(),
// bottom
for (a = [360:-5:0]) [a / 10 - 18, 2 * sin(5 * a) - 20],
// left
[-20, -20],
[-15, 0],
[-20, 20]
];
polygon(points);
For more details, see List Comprehensions topic in the manual
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions
ciao,
Torsten.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient
Virus-free. http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient www.avg.com
When talking to people with some technical background I’m often describing OpenSCAD as like building a web page by typing raw HTML.
This then makes it easy for them to imagine the layers of use:
-It’s easy to make a simple thing, like a web page from the 90’s
-It’s a HORRIBLE way to make something sophisticated like a modern web page from scratch – it would normally be the wrong tool
- EXCEPT if you need to make something very specific happen, or you need a greater control of the moving parts than you get by using a plug-in.
- And that sections of pre-written code can be imported and then used with great control – making much more sophisticated things faster without going insane making them from scratch.
Alex Gibson
admg consulting
edumaker limited
· Project management
· Operations & Process improvement
· 3D Printing
From: Discuss [mailto:discuss-bounces@lists.openscad.org] On Behalf Of nop head
Sent: 08 May 2020 11:32
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] 2D SVG concat(points, [point]) no output, loops&conditionals, vector declarations
Another way to think of it is that OpenSCAD script is not a program, it is a description of some geometric objects. When you describe something static nothing about it changes during the description, so no variables are needed.
It is also like maths in that x = x +1 does not make sense.
On Fri, 8 May 2020 at 11:21, Max Bond <max.o.bond@gmail.com> wrote:
I would place OpenSCAD solidly in the functional camp.
t helps to understand that OpenSCAD is actually a fairly thin layer over OpenCSG; if you take a look at some "compiled" code using Design -> Display CSG Tree, you'll see that OpenSCAD's output is a static structure in an "assembly language" not too different from OpenSCAD itself. OpenCSG doesn't have any concept of variables or of mutating state. Those quirks propagate up the stack into OpenSCAD.
It can take a big adjustment to learn to think in OpenSCAD, but I've found that programming in this environment forces me to have a discipline that's made me a better programmer in other languages.
Best of luck!
On Fri, May 8, 2020 at 1:04 AM kipple bits <kipplebits@gmail.com> wrote:
...Right, Thank! ...I think I was actually already doing this subconsciously, although I guess I was working a little outside of my comfort zone, and got turned around. ...Also probably didn't help that I was using a 3 year old build.(up to date now!) ...i guess the problem in my example was related to scope then; I think in most programing languages(c++, java) a for loop carries the same scope as it's surroundings... ...also vectors/arrays are not static... ...kind of a curveball ;P
OpenSCAD is sort of strange if you are used to c++ or java. how would you classify OpenSCAD as a programing language? what other language would you say it is most like? https://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Pure ...Haskell?
Anyway I think I'm straightened out now, Thanks! hopefully I won't decide to import code snips into my scad files again.
On Thu, May 7, 2020 at 6:46 PM Torsten Paul <Torsten.Paul@gmx.de> wrote:
You can't modify already assigned vectors, but you can
declare them using multiple expression and function
calls, e.g:
function right() = [ for (a = [20:-5:-20]) [18 + abs(a%10), a] ];
points = [
// top
for (a = [0:5:360]) [a / 10 - 18, 5 * sin(a) + 20],
// right
each right(),
// bottom
for (a = [360:-5:0]) [a / 10 - 18, 2 * sin(5 * a) - 20],
// left
[-20, -20],
[-15, 0],
[-20, 20]
];
polygon(points);
For more details, see List Comprehensions topic in the manual
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions
ciao,
Torsten.
_______________________________________________
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
Virus-free. <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient> www.avg.com
RW
Rob Ward
Fri, May 8, 2020 11:58 AM
I think that sums up the OpenSCAD variable dilemma.
"It is also like maths in that x = x +1 does not make sense."
as a static equation, as NopHead says it does make sense mathematically, I agree.
But to see it as a powerful programming concept of a calculation followed by an assignment means it is a very, very sad omission in OpenSCAD.
My limited understanding of OpenSCAD is that it was thrown together to generate .stl files to make 3-D printer parts. This maybe mythological garbage I have accumulated from somewhere, or maybe true. If that is true, it has succeeded in that sense and in many other fantastic designs.
I have found OpenSCAD immensely useful and inspiring in its current incarnation. I am indebted to its authors. But it seems to me that the long term users of it have so much code they don't want to see broken, and they are the ones most qualified to change it, that nothing is going to change soon.
Call OpenSCAD whatever type of programming you like, if it is unable to implement a simple accumulator increment, then it simply appears a mysterious orphan, cast off from the very architecture that actually makes it possible. Very curious.
If it is possible to set up increments/assignments in For loops, why not for other variables?
Rob
On 8 May 2020 8:31:38 pm AEST, nop head nop.head@gmail.com wrote:
Another way to think of it is that OpenSCAD script is not a program, it
is
a description of some geometric objects. When you describe
something static nothing about it changes during the description, so no
variables are needed.
It is also like maths in that x = x +1 does not make sense.
On Fri, 8 May 2020 at 11:21, Max Bond max.o.bond@gmail.com wrote:
I would place OpenSCAD solidly in the functional camp.
t helps to understand that OpenSCAD is actually a fairly thin layer
OpenCSG; if you take a look at some "compiled" code using Design ->
CSG Tree, you'll see that OpenSCAD's output is a static structure in
"assembly language" not too different from OpenSCAD itself. OpenCSG
have any concept of variables or of mutating state. Those quirks
up the stack into OpenSCAD.
It can take a big adjustment to learn to think in OpenSCAD, but I've
that programming in this environment forces me to have a discipline
made me a better programmer in other languages.
Best of luck!
On Fri, May 8, 2020 at 1:04 AM kipple bits kipplebits@gmail.com
...Right, Thank! ...I think I was actually already doing this
subconsciously, although I guess I was working a little outside of
comfort zone, and got turned around. ...Also probably didn't help
was using a 3 year old build.(up to date now!) ...i guess the
example was related to scope then; I think in most programing
languages(c++, java) a for loop carries the same scope as it's
surroundings... ...also vectors/arrays are not static... ...kind of
curveball ;P
OpenSCAD is sort of strange if you are used to c++ or java. how
classify OpenSCAD as a programing language? what other language
...Haskell?
Anyway I think I'm straightened out now, Thanks! hopefully I won't
to import code snips into my scad files again.
On Thu, May 7, 2020 at 6:46 PM Torsten Paul Torsten.Paul@gmx.de
You can't modify already assigned vectors, but you can
declare them using multiple expression and function
calls, e.g:
function right() = [ for (a = [20:-5:-20]) [18 + abs(a%10), a] ];
points = [
// top
for (a = [0:5:360]) [a / 10 - 18, 5 * sin(a) + 20],
// right
each right(),
// bottom
for (a = [360:-5:0]) [a / 10 - 18, 2 * sin(5 * a) - 20],
// left
[-20, -20],
[-15, 0],
[-20, 20]
];
polygon(points);
For more details, see List Comprehensions topic in the manual
I think that sums up the OpenSCAD variable dilemma.
"It is also like maths in that x = x +1 does not make sense."
as a static equation, as NopHead says it does make sense mathematically, I agree.
But to see it as a powerful programming concept of a calculation followed by an assignment means it is a very, very sad omission in OpenSCAD.
My limited understanding of OpenSCAD is that it was thrown together to generate .stl files to make 3-D printer parts. This maybe mythological garbage I have accumulated from somewhere, or maybe true. If that is true, it has succeeded in that sense and in many other fantastic designs.
I have found OpenSCAD immensely useful and inspiring in its current incarnation. I am indebted to its authors. But it seems to me that the long term users of it have so much code they don't want to see broken, and they are the ones most qualified to change it, that nothing is going to change soon.
Call OpenSCAD whatever type of programming you like, if it is unable to implement a simple accumulator increment, then it simply appears a mysterious orphan, cast off from the very architecture that actually makes it possible. Very curious.
If it is possible to set up increments/assignments in For loops, why not for other variables?
Rob
On 8 May 2020 8:31:38 pm AEST, nop head <nop.head@gmail.com> wrote:
>Another way to think of it is that OpenSCAD script is not a program, it
>is
>a description of some geometric objects. When you describe
>something static nothing about it changes during the description, so no
>variables are needed.
>
>It is also like maths in that x = x +1 does not make sense.
>
>On Fri, 8 May 2020 at 11:21, Max Bond <max.o.bond@gmail.com> wrote:
>
>> I would place OpenSCAD solidly in the functional camp.
>>
>> t helps to understand that OpenSCAD is actually a fairly thin layer
>over
>> OpenCSG; if you take a look at some "compiled" code using Design ->
>Display
>> CSG Tree, you'll see that OpenSCAD's output is a static structure in
>an
>> "assembly language" not too different from OpenSCAD itself. OpenCSG
>doesn't
>> have any concept of variables or of mutating state. Those quirks
>propagate
>> up the stack into OpenSCAD.
>>
>> It can take a big adjustment to learn to think in OpenSCAD, but I've
>found
>> that programming in this environment forces me to have a discipline
>that's
>> made me a better programmer in other languages.
>>
>> Best of luck!
>>
>> On Fri, May 8, 2020 at 1:04 AM kipple bits <kipplebits@gmail.com>
>wrote:
>>
>>> ...Right, Thank! ...I think I was actually already doing this
>>> subconsciously, although I guess I was working a little outside of
>my
>>> comfort zone, and got turned around. ...Also probably didn't help
>that I
>>> was using a 3 year old build.(up to date now!) ...i guess the
>problem in my
>>> example was related to scope then; I think in most programing
>>> languages(c++, java) a for loop carries the same scope as it's
>>> surroundings... ...also vectors/arrays are not static... ...kind of
>a
>>> curveball ;P
>>>
>>> OpenSCAD is sort of strange if you are used to c++ or java. how
>would you
>>> classify OpenSCAD as a programing language? what other language
>would you
>>> say it is most like?
>>>
>https://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Pure
>>> ...Haskell?
>>>
>>> Anyway I think I'm straightened out now, Thanks! hopefully I won't
>decide
>>> to import code snips into my scad files again.
>>>
>>> On Thu, May 7, 2020 at 6:46 PM Torsten Paul <Torsten.Paul@gmx.de>
>wrote:
>>>
>>>> You can't modify already assigned vectors, but you can
>>>> declare them using multiple expression and function
>>>> calls, e.g:
>>>>
>>>>
>>>> function right() = [ for (a = [20:-5:-20]) [18 + abs(a%10), a] ];
>>>>
>>>> points = [
>>>> // top
>>>> for (a = [0:5:360]) [a / 10 - 18, 5 * sin(a) + 20],
>>>> // right
>>>> each right(),
>>>> // bottom
>>>> for (a = [360:-5:0]) [a / 10 - 18, 2 * sin(5 * a) - 20],
>>>> // left
>>>> [-20, -20],
>>>> [-15, 0],
>>>> [-20, 20]
>>>> ];
>>>>
>>>> polygon(points);
>>>>
>>>>
>>>> For more details, see List Comprehensions topic in the manual
>>>>
>https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions
>>>>
>>>> ciao,
>>>> Torsten.
>>>>
>>>> _______________________________________________
>>>> OpenSCAD mailing list
>>>> Discuss@lists.openscad.org
>>>>
>http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>>>>
>>> _______________________________________________
>>> OpenSCAD mailing list
>>> Discuss@lists.openscad.org
>>>
>http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>>>
>> _______________________________________________
>> OpenSCAD mailing list
>> Discuss@lists.openscad.org
>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>>
JB
Jordan Brown
Fri, May 8, 2020 6:00 PM
On 5/8/2020 4:58 AM, Rob Ward wrote:
If it is possible to set up increments/assignments in For loops, why
not for other variables?
First, I have to note that I know nothing of the internals of OpenSCAD.
However, I have done some black-box exploration of its behavior.
There are two distinct questions there:
- Could there be a language similar to OpenSCAD that has more
"conventional" behavior?
- How hard would it be to change OpenSCAD to behave like such a language?
I think the answer to the first is clearly "yes". One can readily
imagine languages that behave more conventionally. Most likely, one
would just build a CSG library for some existing language like Python or
JavaScript.
The answer to the second question is much trickier. Again, I'm not
familiar with the internals of OpenSCAD, but black-box testing shows
that its behavior is even further from "conventional" than it first appears.
Consider:
x = echo("1") 0;
echo("2");
y = echo("3") 0;
Simple enough, right?
ECHO: "1"
ECHO: "3"
ECHO: "2"
Or the behavior of children():
module x() {
children(0);
children(0);
children(2);
}
x() {
echo("0");
echo("1");
echo("2");
}
It's not terribly unobvious, but doesn't bear much resemblance to a
conventional language:
ECHO: "0"
ECHO: "0"
ECHO: "2"
Speaking of children, how do assignments and children interact?
module x() {
a = echo("a") 0;
children(0);
b = echo("b") 0;
}
x() {
c = echo("c") 0;
echo("0");
echo("1");
echo("2");
d = echo("d") 0;
}
Did you expect this?
ECHO: "c"
ECHO: "d"
ECHO: "a"
ECHO: "b"
ECHO: "0"
Net, the execution flow in OpenSCAD doesn't look much like what you
would expect from a conventional language. Could a language have the
same goals and be more conventional? Sure. But it's clear that the
internal plumbing of OpenSCAD is very, very different from a
conventional language and it would require a substantial overhaul to
become more conventional.
And I suppose there's a third question:
- Could OpenSCAD be changed to be more conventional, while retaining
compatibility with its current behavior?
Technically, no. One can readily write OpenSCAD programs that would
execute differently in a more conventional language.
One such case is the fact that assignments are processed before module
invocations:
echo(x);
x = 1;
Another is the fact that assigning a value inside a scope creates a new
symbol visible only inside that scope:
x = 1;
if (1 == 1) {
x = 2;
echo(x);
}
echo(x);
yields
ECHO: 2
ECHO: 1
And the fact that when you define an OpenSCAD symbol, the value of the
same-named symbol from the enclosing scope is still visible:
x = 1;
for (i = [0:1]) {
x = x + 1;
echo(x);
}
yields:
ECHO: 2
ECHO: 2
Do people actually use these ... interesting ... cases? I don't know.
But they clearly could, and so true compatibility would not be possible.
Somebody asked how to classify OpenSCAD. My personal model is largely
that it is a macro processing language, that executing an OpenSCAD
program consists of expanding the various macros to form the resulting tree.
One thing that I do wonder is how isolated the language processing is,
inside OpenSCAD. Hypothetically, it seems like the language processing
could be a black box that takes source text as input and returns a
geometry tree as output. If it is such a black box, then perhaps it
would be practical to make it a plug-in, so that one could type Python
into the editor, with an appropriate Python library, and have the
results end up in the viewing window. One could even imagine
cross-language calls that passed parameters and returned geometry.
Let me be clear: that's just a fantasy. I'm not asking the developers
to work on such a thing.
On 5/8/2020 4:58 AM, Rob Ward wrote:
> If it is possible to set up increments/assignments in For loops, why
> not for other variables?
First, I have to note that I know nothing of the internals of OpenSCAD.
However, I have done some black-box exploration of its behavior.
There are two distinct questions there:
* Could there be a language similar to OpenSCAD that has more
"conventional" behavior?
* How hard would it be to change OpenSCAD to behave like such a language?
I think the answer to the first is clearly "yes". One can readily
imagine languages that behave more conventionally. Most likely, one
would just build a CSG library for some existing language like Python or
JavaScript.
The answer to the second question is much trickier. Again, I'm not
familiar with the internals of OpenSCAD, but black-box testing shows
that its behavior is even further from "conventional" than it first appears.
Consider:
x = echo("1") 0;
echo("2");
y = echo("3") 0;
Simple enough, right?
ECHO: "1"
ECHO: "3"
ECHO: "2"
Or the behavior of children():
module x() {
children(0);
children(0);
children(2);
}
x() {
echo("0");
echo("1");
echo("2");
}
It's not terribly unobvious, but doesn't bear much resemblance to a
conventional language:
ECHO: "0"
ECHO: "0"
ECHO: "2"
Speaking of children, how do assignments and children interact?
module x() {
a = echo("a") 0;
children(0);
b = echo("b") 0;
}
x() {
c = echo("c") 0;
echo("0");
echo("1");
echo("2");
d = echo("d") 0;
}
Did you expect this?
ECHO: "c"
ECHO: "d"
ECHO: "a"
ECHO: "b"
ECHO: "0"
Net, the execution flow in OpenSCAD doesn't look much like what you
would expect from a conventional language. Could a language have the
same goals and be more conventional? Sure. But it's clear that the
internal plumbing of OpenSCAD is very, very different from a
conventional language and it would require a substantial overhaul to
become more conventional.
And I suppose there's a third question:
* Could OpenSCAD be changed to be more conventional, while retaining
compatibility with its current behavior?
Technically, no. One can readily write OpenSCAD programs that would
execute differently in a more conventional language.
One such case is the fact that assignments are processed before module
invocations:
echo(x);
x = 1;
Another is the fact that assigning a value inside a scope creates a new
symbol visible only inside that scope:
x = 1;
if (1 == 1) {
x = 2;
echo(x);
}
echo(x);
yields
ECHO: 2
ECHO: 1
And the fact that when you define an OpenSCAD symbol, the value of the
same-named symbol from the enclosing scope is still visible:
x = 1;
for (i = [0:1]) {
x = x + 1;
echo(x);
}
yields:
ECHO: 2
ECHO: 2
Do people actually use these ... interesting ... cases? I don't know.
But they clearly could, and so true compatibility would not be possible.
---
Somebody asked how to classify OpenSCAD. My personal model is largely
that it is a macro processing language, that executing an OpenSCAD
program consists of expanding the various macros to form the resulting tree.
---
One thing that I do wonder is how isolated the language processing is,
inside OpenSCAD. Hypothetically, it seems like the language processing
could be a black box that takes source text as input and returns a
geometry tree as output. If it is such a black box, then perhaps it
would be practical to make it a plug-in, so that one could type Python
into the editor, with an appropriate Python library, and have the
results end up in the viewing window. One could even imagine
cross-language calls that passed parameters and returned geometry.
Let me be clear: that's just a fantasy. I'm not asking the developers
to work on such a thing.
A
arnholm@arnholm.org
Fri, May 8, 2020 6:52 PM
On 2020-05-08 20:00, Jordan Brown wrote:
There are two distinct questions there:
* Could there be a language similar to OpenSCAD that has more
"conventional" behavior?
On 2020-05-08 20:00, Jordan Brown wrote:
> There are two distinct questions there:
>
> * Could there be a language similar to OpenSCAD that has more
> "conventional" behavior?
Yes, AngelCAD is like that, using AngelScript.
https://arnholm.github.io/angelcad-docs/
Carsten Arnholm