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

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

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

kipplebits
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/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

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

JordanBrown
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
tp3
Reply | Threaded
Open this post in threaded view
|

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

tp3
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
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
-- Torsten
Reply | Threaded
Open this post in threaded view
|

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

kipplebits
...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
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions

ciao,
  Torsten.

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

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

Max Bond
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
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions

ciao,
  Torsten.

_______________________________________________
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

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

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

nophead
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
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions

ciao,
  Torsten.

_______________________________________________
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
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

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

alexgibson

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:[hidden email]] 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 <[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
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions

ciao,
  Torsten.

_______________________________________________
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

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

 

Virus-free. www.avg.com

 


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

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

RobWLakes
In reply to this post by nophead
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 <[hidden email]> 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 <[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
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions

ciao,
  Torsten.

_______________________________________________
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
_______________________________________________
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
Rob W
Lake Tyers Beach,
Victoria, Australia
Reply | Threaded
Open this post in threaded view
|

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

JordanBrown
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
Reply | Threaded
Open this post in threaded view
|

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

cacb
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
Reply | Threaded
Open this post in threaded view
|

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

nophead
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
Reply | Threaded
Open this post in threaded view
|

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

kipplebits
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#Children

I'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
Reply | Threaded
Open this post in threaded view
|

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

kipplebits
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:4345994

On 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#Children

I'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
Reply | Threaded
Open this post in threaded view
|

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

Les Caraccioli
In reply to this post by RobWLakes

Please remove my email from all discussions

 

From: Discuss [mailto:[hidden email]] On Behalf Of Rob Ward
Sent: Friday, May 8, 2020 6:59 AM
To: OpenSCAD general discussion; nop head
Subject: Re: [OpenSCAD] 2D SVG concat(points, [point]) no output, loops&conditionals, vector declarations

 

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 <[hidden email]> 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 <[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
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions

ciao,
  Torsten.

_______________________________________________
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

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

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

OpenSCAD mailing list-2
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
Reply | Threaded
Open this post in threaded view
|

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

kipplebits
I posted my little scad file: https://www.thingiverse.com/thing:4354587

It'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 horizontal
for(i=[0:2:length-1]){
    translate(v = [0, i*10, 0]){   
        square(size = [width*10, 10], center = true/false);
    }
}
//or vertical
for(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/numbers
for(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
Reply | Threaded
Open this post in threaded view
|

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

MichaelAtOz
Administrator
> although I'm really just looking for an efficient way to convert to b&w;

I'm not sure what you're doing, but you know you can do custom Color
Schemes?




-----
Admin - email* me if you need anything,  or if I've done something stupid...

* click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

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

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Admin - email* me if you need anything, or if I've done something stupid...
* click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.
Reply | Threaded
Open this post in threaded view
|

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

kipplebits
> you know you can do custom Color Schemes?

doesn't change the output color in the svg, although you did give me an idea to edit the line in my svg stroke="black" fill="lightgrey" stroke-width="0.5"

i changed it to simply fill="black", then open in gimp, upsize DPI, remove alpha-channel,(and perhaps index to black&white), and it actually looks pretty good! it's still a few clicks, although much better than add 2 new layers and path to selection fill b&w then merge layers. ;D



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org