From 942c15e84d92d6bf2654f60d8eb3b219e45baa0a Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Sun, 20 Mar 2022 08:25:04 -0400 Subject: [PATCH 1/4] replace color scheme handling with a "default" color --- attachments.scad | 56 ++++++++++++------------------------------------ 1 file changed, 14 insertions(+), 42 deletions(-) diff --git a/attachments.scad b/attachments.scad index 5a7f8d6..207490b 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]; @@ -837,10 +817,10 @@ module hulling(a) // 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. +// Note that recolor() affects its children and all their descendants. // 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(); } @@ -865,18 +845,11 @@ module recolor(c) // 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(). // . // 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 // 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(); } @@ -1441,7 +1414,7 @@ module attachable( $attach_to = undef; do_show = _attachment_is_shown($tags); if (do_show) { - if (is_undef($color)) { + if (is_undef($color) || $color=="default") { children(0); } else color($color) { $color = undef; @@ -2369,7 +2342,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 +2354,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); From c25d3a3f67678a1023da1b15673e782d863b669b Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Sun, 20 Mar 2022 09:03:18 -0400 Subject: [PATCH 2/4] bug fixes for "default" color --- attachments.scad | 10 ++-------- builtins.scad | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/attachments.scad b/attachments.scad index 207490b..f8310e8 100644 --- a/attachments.scad +++ b/attachments.scad @@ -1413,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) || $color=="default") { - 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; 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); From dd99cec7a0fcb2bbe8f6b46193663ee3a5cdf390 Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Sun, 20 Mar 2022 09:40:02 -0400 Subject: [PATCH 3/4] bugfix --- attachments.scad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/attachments.scad b/attachments.scad index f8310e8..108db8d 100644 --- a/attachments.scad +++ b/attachments.scad @@ -2350,7 +2350,7 @@ module expose_anchors(opacity=0.2) { show("anchor-arrow") children(); hide("anchor-arrow") - color(is_undef($color) || color=="default" ? [0,0,0] : + color(is_undef($color) || $color=="default" ? [0,0,0] : is_string($color) ? $color : point3d($color), opacity) From 5bcd7e571bb11d4d86cb042522b11ac9083136b1 Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Mon, 21 Mar 2022 23:58:18 -0400 Subject: [PATCH 4/4] doc tweaks --- attachments.scad | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/attachments.scad b/attachments.scad index 108db8d..2475787 100644 --- a/attachments.scad +++ b/attachments.scad @@ -815,9 +815,9 @@ 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. -// Note that 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 default color in your color scheme. @@ -844,11 +844,11 @@ module recolor(c="default") // 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. +// 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: // cuboid([10,10,5]) // color_this("green")attach(TOP,BOT) cuboid([9,9,4.5])