mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-28 07:49:45 +00:00
replace color scheme handling with a "default" color
This commit is contained in:
parent
372b3ae857
commit
942c15e84d
1 changed files with 14 additions and 42 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue