# 2D SVG concat(points, [point]) no output, loops&conditionals, vector declarations

18 messages
Open this post in threaded view
|

## 2D SVG concat(points, [point]) no output, loops&conditionals, vector declarations

Open this post in threaded view
|

## Re: 2D SVG concat(points, [point]) no output, loops&conditionals, vector declarations

 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. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: 2D SVG concat(points, [point]) no output, loops&conditionals, vector declarations

 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_Comprehensionsciao,   Torsten. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- Torsten
Open this post in threaded view
|

## Re: 2D SVG concat(points, [point]) no output, loops&conditionals, vector declarations

Open this post in threaded view
|

## Re: 2D SVG concat(points, [point]) no output, loops&conditionals, vector declarations

Open this post in threaded view
|

## Re: 2D SVG concat(points, [point]) no output, loops&conditionals, vector declarations

Open this post in threaded view
|

## Re: 2D SVG concat(points, [point]) no output, loops&conditionals, vector declarations

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

edumaker limited

·         Project management

·         Operations & Process improvement

·         3D Printing

From: Discuss [mailto:[hidden email]] On Behalf Of nop head
Sent: 08 May 2020 11:32
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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

ciao,
Torsten.

_______________________________________________
[hidden email]

_______________________________________________
[hidden email]

_______________________________________________
[hidden email]

 Virus-free. www.avg.com

_______________________________________________
[hidden email]
Open this post in threaded view
|

## Re: 2D SVG concat(points, [point]) no output, loops&conditionals, vector declarations

Open this post in threaded view
|

## Re: 2D SVG concat(points, [point]) no output, loops&conditionals, vector declarations

 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. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: 2D SVG concat(points, [point]) no output, loops&conditionals, vector declarations

 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 _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: 2D SVG concat(points, [point]) no output, loops&conditionals, vector declarations

 There are also Python fronts ends for OpenSCAD for people who prefer to describe objects in Python.On Fri, 8 May 2020 at 19:53, <[hidden email]> wrote: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 _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: 2D SVG concat(points, [point]) no output, loops&conditionals, vector declarations

 In reply to this post by JordanBrown Thanks Jordan, that's very interesting! maybe I will read up more on chldren: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/User-Defined_Functions_and_Modules#ChildrenI'm pretty sure I'll be able to build whatever shape i want now. Also i think adding while loops is probably counter productive; I think I was just stuck in the wrong mind frame. I like the new release(2019.05)! Everything is better-than-ever(once i figured out how to turn off sound notifications and mouse centric zoom)! ;) On Fri, May 8, 2020 at 2:01 PM Jordan Brown <[hidden email]> wrote: 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. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: 2D SVG concat(points, [point]) no output, loops&conditionals, vector declarations

 By the way, perhaps people might be curious about what I'm actually trying to fabricate(it's face masks): https://www.thingiverse.com/thing:4345994On Fri, May 8, 2020 at 3:18 PM kipple bits <[hidden email]> wrote:Thanks Jordan, that's very interesting! maybe I will read up more on chldren: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/User-Defined_Functions_and_Modules#ChildrenI'm pretty sure I'll be able to build whatever shape i want now. Also i think adding while loops is probably counter productive; I think I was just stuck in the wrong mind frame. I like the new release(2019.05)! Everything is better-than-ever(once i figured out how to turn off sound notifications and mouse centric zoom)! ;) On Fri, May 8, 2020 at 2:01 PM Jordan Brown <[hidden email]> wrote: 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. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: 2D SVG concat(points, [point]) no output, loops&conditionals, vector declarations

Open this post in threaded view
|

## Re: 2D SVG concat(points, [point]) no output, loops&conditionals, vector declarations

 For the 2D angle there are a number of other tools to try/consider:  - Processing  - Nodebox  - Metapost (and its derivatives such as TikZ, Asymptote, &c.)  - Maker.js -- this is oriented towards CAM another successor tool would (eventually?) be RapCAD. A newer tool I'm investigating is CADquery. That said, I'm kind of wedded to OpenSCAD since I really like the BlockSCAD environment --- OpenJSCAD has a similar one though. William _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: 2D SVG concat(points, [point]) no output, loops&conditionals, vector declarations

 I posted my little scad file: https://www.thingiverse.com/thing:4354587It's not very complex, but then it's kind of a pain if you mess up and overshoot, so maybe it could be helpful to someone. width = 34;length = 48;xremainder = 4;yremainder = 5;/*//either horizontalfor(i=[0:2:length-1]){    translate(v = [0, i*10, 0]){           square(size = [width*10, 10], center = true/false);    }}//or verticalfor(i=[0:2:width-1]){    translate(v = [i*10, 0, 0]){           square(size = [10, length*10], center = true/false);    }}*///perimeter nearest cm//square(size = [10*width, 10*length]);// full perimeter nearest mm//square(size = [10*width+xremainder, 10*length+yremainder]);//full area offset for safety check/*translate(v = [0, 0, -10]) {    square(size = [10*width, 10*length]);}*///scale/numbersfor(i=[0:2:width-1]){    translate([i*10+1, 10, 0]) {text(str(i));}}for(i=[0:2:length-1]){    translate([10, i*10+1, 0]) {text(str(i));}lasergrbl had some troubles importing svg, so I ended up converting to black&white png, using GIMP. I'll have to check out some of William's suggestions, although I'm really just looking for an efficient way to convert to b&w; maybe batch-mode or gimp-scripting/automated-editing...? ...or maybe there's something to be done as far as lasergrbl svg support? ...anyway, the latest build of openSCAD is working well for me, keep up the good work!  _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org