How to convert escad to haskell?

53 views
Skip to first unread message

nmz...@gmail.com

unread,
Dec 29, 2014, 3:28:40 AM12/29/14
to impli...@googlegroups.com
I wrote some .escad but noticed that many of my syntax errors would go silently and either leave the program hanging (I think) or objects would be absent from my renderings. I was recommended to move to haskell. How can I do this? I installed from cabal but it seems everything is binary. Is there a guide to converting the source code to usable form, or compiling it with a haskell implicitcad file (i.e. my desired .escad converted to haskell)?

Thanks!

p.s. here is the .escad I am referring to:
https://github.com/nmz787/microfluidic-cad/blob/master/implicitCAD/tobacco_mesophyll_protoplast_fusion_device.escad

Christopher Olah

unread,
Dec 29, 2014, 4:28:34 AM12/29/14
to nmz...@gmail.com, ImplicitCAD
Hello,

You want to use the library "Graphics.Implicit". Documentation for it
can be found here:
https://hackage.haskell.org/package/implicit-0.0.3/docs/Graphics-Implicit.html

Example (that I haven't tested, there may be syntax errors):

module pdms_slab(distance_output_port_from_center)
{
width=distance_output_port_from_center*3;
translate ([width/-2,width/-2]) square(size=[width, width]);
}

would become something like:

pdms_slab distance_output_port_from_center =
translate [width/-2,width/-2] rectR 0 [0,0] [width, width]
where width = distance_output_port_from_center*3

Or, slightly cleaner:

pdms_slab distance_output_port_from_center =
rectR 0 [-width, -width] [width, width]
where width = distance_output_port_from_center*3/2

I no longer maintain ImplicitCAD. Julia Longtin (who I think is also
on this list) does. I will leave further comments to her.

All the best,

Chris
colah.github.io
> --
> You received this message because you are subscribed to the Google Groups "ImplicitCAD" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to implicitcad...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Nathan McCorkle

unread,
Dec 29, 2014, 5:24:34 AM12/29/14
to Christopher Olah, ImplicitCAD
On Mon, Dec 29, 2014 at 1:28 AM, Christopher Olah
<christoph...@gmail.com> wrote:
> Hello,
>
> You want to use the library "Graphics.Implicit". Documentation for it
> can be found here:
> https://hackage.haskell.org/package/implicit-0.0.3/docs/Graphics-Implicit.html
>
> Example (that I haven't tested, there may be syntax errors):

> pdms_slab distance_output_port_from_center =
> translate [width/-2,width/-2] rectR 0 [0,0] [width, width]
> where width = distance_output_port_from_center*3
>
> Or, slightly cleaner:
>
> pdms_slab distance_output_port_from_center =
> rectR 0 [-width, -width] [width, width]
> where width = distance_output_port_from_center*3/2


Awesome, thank you! If I was starting from the repo source, are there
steps that are laid out that could get the code you just wrote to
produce an SVG or STL, or error out telling me to fix things?

:)

Christopher Olah

unread,
Dec 29, 2014, 5:37:30 AM12/29/14
to Nathan McCorkle, ImplicitCAD
Once you have ImplicitCAD installed, you can write code something like this:

obj.hs (again, there are probably syntax errors, but this gives you a
rough idea):

> import Graphics.Implicit
>
> pdms_slab distance_output_port_from_center =
> rectR 0 [-width, -width] [width, width]
> where width = distance_output_port_from_center*3/2
>
> obj = pdms_slab 1
>
> resolution = 0.1
>
> main = writeSVG resolution "obj.svg" obj

Then:

$ runhaskell obj.hs

Or, alternatively:

$ ghc obj.hs
$ ./obj

A file obj.svg will be produced with the output. For a 3D object, you
could use writeSTL instead of writeSVG.

All the best,

Chris
colah.github.io

Reply all
Reply to author
Forward
0 new messages