Tool like OpenSCAD, but for 2D images?

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

Tool like OpenSCAD, but for 2D images?

Troberg
I know this is somewhat off topic, but I've found that people who don't know
what OpenSCAD is don't even understand what I'm asking, and I only get "You
can do that in photoshop" or "Why would you need that?" when asking in other
places, and I thought the issue might interest OpenSCAD users.

I'm looking for something like OpenSCAD, but for creating 2D images using a
script.

This would be useful for geometric shapes or parametric designs. Say, for
example, that I want to make an image with a railroad track running in an
oval around a parameterized text. Simple scaling wouldn't do, since the
track would get strange proportions. However, with some scripting, it would
be trivial to draw a track that fits the text.

OpenSCAD, while nice, doesn't really do 2D images that looks nice, it's more
about "here be stuff, here be nothing" which is suitable for later
3D-printing.

Any ideas?



--
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: Tool like OpenSCAD, but for 2D images?

moshel
I have been looking for something like this as well in the past month.
Openscad is also not very good for 2.5d as its pretty hard to draw lines on
a face (or at least I couldn't find a way).
Closest i could find were "parametric" cads, like freecad. It also have
openscad import. I know its not what you are looking for.

Would be very happy if there is one that I missed



--
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: Tool like OpenSCAD, but for 2D images?

fractorr
In reply to this post by Troberg
Sounds like SVG might work for what you described.


On October 20, 2017 12:28:27 AM Troberg <[hidden email]> wrote:

> I know this is somewhat off topic, but I've found that people who don't know
> what OpenSCAD is don't even understand what I'm asking, and I only get "You
> can do that in photoshop" or "Why would you need that?" when asking in other
> places, and I thought the issue might interest OpenSCAD users.
>
> I'm looking for something like OpenSCAD, but for creating 2D images using a
> script.
>
> This would be useful for geometric shapes or parametric designs. Say, for
> example, that I want to make an image with a railroad track running in an
> oval around a parameterized text. Simple scaling wouldn't do, since the
> track would get strange proportions. However, with some scripting, it would
> be trivial to draw a track that fits the text.
>
> OpenSCAD, while nice, doesn't really do 2D images that looks nice, it's more
> about "here be stuff, here be nothing" which is suitable for later
> 3D-printing.
>
> Any ideas?
>
>
>
> --
> Sent from: http://forum.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: Tool like OpenSCAD, but for 2D images?

Eric Buijs
In reply to this post by moshel
The beauty of OpenSCAD is that it's easy to add functionality. If you want to
draw 2d lines just write a module, for example:

//line module draws a 2D line from p1 to p2
module line(p1,p2,w) {
    hull() {
        translate(p1) circle(r=w,$fn=20);
        translate(p2) circle(r=w,$fn=20);
    }
}

line([3,1],[5,4]);

If you want to have a polyline just add another module. For example.

//random points for demonstration purposes
p0=[-4,8];
p1=[2,7];
p2=[6,12];
p3=[8,24];
p4=[10,12];

points=[p0,p1,p2,p3,p4];

//line module draws a 2D line from p1 to p2
module line(p1,p2,w) {
    hull() {
        translate(p1) circle(r=w,$fn=20);
        translate(p2) circle(r=w,$fn=20);
    }
}

//polyline is a recursive module that to draw lines between all points in de
list of points.
module polyline(points, index, w) {
        if(index < len(points)) {
            line(points[index - 1], points[index],w);
            polyline(points, index + 1,w);
        }
    }

polyline(points,1,0.5);

So I think it's entirely possible to do a railroad track around a
parameterized text and scale it. Here is a link to OpenSCAD articles by
Justin Lin <https://openhome.cc/eGossip/OpenSCAD/index.html>  . He's done
several 2D projects like bezier curves and turtle graphics in OpenSCAD just
by adding functionality. Hopefully it provides inspiration to create your
project.



--
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: Tool like OpenSCAD, but for 2D images?

cacb
In reply to this post by Troberg
On 2017-10-20 09:27, Troberg wrote:
> I'm looking for something like OpenSCAD, but for creating 2D images
> using a
> script.

It is not really clear what you are after, but you can create 2d objects
and use boolean operations on them in OpenSCAD, and you can export that
as e.g. DXF to visualise somewhere else.

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: Tool like OpenSCAD, but for 2D images?

Troberg
I'd say that what I'm looking for is something like "script controlled
PaintShop", much like one could say that OpenSCAD is a "script controlled
SketchUp" (and don't nitpick that definition, I'm just trying to get a
general idea across here...).



--
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: Tool like OpenSCAD, but for 2D images?

William Adams-2
If I understand what you're asking, the TeX community has a number of tools for 2D drawing:

 - METAFONT/METAPOST
 - Tikz
 - psedit
 - Asymptote

and of course, one can just use raw PostScript: http://www.math.ubc.ca/~cass/graphics/manual/
 
There's also Nodebox and Processing or node.js or the various JavaScript SVG libraries.



On Fri, Oct 20, 2017 at 7:06 AM, Troberg <[hidden email]> wrote:
I'd say that what I'm looking for is something like "script controlled
PaintShop", much like one could say that OpenSCAD is a "script controlled
SketchUp" (and don't nitpick that definition, I'm just trying to get a
general idea across here...).



--
Sent from: http://forum.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: Tool like OpenSCAD, but for 2D images?

shadowwynd
In reply to this post by Troberg
The issue has to do with OpenSCAD's top-level union, which is automatically
applied.  This means it can do 3D well, 2.5D with limitations (great as long
as the "D" are the same (e.g. a plate with holes and slots)), and is very
poor at 2D.

Let's say we want a cylinder, with a half-hollowed cylinder and an
axle-hole.

Here is the OpenSCAD code to create this shape (great if using a 3D
printer):

difference()
{
        cylinder (d=50, h=20);
        translate ([0, 0, 10]) cylinder (d=30, h=20);
        cylinder (d=15, h=50, center=true);

}

<http://forum.openscad.org/file/t486/1.png>

The problem though, is that if you need a 2D end product (like a graphic),
or 2.5D (like CNC), all you get is the outermost shape.

for example

circle (d=50);
circle (d=30);
circle (d=15);

Only returns "circle (d=50)" since the others are contained in the bigger
circle.

<http://forum.openscad.org/file/t486/2.png>

To get the 3 2D concentric circles in OpenSCAD (that could be exported to 2D
outputs like DXF or SVG or PNG), you need to phrase it like:

difference()
{
        circle (d=50);
        circle (d=30);
}
circle (d=15);

<http://forum.openscad.org/file/t486/3.png>

This example would work for most 2.5D CNC programs, as it deals with
enclosed areas and shapes - however this technique breaks down in a hurry if
you are dealing with any shapes more complex than basic primitives or if you
are doing text, having the bit follow a single line, etc.   If you needed
three concentric circles for a drawing (with no filled areas) (such as for a
graphic), you are out of luck.  

Mostly out of luck, anyway.  I have sometimes gotten away with extremely
thin shells:

module offsetShell()
{
        difference()
        {
                children(0);
                offset (r=-0.05) children(0);
        }
}

offsetShell() circle (d=50);
offsetShell() circle (d=30);
offsetShell() circle (d=15);

<http://forum.openscad.org/file/t486/4.png>

In this case, the practical difference for most CNC applications is
negligible.  I have also used extremely thin walls between features that
either break out from the bit or can be easily broken out by hand.

There has been talk of having a modifier that prevents top-level union in
OpenSCAD; this would enable OpenSCAD to do what you (and me, and many others
(since the topic crops up periodically)) are wanting to do - use OpenSCAD
for 2D artwork as well.  This would allow one file to have all the
parameters for a project, even if it has 2D/2.5D/3D components.  It also
would make OpenSCAD more useful for use with a laser cutter/CNC.  

In the meantime, though, you might want to look at SVG programming in
Python.  That would probably be the easiest route to get the output you need
parametrically; however it is not as interactive as modeling in OpenSCAD.



--
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: Tool like OpenSCAD, but for 2D images?

shadowwynd
In reply to this post by Troberg
The issue has to do with OpenSCAD's top-level union, which is automatically
applied.  This means it can do 3D well, 2.5D with limitations (great as long
as the "D" are the same (e.g. a plate with holes and slots)), and is very
poor at 2D.

Let's say we want a cylinder, with a half-hollowed cylinder and an
axle-hole.

Here is the OpenSCAD code to create this shape (great if using a 3D
printer):

difference()
{
        cylinder (d=50, h=20);
        translate ([0, 0, 10]) cylinder (d=30, h=20);
        cylinder (d=15, h=50, center=true);

}

<http://forum.openscad.org/file/t486/1.png>

The problem though, is that if you need a 2D end product (like a graphic),
or 2.5D (like CNC), all you get is the outermost shape.

for example

circle (d=50);
circle (d=30);
circle (d=15);

Only returns "circle (d=50)" since the others are contained in the bigger
circle.

<http://forum.openscad.org/file/t486/2.png>

To get the 3 2D concentric circles in OpenSCAD (that could be exported to 2D
outputs like DXF or SVG or PNG), you need to phrase it like:

difference()
{
        circle (d=50);
        circle (d=30);
}
circle (d=15);

<http://forum.openscad.org/file/t486/3.png>

This example would work for most 2.5D CNC programs, as it deals with
enclosed areas and shapes - however this technique breaks down in a hurry if
you are dealing with any shapes more complex than basic primitives or if you
are doing text, having the bit follow a single line, etc.   If you needed
three concentric circles for a drawing (with no filled areas) (such as for a
graphic), you are out of luck.  

Mostly out of luck, anyway.  I have sometimes gotten away with extremely
thin shells:

module offsetShell()
{
        difference()
        {
                children(0);
                offset (r=-0.05) children(0);
        }
}

offsetShell() circle (d=50);
offsetShell() circle (d=30);
offsetShell() circle (d=15);

<http://forum.openscad.org/file/t486/4.png>

In this case, the practical difference for most CNC applications is
negligible.  I have also used extremely thin walls between features that
either break out from the bit or can be easily broken out by hand.

There has been talk of having a modifier that prevents top-level union in
OpenSCAD; this would enable OpenSCAD to do what you (and me, and many others
(since the topic crops up periodically)) are wanting to do - use OpenSCAD
for 2D artwork as well.  This would allow one file to have all the
parameters for a project, even if it has 2D/2.5D/3D components.  It also
would make OpenSCAD more useful for use with a laser cutter/CNC.  

In the meantime, though, you might want to look at SVG programming in
Python.  That would probably be the easiest route to get the output you need
parametrically; however it is not as interactive as modeling in OpenSCAD.



--
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: Tool like OpenSCAD, but for 2D images?

Neon22
or you could write a python extension for inkscape and then export to
openscad and extrude, or whatever...

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

Re: Tool like OpenSCAD, but for 2D images?

cacb
In reply to this post by shadowwynd
On 2017-10-20 14:31, shadowwynd wrote:
> The issue has to do with OpenSCAD's top-level union, which is
> automatically
> applied.  This means it can do 3D well, 2.5D with limitations (great as
> long
> as the "D" are the same (e.g. a plate with holes and slots)), and is
> very
> poor at 2D.

OpenSCAD is a CSG (Constructive Solid Geometry) modeller for 2D or 3D.
It is not a line drawing program, neither in 2D nor 3D.

> If you needed
> three concentric circles for a drawing (with no filled areas) (such as
> for a
> graphic), you are out of luck.

In OpenSCAD, everything is a solid (in 2D or 3D). If what you want is a
line drawing tool, then OpenSCAD is the wrong choice.

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: Tool like OpenSCAD, but for 2D images?

fractorr
I have use this SVG JavaScript library on several projects.



On Fri, Oct 20, 2017 at 6:19 AM, <[hidden email]> wrote:
On 2017-10-20 14:31, shadowwynd wrote:
The issue has to do with OpenSCAD's top-level union, which is automatically
applied.  This means it can do 3D well, 2.5D with limitations (great as long
as the "D" are the same (e.g. a plate with holes and slots)), and is very
poor at 2D.

OpenSCAD is a CSG (Constructive Solid Geometry) modeller for 2D or 3D. It is not a line drawing program, neither in 2D nor 3D.

If you needed
three concentric circles for a drawing (with no filled areas) (such as for a
graphic), you are out of luck.

In OpenSCAD, everything is a solid (in 2D or 3D). If what you want is a line drawing tool, then OpenSCAD is the wrong choice.

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: Tool like OpenSCAD, but for 2D images?

ashuan
In reply to this post by Troberg
Perhaps you could use D3.js library.
It's graph oriented but there's many other kind of example :
https://github.com/d3/d3/wiki/Gallery

It's use SVG model.



--
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: Tool like OpenSCAD, but for 2D images?

Oakapple
In reply to this post by Troberg
Or consider using a programmatic 2D tool such as Processing...https://en.m.wikipedia.org/wiki/Processing_(programming_language)



---------------------------------
Colin Smart (07968 049660)


On 20 Oct 2017, at 12:07, Troberg <[hidden email]> wrote:

I'd say that what I'm looking for is something like "script controlled
PaintShop", much like one could say that OpenSCAD is a "script controlled
SketchUp" (and don't nitpick that definition, I'm just trying to get a
general idea across here...).



--
Sent from: http://forum.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: Tool like OpenSCAD, but for 2D images?

moshel
Processing looks promising! I'll give it a try. Thanks!



--
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: Tool like OpenSCAD, but for 2D images?

mbugert
moshel wrote
> Processing looks promising! I'll give it a try. Thanks!

I recently wrote a library which could help for your problem. It's about
lasercutting stuff with OpenSCAD, see
http://forum.openscad.org/laserscad-A-library-for-efficient-lasercutting-with-OpenSCAD-td22429.html
<http://forum.openscad.org/laserscad-A-library-for-efficient-lasercutting-with-OpenSCAD-td22429.html>
).

Cheers,
mbugert



--
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: Tool like OpenSCAD, but for 2D images?

TLC123
In reply to this post by Troberg
ImageMagick can do scripting for 2d bitmaps



--
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: Tool like OpenSCAD, but for 2D images?

Troberg
Imagemagick is good for some types of processing, but not for creating images
from scratch.

I'm looking for a tool where I can script things like this:

Start with a blank bitmap. Load another bitmap from disk. Draw a circle on
it, then invert what's in the circle. Paint the modified bitmap in several
positions on the screen. Draw a border of evenly spaced circles. Load a logo
bitmap from disk and put in the corner. Add some text in a new layer, set to
semitransparent and add to the main picture as a water mark. Convert the
result to greyscale.

Basically, a combined bitmap and vector tool, like a bunch of paint programs
out there, but with the mindset of OpenSCAD, where everything is scripted
and there is no GUI for drawing. Basically, scripted drawing for engineers.



--
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: Tool like OpenSCAD, but for 2D images?

TLC123
Guess one can do most of that with a hand coded svg with embedded bitmaps and
possibly even scriptable canvas tag.




--
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: Tool like OpenSCAD, but for 2D images?

kintel
Administrator
In reply to this post by Troberg
There’s always maker.js: https://maker.js.org/

 -Marius


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