mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +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.
|
// Default values for attachment code.
|
||||||
$tags = "";
|
$tags = "";
|
||||||
$overlap = 0;
|
$overlap = 0;
|
||||||
$color = undef;//"yellow";
|
$color = "default";
|
||||||
$save_color = undef; // Saved color to revert back for children
|
$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_to = undef;
|
||||||
$attach_anchor = [CENTER, CENTER, UP, 0];
|
$attach_anchor = [CENTER, CENTER, UP, 0];
|
||||||
|
@ -840,7 +820,7 @@ module hulling(a)
|
||||||
// Note that 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]].
|
// For a more step-by-step explanation of attachments, see the [[Attachments Tutorial|Tutorial-Attachments]].
|
||||||
// Arguments:
|
// 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:
|
// Example:
|
||||||
// cuboid([10,10,5])
|
// cuboid([10,10,5])
|
||||||
// recolor("green")attach(TOP,BOT) cuboid([9,9,4.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])
|
// attach(TOP,BOT) cuboid([6,6,3])
|
||||||
// recolor("cyan")attach(TOP,BOT) cuboid([5,5,2.5])
|
// recolor("cyan")attach(TOP,BOT) cuboid([5,5,2.5])
|
||||||
// attach(TOP,BOT) cuboid([4,4,2]);
|
// attach(TOP,BOT) cuboid([4,4,2]);
|
||||||
module recolor(c)
|
module recolor(c="default")
|
||||||
{
|
{
|
||||||
$color = default(c,_default_color());
|
$color=c;
|
||||||
children();
|
children();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -866,17 +846,10 @@ module recolor(c)
|
||||||
// This works only with attachables and you cannot have any color() modules above it in any parents,
|
// 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 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]].
|
// For a more step-by-step explanation of attachments, see the [[Attachments Tutorial|Tutorial-Attachments]].
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// c = Color name or RGBA vector. Default: the standard OpenSCAD yellow
|
// c = Color name or RGBA vector. Default: the standard OpenSCAD yellow
|
||||||
// Example:
|
// Example:
|
||||||
// $color_scheme = "cornfield"; // Change this if necessary
|
|
||||||
// cuboid([10,10,5])
|
// cuboid([10,10,5])
|
||||||
// color_this("green")attach(TOP,BOT) cuboid([9,9,4.5])
|
// color_this("green")attach(TOP,BOT) cuboid([9,9,4.5])
|
||||||
// attach(TOP,BOT) cuboid([8,8,4])
|
// attach(TOP,BOT) cuboid([8,8,4])
|
||||||
|
@ -884,10 +857,10 @@ module recolor(c)
|
||||||
// attach(TOP,BOT) cuboid([6,6,3])
|
// attach(TOP,BOT) cuboid([6,6,3])
|
||||||
// color_this("cyan")attach(TOP,BOT) cuboid([5,5,2.5])
|
// color_this("cyan")attach(TOP,BOT) cuboid([5,5,2.5])
|
||||||
// attach(TOP,BOT) cuboid([4,4,2]);
|
// attach(TOP,BOT) cuboid([4,4,2]);
|
||||||
module color_this(c)
|
module color_this(c="default")
|
||||||
{
|
{
|
||||||
$save_color=default($color, _default_color());
|
$save_color=default($color,"default");
|
||||||
$color=default(c, _default_color());
|
$color=c;
|
||||||
children();
|
children();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1441,7 +1414,7 @@ module attachable(
|
||||||
$attach_to = undef;
|
$attach_to = undef;
|
||||||
do_show = _attachment_is_shown($tags);
|
do_show = _attachment_is_shown($tags);
|
||||||
if (do_show) {
|
if (do_show) {
|
||||||
if (is_undef($color)) {
|
if (is_undef($color) || $color=="default") {
|
||||||
children(0);
|
children(0);
|
||||||
} else color($color) {
|
} else color($color) {
|
||||||
$color = undef;
|
$color = undef;
|
||||||
|
@ -2369,7 +2342,6 @@ module anchor_arrow2d(s=15, color=[0.333,0.333,1], $tags="anchor-arrow") {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Module: expose_anchors()
|
// Module: expose_anchors()
|
||||||
// Usage:
|
// Usage:
|
||||||
// expose_anchors(opacity) {child1() show_anchors(); child2() show_anchors(); ...}
|
// expose_anchors(opacity) {child1() show_anchors(); child2() show_anchors(); ...}
|
||||||
|
@ -2384,15 +2356,15 @@ module expose_anchors(opacity=0.2) {
|
||||||
show("anchor-arrow")
|
show("anchor-arrow")
|
||||||
children();
|
children();
|
||||||
hide("anchor-arrow")
|
hide("anchor-arrow")
|
||||||
color(is_undef($color)? [0,0,0] :
|
color(is_undef($color) || color=="default" ? [0,0,0] :
|
||||||
is_string($color)? $color :
|
is_string($color) ? $color
|
||||||
point3d($color), opacity)
|
: point3d($color),
|
||||||
|
opacity)
|
||||||
children();
|
children();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Module: frame_ref()
|
// Module: frame_ref()
|
||||||
// Usage:
|
// Usage:
|
||||||
// frame_ref(s, opacity);
|
// frame_ref(s, opacity);
|
||||||
|
|
Loading…
Reference in a new issue