Change Attribute to Closest Multiple
I need to have a random number (say, 100) change to it's closest multiple of another number (say, 32) resulting in 96.
Here's how I've done it so far:
3 attributes:
numberathand (real), 100
integer (integer), 0
multiplier (integer), 32
Behaviors:
Change Attribute "numberathand" to "numberathand / multiplier" ---now our number is 3.125
Change Attribute "integer" to "numberathand" ---now our number is 3
Change Attribute "numberathand" to "integer" x "multiplier" ---now our number is 96.
Is there a better way to do this? I'm not a math person...
Here's how I've done it so far:
3 attributes:
numberathand (real), 100
integer (integer), 0
multiplier (integer), 32
Behaviors:
Change Attribute "numberathand" to "numberathand / multiplier" ---now our number is 3.125
Change Attribute "integer" to "numberathand" ---now our number is 3
Change Attribute "numberathand" to "integer" x "multiplier" ---now our number is 96.
Is there a better way to do this? I'm not a math person...
Comments
this will snap to the multiple of 32 lower than it currently is. If you replace floor with ceil it will snap to the higher multiple of 32.
You could stick them both in a rule that says when attribute numberathand is less than ((floor( self.New Attribute /32))*32)+16
change to ((floor( self.New Attribute /32))*32)
otherwise
change to ((ceil( self.New Attribute /32))*32)
This will change to it whichever is closer between the higher and larger multiple of 32
swap all the self.newattributes with self.numberathand