[OpenSCAD] Question on defining a 'color' variable

doug moen doug at moens.org
Tue Jan 23 14:55:17 EST 2018


_color =
    (_myvar == 1) ? "red"
  : (_myvar == 2) ? "green"
  : (_myvar == 3) ? "blue"
  : "black";

color(_color) cube();

On 23 January 2018 at 14:36, Jess Askey <jess at askey.org> wrote:

> Hiya Folks…
>
>
>
> Im doing some automation generating OpenSCAD files and I wanted to have my
> output .png objects colored based upon a value of another parameter…  In my
> simplistic dream world, I would do like below and put the logic in the
> .scad file. I could also try and deal with another step in my templating
> where I output the “myvar” variable directly, but I would prefer not to for
> various reasons if it is indeed possible in .scad.
>
>
>
> The ‘_myvar’ parameter may have values of 1, 2 and 3 for example…
>
>
>
> Im trying to do something like below, but I clearly have scope issues and
> Im confused…   Is there a way to accomplish this concept or am I barking up
> an empty tree?
>
>
>
> _color = “black”;
>
> if (_myvar == 1) _color = “red”;
>
> else if (_myvar == 2) _color=”green”;
>
> else if (_myvar == 3) _color = “blue”;
>
>
>
> color(_color) cube();
>
>
>
> NOTE: in this simple example, I would just put the ‘color(_color) cube()’
> into the if/elseif blocks, but of course, in the real world, that is much
> more complex rendering so it doesn’t fit well inside of a large if/elseif
> tree.
>
>
>
> Thank you…. Jess
>
>
>
> _______________________________________________
> OpenSCAD mailing list
> Discuss at lists.openscad.org
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscad.org/pipermail/discuss_lists.openscad.org/attachments/20180123/b9f58aac/attachment-0002.html>


More information about the Discuss mailing list