discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Rendering takes very long

KE
Karl Exler
Wed, Mar 1, 2023 2:45 PM

I am newbi and have very less knowledge about rendering. I find the
functions and I habe an idea, very less knowledge about programing, but
I am really happy with the results.

$fn=100;
rd=6;
xn=0.5;
yn=3;
zn=0.8;

difference()
{
linear_extrude(zn*0.99)
circle(r=4);

linear_extrude(zn*1.01)
union()
    {
for (i=[1:45:360])
    rotate(i)
translate([0,2,0])
resize(newsize=[xn,yn,zn]) circle(r=rd);

for (i=[1:45:360])
    rotate(i)
translate([1,2.7,0])
circle(d=0.5);
};
};
This ist a small example for a mandala, which works fine.. as
expected.. But it takes veryl long to render. And therefore I ask if I
could optimize the code in any way.

-in my mind I feel, that always when I use a rotate() and/or a
difference( ) function OpensCad gets really slow.

On the other side I am aware, that I am a bloody beginner.

So perhaps I can receive some hints to get a bit better in programing.

Thank you very much
Karl

I am newbi and have very less knowledge about rendering. I find the functions and I habe an idea, very less knowledge about programing, but I am really happy with the results. $fn=100; rd=6; xn=0.5; yn=3; zn=0.8; difference() { linear_extrude(zn*0.99) circle(r=4); linear_extrude(zn*1.01) union()     { for (i=[1:45:360])     rotate(i) translate([0,2,0]) resize(newsize=[xn,yn,zn]) circle(r=rd); for (i=[1:45:360])     rotate(i) translate([1,2.7,0]) circle(d=0.5); }; }; This ist a small example for a mandala, which works fine.. as expected.. But it takes veryl long to render. And therefore I ask if I could optimize the code in any way. -in my mind I feel, that always when I use a rotate() and/or a difference( ) function OpensCad gets really slow. On the other side I am aware, that I am a bloody beginner. So perhaps I can receive some hints to get a bit better in programing. Thank you very much Karl
FS
FF Systems
Wed, Mar 1, 2023 4:44 PM

I had an epiphany recently that might assist some newcomers (maybe others
too).  OpenSCAD "looks" like software code, but it is really a hardware
definition language (HDL).  As such, it can be difficult for people
(including me) to look at the code and NOT think of it like it is a C
program.  If you look at OpenSCAD code like it is a computer program, you
will often find yourself at odds with what is really going on.

A computer program is a list of machine commands that execute in a
particular order.  The machine state (the contents of the computer's memory
and state of I/O peripherals) generally changes as each machine command is
executed.  This continues until the program is terminated.  Loops and
decisions can make for a very complex program and results that changes each
time the program is executed (depending on the input data).

HDLs don't work that way.  Each command defines a "thing" that then
exists.  Generally, this "thing" is then immutable, but OpenSCAD (and other
HDLs) allow for limited changes (e.g., "difference()" where two or more
"things" can interact to create a new "thing") but in general, once a
"thing" is created, the code is done with it.  You can add or subtract from
this "thing", but then you have a new "thing".  Looping constructs allow us
to create arrays of "things" and these make the code "look" more like
software, but these are just constructs for creating "things" not
calculating constructs for manipulating the machine state (there is no real
analog for "machine state" in an HDL).

So, while experience with software (such as C) can help you manage the
syntax for OpenSCAD, it will mostly serve to confound you as you move into
more and more complex models.

So, don't push too hard on thinking about "programming" while you are
coding OpenSCAD constructs.  Think more along the lines of, "this line of
code creates a "thing" and I am going to use it to add or subtract from the
overall model.  "for" loops are just a means to create a lot of "things"
with just a few lines of code.

Cheers,

Joe

On Wed, Mar 1, 2023 at 8:45 AM Karl Exler karl.exler@meinklang.cc wrote:

I am newbi and have very less knowledge about rendering. I find the
functions and I habe an idea, very less knowledge about programing, but I
am really happy with the results.

$fn=100;
rd=6;
xn=0.5;
yn=3;
zn=0.8;

difference()
{
linear_extrude(zn*0.99)
circle(r=4);

linear_extrude(zn*1.01)
union()
{
for (i=[1:45:360])
rotate(i)
translate([0,2,0])
resize(newsize=[xn,yn,zn]) circle(r=rd);

for (i=[1:45:360])
rotate(i)
translate([1,2.7,0])
circle(d=0.5);
};
};
This ist a small example for a mandala, which works fine.. as expected..
But it takes veryl long to render. And therefore I ask if I could optimize
the code in any way.

-in my mind I feel, that always when I use a rotate() and/or a difference(
) function OpensCad gets really slow.

On the other side I am aware, that I am a bloody beginner.

So perhaps I can receive some hints to get a bit better in programing.

Thank you very much
Karl


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

I had an epiphany recently that might assist some newcomers (maybe others too). OpenSCAD "looks" like software code, but it is really a hardware definition language (HDL). As such, it can be difficult for people (including me) to look at the code and NOT think of it like it is a C program. If you look at OpenSCAD code like it is a computer program, you will often find yourself at odds with what is really going on. A computer program is a list of machine commands that execute in a particular order. The machine state (the contents of the computer's memory and state of I/O peripherals) generally changes as each machine command is executed. This continues until the program is terminated. Loops and decisions can make for a very complex program and results that changes each time the program is executed (depending on the input data). HDLs don't work that way. Each command defines a "thing" that then exists. Generally, this "thing" is then immutable, but OpenSCAD (and other HDLs) allow for limited changes (e.g., "difference()" where two or more "things" can interact to create a new "thing") but in general, once a "thing" is created, the code is done with it. You can add or subtract from this "thing", but then you have a new "thing". Looping constructs allow us to create arrays of "things" and these make the code "look" more like software, but these are just constructs for creating "things" not calculating constructs for manipulating the machine state (there is no real analog for "machine state" in an HDL). So, while experience with software (such as C) can help you manage the syntax for OpenSCAD, it will mostly serve to confound you as you move into more and more complex models. So, don't push too hard on thinking about "programming" while you are coding OpenSCAD constructs. Think more along the lines of, "this line of code creates a "thing" and I am going to use it to add or subtract from the overall model. "for" loops are just a means to create a lot of "things" with just a few lines of code. Cheers, Joe On Wed, Mar 1, 2023 at 8:45 AM Karl Exler <karl.exler@meinklang.cc> wrote: > I am newbi and have very less knowledge about rendering. I find the > functions and I habe an idea, very less knowledge about programing, but I > am really happy with the results. > > > $fn=100; > rd=6; > xn=0.5; > yn=3; > zn=0.8; > > > difference() > { > linear_extrude(zn*0.99) > circle(r=4); > > linear_extrude(zn*1.01) > union() > { > for (i=[1:45:360]) > rotate(i) > translate([0,2,0]) > resize(newsize=[xn,yn,zn]) circle(r=rd); > > for (i=[1:45:360]) > rotate(i) > translate([1,2.7,0]) > circle(d=0.5); > }; > }; > This ist a small example for a mandala, which works fine.. as expected.. > But it takes veryl long to render. And therefore I ask if I could optimize > the code in any way. > > -in my mind I feel, that always when I use a rotate() and/or a difference( > ) function OpensCad gets really slow. > > On the other side I am aware, that I am a bloody beginner. > > So perhaps I can receive some hints to get a bit better in programing. > > Thank you very much > Karl > > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
FH
Father Horton
Wed, Mar 1, 2023 5:32 PM

An alternative way to look at it is that OpenSCAD is largely based on a
functional programming paradigm. For those of us who learned to program in
imperative/procedural languages, it’s a real mental adjustment.

On Wed, Mar 1, 2023 at 10:49 AM FF Systems joeh@rollanet.org wrote:

I had an epiphany recently that might assist some newcomers (maybe others
too).  OpenSCAD "looks" like software code, but it is really a hardware
definition language (HDL).  As such, it can be difficult for people
(including me) to look at the code and NOT think of it like it is a C
program.  If you look at OpenSCAD code like it is a computer program, you
will often find yourself at odds with what is really going on.

A computer program is a list of machine commands that execute in a
particular order.  The machine state (the contents of the computer's memory
and state of I/O peripherals) generally changes as each machine command is
executed.  This continues until the program is terminated.  Loops and
decisions can make for a very complex program and results that changes each
time the program is executed (depending on the input data).

HDLs don't work that way.  Each command defines a "thing" that then
exists.  Generally, this "thing" is then immutable, but OpenSCAD (and other
HDLs) allow for limited changes (e.g., "difference()" where two or more
"things" can interact to create a new "thing") but in general, once a
"thing" is created, the code is done with it.  You can add or subtract from
this "thing", but then you have a new "thing".  Looping constructs allow us
to create arrays of "things" and these make the code "look" more like
software, but these are just constructs for creating "things" not
calculating constructs for manipulating the machine state (there is no real
analog for "machine state" in an HDL).

So, while experience with software (such as C) can help you manage the
syntax for OpenSCAD, it will mostly serve to confound you as you move into
more and more complex models.

So, don't push too hard on thinking about "programming" while you are
coding OpenSCAD constructs.  Think more along the lines of, "this line of
code creates a "thing" and I am going to use it to add or subtract from the
overall model.  "for" loops are just a means to create a lot of "things"
with just a few lines of code.

Cheers,

Joe

On Wed, Mar 1, 2023 at 8:45 AM Karl Exler karl.exler@meinklang.cc wrote:

I am newbi and have very less knowledge about rendering. I find the
functions and I habe an idea, very less knowledge about programing, but I
am really happy with the results.

$fn=100;
rd=6;
xn=0.5;
yn=3;
zn=0.8;

difference()
{
linear_extrude(zn*0.99)
circle(r=4);

linear_extrude(zn*1.01)
union()
{
for (i=[1:45:360])
rotate(i)
translate([0,2,0])
resize(newsize=[xn,yn,zn]) circle(r=rd);

for (i=[1:45:360])
rotate(i)
translate([1,2.7,0])
circle(d=0.5);
};
};
This ist a small example for a mandala, which works fine.. as expected..
But it takes veryl long to render. And therefore I ask if I could optimize
the code in any way.

-in my mind I feel, that always when I use a rotate() and/or a
difference( ) function OpensCad gets really slow.

On the other side I am aware, that I am a bloody beginner.

So perhaps I can receive some hints to get a bit better in programing.

Thank you very much
Karl


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


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

An alternative way to look at it is that OpenSCAD is largely based on a functional programming paradigm. For those of us who learned to program in imperative/procedural languages, it’s a real mental adjustment. On Wed, Mar 1, 2023 at 10:49 AM FF Systems <joeh@rollanet.org> wrote: > I had an epiphany recently that might assist some newcomers (maybe others > too). OpenSCAD "looks" like software code, but it is really a hardware > definition language (HDL). As such, it can be difficult for people > (including me) to look at the code and NOT think of it like it is a C > program. If you look at OpenSCAD code like it is a computer program, you > will often find yourself at odds with what is really going on. > > A computer program is a list of machine commands that execute in a > particular order. The machine state (the contents of the computer's memory > and state of I/O peripherals) generally changes as each machine command is > executed. This continues until the program is terminated. Loops and > decisions can make for a very complex program and results that changes each > time the program is executed (depending on the input data). > > HDLs don't work that way. Each command defines a "thing" that then > exists. Generally, this "thing" is then immutable, but OpenSCAD (and other > HDLs) allow for limited changes (e.g., "difference()" where two or more > "things" can interact to create a new "thing") but in general, once a > "thing" is created, the code is done with it. You can add or subtract from > this "thing", but then you have a new "thing". Looping constructs allow us > to create arrays of "things" and these make the code "look" more like > software, but these are just constructs for creating "things" not > calculating constructs for manipulating the machine state (there is no real > analog for "machine state" in an HDL). > > So, while experience with software (such as C) can help you manage the > syntax for OpenSCAD, it will mostly serve to confound you as you move into > more and more complex models. > > So, don't push too hard on thinking about "programming" while you are > coding OpenSCAD constructs. Think more along the lines of, "this line of > code creates a "thing" and I am going to use it to add or subtract from the > overall model. "for" loops are just a means to create a lot of "things" > with just a few lines of code. > > Cheers, > > Joe > > > On Wed, Mar 1, 2023 at 8:45 AM Karl Exler <karl.exler@meinklang.cc> wrote: > >> I am newbi and have very less knowledge about rendering. I find the >> functions and I habe an idea, very less knowledge about programing, but I >> am really happy with the results. >> >> >> $fn=100; >> rd=6; >> xn=0.5; >> yn=3; >> zn=0.8; >> >> >> difference() >> { >> linear_extrude(zn*0.99) >> circle(r=4); >> >> linear_extrude(zn*1.01) >> union() >> { >> for (i=[1:45:360]) >> rotate(i) >> translate([0,2,0]) >> resize(newsize=[xn,yn,zn]) circle(r=rd); >> >> for (i=[1:45:360]) >> rotate(i) >> translate([1,2.7,0]) >> circle(d=0.5); >> }; >> }; >> This ist a small example for a mandala, which works fine.. as expected.. >> But it takes veryl long to render. And therefore I ask if I could optimize >> the code in any way. >> >> -in my mind I feel, that always when I use a rotate() and/or a >> difference( ) function OpensCad gets really slow. >> >> On the other side I am aware, that I am a bloody beginner. >> >> So perhaps I can receive some hints to get a bit better in programing. >> >> Thank you very much >> Karl >> >> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
SL
Steve Lelievre
Wed, Mar 1, 2023 5:58 PM

I think of an OpenSCAD model as a tree - just a list of objects, some of
which that themselves lists of objects. The branches are sometimes made by
adding, sometimes by subtracting, sometimes by various distortions of the
basic shapes.

That’s probably the same as Joe’s HDL but without the technical awareness.

Steve

On Wed, Mar 1, 2023 at 08:50, FF Systems joeh@rollanet.org wrote:

I had an epiphany recently that might assist some newcomers (maybe others
too).  OpenSCAD "looks" like software code, but it is really a hardware
definition language (HDL).  As such, it can be difficult for people
(including me) to look at the code and NOT think of it like it is a C
program.  If you look at OpenSCAD code like it is a computer program, you
will often find yourself at odds with what is really going on.

A computer program is a list of machine commands that execute in a
particular order.  The machine state (the contents of the computer's memory
and state of I/O peripherals) generally changes as each machine command is
executed.  This continues until the program is terminated.  Loops and
decisions can make for a very complex program and results that changes each
time the program is executed (depending on the input data).

HDLs don't work that way.  Each command defines a "thing" that then
exists.  Generally, this "thing" is then immutable, but OpenSCAD (and other
HDLs) allow for limited changes (e.g., "difference()" where two or more
"things" can interact to create a new "thing") but in general, once a
"thing" is created, the code is done with it.  You can add or subtract from
this "thing", but then you have a new "thing".  Looping constructs allow us
to create arrays of "things" and these make the code "look" more like
software, but these are just constructs for creating "things" not
calculating constructs for manipulating the machine state (there is no real
analog for "machine state" in an HDL).

So, while experience with software (such as C) can help you manage the
syntax for OpenSCAD, it will mostly serve to confound you as you move into
more and more complex models.

So, don't push too hard on thinking about "programming" while you are
coding OpenSCAD constructs.  Think more along the lines of, "this line of
code creates a "thing" and I am going to use it to add or subtract from the
overall model.  "for" loops are just a means to create a lot of "things"
with just a few lines of code.

Cheers,

Joe

On Wed, Mar 1, 2023 at 8:45 AM Karl Exler karl.exler@meinklang.cc wrote:

I am newbi and have very less knowledge about rendering. I find the
functions and I habe an idea, very less knowledge about programing, but I
am really happy with the results.

$fn=100;
rd=6;
xn=0.5;
yn=3;
zn=0.8;

difference()
{
linear_extrude(zn*0.99)
circle(r=4);

linear_extrude(zn*1.01)
union()
{
for (i=[1:45:360])
rotate(i)
translate([0,2,0])
resize(newsize=[xn,yn,zn]) circle(r=rd);

for (i=[1:45:360])
rotate(i)
translate([1,2.7,0])
circle(d=0.5);
};
};
This ist a small example for a mandala, which works fine.. as expected..
But it takes veryl long to render. And therefore I ask if I could optimize
the code in any way.

-in my mind I feel, that always when I use a rotate() and/or a
difference( ) function OpensCad gets really slow.

On the other side I am aware, that I am a bloody beginner.

So perhaps I can receive some hints to get a bit better in programing.

Thank you very much
Karl


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


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

--
Cell +1 778 837 5771

I think of an OpenSCAD model as a tree - just a list of objects, some of which that themselves lists of objects. The branches are sometimes made by adding, sometimes by subtracting, sometimes by various distortions of the basic shapes. That’s probably the same as Joe’s HDL but without the technical awareness. Steve On Wed, Mar 1, 2023 at 08:50, FF Systems <joeh@rollanet.org> wrote: > I had an epiphany recently that might assist some newcomers (maybe others > too). OpenSCAD "looks" like software code, but it is really a hardware > definition language (HDL). As such, it can be difficult for people > (including me) to look at the code and NOT think of it like it is a C > program. If you look at OpenSCAD code like it is a computer program, you > will often find yourself at odds with what is really going on. > > A computer program is a list of machine commands that execute in a > particular order. The machine state (the contents of the computer's memory > and state of I/O peripherals) generally changes as each machine command is > executed. This continues until the program is terminated. Loops and > decisions can make for a very complex program and results that changes each > time the program is executed (depending on the input data). > > HDLs don't work that way. Each command defines a "thing" that then > exists. Generally, this "thing" is then immutable, but OpenSCAD (and other > HDLs) allow for limited changes (e.g., "difference()" where two or more > "things" can interact to create a new "thing") but in general, once a > "thing" is created, the code is done with it. You can add or subtract from > this "thing", but then you have a new "thing". Looping constructs allow us > to create arrays of "things" and these make the code "look" more like > software, but these are just constructs for creating "things" not > calculating constructs for manipulating the machine state (there is no real > analog for "machine state" in an HDL). > > So, while experience with software (such as C) can help you manage the > syntax for OpenSCAD, it will mostly serve to confound you as you move into > more and more complex models. > > So, don't push too hard on thinking about "programming" while you are > coding OpenSCAD constructs. Think more along the lines of, "this line of > code creates a "thing" and I am going to use it to add or subtract from the > overall model. "for" loops are just a means to create a lot of "things" > with just a few lines of code. > > Cheers, > > Joe > > > On Wed, Mar 1, 2023 at 8:45 AM Karl Exler <karl.exler@meinklang.cc> wrote: > >> I am newbi and have very less knowledge about rendering. I find the >> functions and I habe an idea, very less knowledge about programing, but I >> am really happy with the results. >> >> >> $fn=100; >> rd=6; >> xn=0.5; >> yn=3; >> zn=0.8; >> >> >> difference() >> { >> linear_extrude(zn*0.99) >> circle(r=4); >> >> linear_extrude(zn*1.01) >> union() >> { >> for (i=[1:45:360]) >> rotate(i) >> translate([0,2,0]) >> resize(newsize=[xn,yn,zn]) circle(r=rd); >> >> for (i=[1:45:360]) >> rotate(i) >> translate([1,2.7,0]) >> circle(d=0.5); >> }; >> }; >> This ist a small example for a mandala, which works fine.. as expected.. >> But it takes veryl long to render. And therefore I ask if I could optimize >> the code in any way. >> >> -in my mind I feel, that always when I use a rotate() and/or a >> difference( ) function OpensCad gets really slow. >> >> On the other side I am aware, that I am a bloody beginner. >> >> So perhaps I can receive some hints to get a bit better in programing. >> >> Thank you very much >> Karl >> >> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > -- Cell +1 778 837 5771
JB
Jordan Brown
Wed, Mar 1, 2023 6:02 PM

The biggest piece of advice is that $fn=100 is very large, especially
when you are making circles that are only 0.5 in diameter.  That's
making segments that are only 0.015.  Even if you're working in inches
(which you probably shouldn't, because slicers default to millimeters)
that's really small.

I don't personally use $fn to control circles.  I use $fn to create
regular polygons.  To control circles I use $fa and $fs, which adjust
the number of sides based on the size of the circle.  $fa=1 is plenty
fine for even large circles, and $fs=0.5 (in millimeters) is about as
fine as you will get from a 3D printer anyway.

Oh, and don't use resize.  It's probably fine here but in general is
slow to preview.  Instead use scale().  Here, use

scale([xn,yn,zn]) circle(d=1);

and... see that shimmery stuff on the bottom?  That's because your
negative object doesn't protrude below the bottom of the thing you're
subtracting from.  Either translate it down a smidge, or set center=true
on both linear extrudes.

Also, the explicit union is unnecessary but harmless.  Except for
obvious exceptions like intersection and difference, children of
OpenSCAD operations are unioned by default.

The biggest piece of advice is that $fn=100 is very large, especially when you are making circles that are only 0.5 in diameter.  That's making segments that are only 0.015.  Even if you're working in inches (which you probably shouldn't, because slicers default to millimeters) that's really small. I don't personally use $fn to control circles.  I use $fn to create regular polygons.  To control circles I use $fa and $fs, which adjust the number of sides based on the size of the circle.  $fa=1 is plenty fine for even large circles, and $fs=0.5 (in millimeters) is about as fine as you will get from a 3D printer anyway. Oh, and don't use resize.  It's probably fine here but in general is slow to preview.  Instead use scale().  Here, use scale([xn,yn,zn]) circle(d=1); and... see that shimmery stuff on the bottom?  That's because your negative object doesn't protrude below the bottom of the thing you're subtracting from.  Either translate it down a smidge, or set center=true on both linear extrudes. Also, the explicit union is unnecessary but harmless.  Except for obvious exceptions like intersection and difference, children of OpenSCAD operations are unioned by default.
MM
Michael Möller
Wed, Mar 1, 2023 7:49 PM

Indeed, indeed ....

"But" there are differences in how you create things.

linear_extrude() circle() ;
vs.
cylinder() ;
for example. On one hand it is better to do (lots of) join operations in 2D
and then linear_extrude (appropriate for this "coin") rather than do all
sub-elements in 3D and join. But it depends on the individual case.

Michael, fra mobilen

ons. 1. mar. 2023 17.49 skrev FF Systems joeh@rollanet.org:

I had an epiphany recently that might assist some newcomers (maybe others
too).  OpenSCAD "looks" like software code, but it is really a hardware
definition language (HDL).  As such, it can be difficult for people
(including me) to look at the code and NOT think of it like it is a C
program.  If you look at OpenSCAD code like it is a computer program, you
will often find yourself at odds with what is really going on.

A computer program is a list of machine commands that execute in a
particular order.  The machine state (the contents of the computer's memory
and state of I/O peripherals) generally changes as each machine command is
executed.  This continues until the program is terminated.  Loops and
decisions can make for a very complex program and results that changes each
time the program is executed (depending on the input data).

HDLs don't work that way.  Each command defines a "thing" that then
exists.  Generally, this "thing" is then immutable, but OpenSCAD (and other
HDLs) allow for limited changes (e.g., "difference()" where two or more
"things" can interact to create a new "thing") but in general, once a
"thing" is created, the code is done with it.  You can add or subtract from
this "thing", but then you have a new "thing".  Looping constructs allow us
to create arrays of "things" and these make the code "look" more like
software, but these are just constructs for creating "things" not
calculating constructs for manipulating the machine state (there is no real
analog for "machine state" in an HDL).

So, while experience with software (such as C) can help you manage the
syntax for OpenSCAD, it will mostly serve to confound you as you move into
more and more complex models.

So, don't push too hard on thinking about "programming" while you are
coding OpenSCAD constructs.  Think more along the lines of, "this line of
code creates a "thing" and I am going to use it to add or subtract from the
overall model.  "for" loops are just a means to create a lot of "things"
with just a few lines of code.

Cheers,

Joe

On Wed, Mar 1, 2023 at 8:45 AM Karl Exler karl.exler@meinklang.cc wrote:

I am newbi and have very less knowledge about rendering. I find the
functions and I habe an idea, very less knowledge about programing, but I
am really happy with the results.

$fn=100;
rd=6;
xn=0.5;
yn=3;
zn=0.8;

difference()
{
linear_extrude(zn*0.99)
circle(r=4);

linear_extrude(zn*1.01)
union()
{
for (i=[1:45:360])
rotate(i)
translate([0,2,0])
resize(newsize=[xn,yn,zn]) circle(r=rd);

for (i=[1:45:360])
rotate(i)
translate([1,2.7,0])
circle(d=0.5);
};
};
This ist a small example for a mandala, which works fine.. as expected..
But it takes veryl long to render. And therefore I ask if I could optimize
the code in any way.

-in my mind I feel, that always when I use a rotate() and/or a
difference( ) function OpensCad gets really slow.

On the other side I am aware, that I am a bloody beginner.

So perhaps I can receive some hints to get a bit better in programing.

Thank you very much
Karl


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


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

Indeed, indeed .... "But" there are differences in how you create things. linear_extrude() circle() ; vs. cylinder() ; for example. On one hand it is better to do (lots of) join operations in 2D and then linear_extrude (appropriate for this "coin") rather than do all sub-elements in 3D and join. But it depends on the individual case. Michael, fra mobilen ons. 1. mar. 2023 17.49 skrev FF Systems <joeh@rollanet.org>: > I had an epiphany recently that might assist some newcomers (maybe others > too). OpenSCAD "looks" like software code, but it is really a hardware > definition language (HDL). As such, it can be difficult for people > (including me) to look at the code and NOT think of it like it is a C > program. If you look at OpenSCAD code like it is a computer program, you > will often find yourself at odds with what is really going on. > > A computer program is a list of machine commands that execute in a > particular order. The machine state (the contents of the computer's memory > and state of I/O peripherals) generally changes as each machine command is > executed. This continues until the program is terminated. Loops and > decisions can make for a very complex program and results that changes each > time the program is executed (depending on the input data). > > HDLs don't work that way. Each command defines a "thing" that then > exists. Generally, this "thing" is then immutable, but OpenSCAD (and other > HDLs) allow for limited changes (e.g., "difference()" where two or more > "things" can interact to create a new "thing") but in general, once a > "thing" is created, the code is done with it. You can add or subtract from > this "thing", but then you have a new "thing". Looping constructs allow us > to create arrays of "things" and these make the code "look" more like > software, but these are just constructs for creating "things" not > calculating constructs for manipulating the machine state (there is no real > analog for "machine state" in an HDL). > > So, while experience with software (such as C) can help you manage the > syntax for OpenSCAD, it will mostly serve to confound you as you move into > more and more complex models. > > So, don't push too hard on thinking about "programming" while you are > coding OpenSCAD constructs. Think more along the lines of, "this line of > code creates a "thing" and I am going to use it to add or subtract from the > overall model. "for" loops are just a means to create a lot of "things" > with just a few lines of code. > > Cheers, > > Joe > > > On Wed, Mar 1, 2023 at 8:45 AM Karl Exler <karl.exler@meinklang.cc> wrote: > >> I am newbi and have very less knowledge about rendering. I find the >> functions and I habe an idea, very less knowledge about programing, but I >> am really happy with the results. >> >> >> $fn=100; >> rd=6; >> xn=0.5; >> yn=3; >> zn=0.8; >> >> >> difference() >> { >> linear_extrude(zn*0.99) >> circle(r=4); >> >> linear_extrude(zn*1.01) >> union() >> { >> for (i=[1:45:360]) >> rotate(i) >> translate([0,2,0]) >> resize(newsize=[xn,yn,zn]) circle(r=rd); >> >> for (i=[1:45:360]) >> rotate(i) >> translate([1,2.7,0]) >> circle(d=0.5); >> }; >> }; >> This ist a small example for a mandala, which works fine.. as expected.. >> But it takes veryl long to render. And therefore I ask if I could optimize >> the code in any way. >> >> -in my mind I feel, that always when I use a rotate() and/or a >> difference( ) function OpensCad gets really slow. >> >> On the other side I am aware, that I am a bloody beginner. >> >> So perhaps I can receive some hints to get a bit better in programing. >> >> Thank you very much >> Karl >> >> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
JB
Jordan Brown
Fri, Mar 3, 2023 5:18 AM

On 3/1/2023 9:58 AM, Steve Lelievre wrote:

I think of an OpenSCAD model as a tree - just a list of objects, some
of which that themselves lists of objects. The branches are sometimes
made by adding, sometimes by subtracting, sometimes by various
distortions of the basic shapes.

I would say that that, the CSG tree, is the intermediate form.

A simple OpenSCAD program directly represents the CSG tree...

difference() {
    sphere();
    cube();
}

A more complex OpenSCAD program is a proper program, that generates
the CSG tree.

sep = 30;
d = 20;
n = 10;

function coinflip() = rands(0,1,1)[0] < 0.5;

for (x=[1:n], y=[1:n]) {
    if (coinflip()) {
        translate([x,y]*sep) sphere(d=d);
    }
}

For those who do not think that OpenSCAD is a programming language... I
have implementations of Life and Tic-Tac-Toe written in OpenSCAD.  The
Life implementation is door #19 in the 2022 advent calendar
https://openscad.org/advent-calendar-2022/.

On 3/1/2023 9:58 AM, Steve Lelievre wrote: > I think of an OpenSCAD model as a tree - just a list of objects, some > of which that themselves lists of objects. The branches are sometimes > made by adding, sometimes by subtracting, sometimes by various > distortions of the basic shapes. I would say that that, the CSG tree, is the intermediate form. A simple OpenSCAD program directly represents the CSG tree... difference() { sphere(); cube(); } A more complex OpenSCAD program *is* a proper program, that *generates* the CSG tree. sep = 30; d = 20; n = 10; function coinflip() = rands(0,1,1)[0] < 0.5; for (x=[1:n], y=[1:n]) { if (coinflip()) { translate([x,y]*sep) sphere(d=d); } } For those who do not think that OpenSCAD is a programming language... I have implementations of Life and Tic-Tac-Toe written in OpenSCAD.  The Life implementation is door #19 in the 2022 advent calendar <https://openscad.org/advent-calendar-2022/>.