diff --git a/attachments.scad b/attachments.scad index 5a7f8d6..2475787 100644 --- a/attachments.scad +++ b/attachments.scad @@ -16,28 +16,8 @@ // Default values for attachment code. $tags = ""; $overlap = 0; -$color = undef;//"yellow"; +$color = "default"; $save_color = undef; // Saved color to revert back for children -$color_scheme = "cornfield"; // Default color scheme - -_default_colors = [ - ["cornfield", "#f9d72c"], - ["metallic", "#ddddff"], - ["sunset", "#ffaaaa"], - ["starnight", "#ffffe0"], - ["beforedawn", "#cccccc"], - ["nature", "#16a085"], - ["deepocean", "#eeeeee"], - ["solarized", "#b58800"], - ["tomorrow", "#4271ae"], - ["tomorrow night", "#81a2be"], - ["monotone", "#f9d72c"] -]; - -function _default_color() = - let(ind = search([downcase($color_scheme)], _default_colors, 1, 0)) - assert(ind[0]!=[], str("$color_scheme set to unknown value ",$color_scheme)) - _default_colors[ind[0]][1]; $attach_to = undef; $attach_anchor = [CENTER, CENTER, UP, 0]; @@ -835,12 +815,12 @@ module hulling(a) // Topics: Attachments // See Also: color_this(), tags(), hide(), show(), diff(), intersect() // Description: -// Sets the color for children that can use the $color special variable. For this to work -// you cannot have any color() modules above it in any parents, only other recolor() or color_this() modules. -// Not ethat recolor() affects its children and all their descendants. +// Sets the color for children and all their descendants. This only works with attachables and you cannot +// have any color() modules above it in any parents, only other recolor() or color_this() modules. +// This works by setting the special `$color` variable. // For a more step-by-step explanation of attachments, see the [[Attachments Tutorial|Tutorial-Attachments]]. // Arguments: -// c = Color name or RGBA vector. Default: The standard OpenSCAD yellow +// c = Color name or RGBA vector. Default: The default color in your color scheme. // Example: // cuboid([10,10,5]) // recolor("green")attach(TOP,BOT) cuboid([9,9,4.5]) @@ -849,9 +829,9 @@ module hulling(a) // attach(TOP,BOT) cuboid([6,6,3]) // recolor("cyan")attach(TOP,BOT) cuboid([5,5,2.5]) // attach(TOP,BOT) cuboid([4,4,2]); -module recolor(c) +module recolor(c="default") { - $color = default(c,_default_color()); + $color=c; children(); } @@ -864,19 +844,12 @@ module recolor(c) // Description: // Sets the color for children at one level, reverting to the previous color for further descendants. // This works only with attachables and you cannot have any color() modules above it in any parents, -// only recolor() or other color_this() modules. -// . -// This module works by saving the current color, which means it needs to know the current color. If you have -// not yet set the color with {{recolor()}} then the current color is the default color. -// OpenSCAD provides no method for learning the value of the default color, so if you don't use the default -// "cornfield" color scheme you should set $color_scheme to the color scheme you are using. -// Alternatively, always use {{recolor()}} on a parent before using color_this(). +// only recolor() or other color_this() modules. This works using the `$color` and `$save_color` variables. // . // For a more step-by-step explanation of attachments, see the [[Attachments Tutorial|Tutorial-Attachments]]. // Arguments: -// c = Color name or RGBA vector. Default: the standard OpenSCAD yellow +// c = Color name or RGBA vector. Default: the default color in your color scheme // Example: -// $color_scheme = "cornfield"; // Change this if necessary // cuboid([10,10,5]) // color_this("green")attach(TOP,BOT) cuboid([9,9,4.5]) // attach(TOP,BOT) cuboid([8,8,4]) @@ -884,10 +857,10 @@ module recolor(c) // attach(TOP,BOT) cuboid([6,6,3]) // color_this("cyan")attach(TOP,BOT) cuboid([5,5,2.5]) // attach(TOP,BOT) cuboid([4,4,2]); -module color_this(c) +module color_this(c="default") { - $save_color=default($color, _default_color()); - $color=default(c, _default_color()); + $save_color=default($color,"default"); + $color=c; children(); } @@ -1440,14 +1413,8 @@ module attachable( $parent_size = _attach_geom_size(geom); $attach_to = undef; do_show = _attachment_is_shown($tags); - if (do_show) { - if (is_undef($color)) { - children(0); - } else color($color) { - $color = undef; - children(0); - } - } + if (do_show) + _color($color) children(0); if (is_def($save_color)) { $color=$save_color; $save_color=undef; @@ -2369,7 +2336,6 @@ module anchor_arrow2d(s=15, color=[0.333,0.333,1], $tags="anchor-arrow") { - // Module: expose_anchors() // Usage: // expose_anchors(opacity) {child1() show_anchors(); child2() show_anchors(); ...} @@ -2382,17 +2348,17 @@ module anchor_arrow2d(s=15, color=[0.333,0.333,1], $tags="anchor-arrow") { // expose_anchors() cube(50, center=true) show_anchors(); module expose_anchors(opacity=0.2) { show("anchor-arrow") - children(); + children(); hide("anchor-arrow") - color(is_undef($color)? [0,0,0] : - is_string($color)? $color : - point3d($color), opacity) + color(is_undef($color) || $color=="default" ? [0,0,0] : + is_string($color) ? $color + : point3d($color), + opacity) children(); } - // Module: frame_ref() // Usage: // frame_ref(s, opacity); diff --git a/builtins.scad b/builtins.scad index 31d7b72..1693a27 100644 --- a/builtins.scad +++ b/builtins.scad @@ -19,7 +19,7 @@ module _text(text,size,font,halign,valign,spacing,direction,language,script) language=language, script=script ); -module _color(color) if (color==undef) children(); else color(color) children(); +module _color(color) if (color==undef || color=="default") children(); else color(color) children(); module _cube(size,center) cube(size,center=center);