In ActionScript 3, is there a shorter way to clip a value to be between 0 and 255?
value = Math.min(255, Math.max(0, value))
In ActionScript 3, is there a shorter way to clip a value to be between 0 and 255?
value = Math.min(255, Math.max(0, value))
Nope, you could create your own shortcut function easily enough though:
function clip(val:Number, min:Number, max:Number):Number {
return Math.min(max, Math.max(min, val));
}
If you're looking for something fast, the following will do:
k = (k | -int(k > 256)) & -int(k > 0) & 0xFF;