From 02d7f27747c1c7285b77897d15826687b500a0f1 Mon Sep 17 00:00:00 2001 From: dooglus Date: Thu, 14 Feb 2008 09:31:11 +0000 Subject: [PATCH] Allow boolean values to be converted to Random. The link's value (0 or 1) has a random value between -radius and radius added to it. If the result <0.5, it's false, else it's true. So with 'link=true' and 'radius=1', the result will be between 0 and 2, which is true about 75% of the time. So get a 50:50 split, use a radius of a million. git-svn-id: http://svn.voria.com/code@1690 1f10aa63-cdf2-0310-b900-c93c546f37ac --- synfig-core/trunk/src/modules/mod_noise/valuenode_random.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/synfig-core/trunk/src/modules/mod_noise/valuenode_random.cpp b/synfig-core/trunk/src/modules/mod_noise/valuenode_random.cpp index 0488189..fdfa331 100644 --- a/synfig-core/trunk/src/modules/mod_noise/valuenode_random.cpp +++ b/synfig-core/trunk/src/modules/mod_noise/valuenode_random.cpp @@ -67,6 +67,9 @@ ValueNode_Random::ValueNode_Random(const ValueBase &value): case ValueBase::TYPE_ANGLE: set_link("link",ValueNode_Const::create(value.get(Angle()))); break; + case ValueBase::TYPE_BOOL: + set_link("link",ValueNode_Const::create(value.get(bool()))); + break; case ValueBase::TYPE_COLOR: set_link("link",ValueNode_Const::create(value.get(Color()))); break; @@ -124,6 +127,10 @@ ValueNode_Random::operator()(Time t)const return ((*link_)(t).get( Angle()) + Angle::deg(random(Smooth(smooth), 0, 0, 0, speed) * radius)); + case ValueBase::TYPE_BOOL: + return round_to_int((*link_)(t).get( bool()) + + random(Smooth(smooth), 0, 0, 0, speed) * radius) > 0; + case ValueBase::TYPE_COLOR: return (((*link_)(t).get( Color()) + Color(random(Smooth(smooth), 0, 0, 0, speed), @@ -258,6 +265,7 @@ ValueNode_Random::check_type(ValueBase::Type type) { return type==ValueBase::TYPE_ANGLE || + type==ValueBase::TYPE_BOOL || type==ValueBase::TYPE_COLOR || type==ValueBase::TYPE_INTEGER || type==ValueBase::TYPE_REAL || -- 2.7.4