mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-01 09:49:45 +00:00
add color_this() module
This commit is contained in:
parent
fe1d017252
commit
5439b1ee64
1 changed files with 50 additions and 8 deletions
|
@ -17,6 +17,8 @@
|
||||||
$tags = "";
|
$tags = "";
|
||||||
$overlap = 0;
|
$overlap = 0;
|
||||||
$color = undef;//"yellow";
|
$color = undef;//"yellow";
|
||||||
|
$save_color = undef; // Saved color to revert back for children
|
||||||
|
_DEFAULT_COLOR = "gold";
|
||||||
|
|
||||||
$attach_to = undef;
|
$attach_to = undef;
|
||||||
$attach_anchor = [CENTER, CENTER, UP, 0];
|
$attach_anchor = [CENTER, CENTER, UP, 0];
|
||||||
|
@ -810,23 +812,59 @@ module hulling(a)
|
||||||
|
|
||||||
// Module: recolor()
|
// Module: recolor()
|
||||||
// Usage:
|
// Usage:
|
||||||
// recolor(c) {...}
|
// recolor([c]) {...}
|
||||||
// Topics: Attachments
|
// Topics: Attachments
|
||||||
// See Also: tags(), hide(), show(), diff(), intersect()
|
// See Also: color_this(), tags(), hide(), show(), diff(), intersect()
|
||||||
// Description:
|
// Description:
|
||||||
// Sets the color for children that can use the $color special variable. For a more step-by-step
|
// Sets the color for children that can use the $color special variable. For this to work
|
||||||
// explanation of attachments, see the [[Attachments Tutorial|Tutorial-Attachments]].
|
// 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.
|
||||||
|
// For a more step-by-step explanation of attachments, see the [[Attachments Tutorial|Tutorial-Attachments]].
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// c = Color name or RGBA vector.
|
// c = Color name or RGBA vector. Default: The standard OpenSCAD yellow
|
||||||
// Example:
|
// Example:
|
||||||
// recolor("red") cyl(l=20, d=10);
|
// cuboid([10,10,5])
|
||||||
module recolor(c)
|
// recolor("green")attach(TOP,BOT) cuboid([9,9,4.5])
|
||||||
|
// attach(TOP,BOT) cuboid([8,8,4])
|
||||||
|
// recolor("purple") attach(TOP,BOT) cuboid([7,7,3.5])
|
||||||
|
// 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=_DEFAULT_COLOR)
|
||||||
{
|
{
|
||||||
$color = c;
|
$color = c;
|
||||||
children();
|
children();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Module: color_this()
|
||||||
|
// Usage:
|
||||||
|
// color_this([c]) {...}
|
||||||
|
// Topics: Attachments
|
||||||
|
// See Also: tags(), recolor()
|
||||||
|
// 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.
|
||||||
|
// 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:
|
||||||
|
// cuboid([10,10,5])
|
||||||
|
// color_this("green")attach(TOP,BOT) cuboid([9,9,4.5])
|
||||||
|
// attach(TOP,BOT) cuboid([8,8,4])
|
||||||
|
// color_this("purple") attach(TOP,BOT) cuboid([7,7,3.5])
|
||||||
|
// 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=_DEFAULT_COLOR)
|
||||||
|
{
|
||||||
|
$save_color=default($color, _DEFAULT_COLOR);
|
||||||
|
$color=c;
|
||||||
|
children();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Module: hide()
|
// Module: hide()
|
||||||
// Usage:
|
// Usage:
|
||||||
// hide(tags) {...}
|
// hide(tags) {...}
|
||||||
|
@ -1383,11 +1421,15 @@ module attachable(
|
||||||
children(0);
|
children(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (is_def($save_color)) {
|
||||||
|
$color=$save_color;
|
||||||
|
$save_color=undef;
|
||||||
|
children(1);
|
||||||
|
} else
|
||||||
children(1);
|
children(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Function: reorient()
|
// Function: reorient()
|
||||||
//
|
//
|
||||||
// Usage: Square/Trapezoid Geometry
|
// Usage: Square/Trapezoid Geometry
|
||||||
|
|
Loading…
Reference in a new issue