ondras / rot.js

ROguelike Toolkit in JavaScript. Cool dungeon-related stuff, interactive manual, documentation, tests!
https://ondras.github.io/rot.js/hp/
BSD 3-Clause "New" or "Revised" License
2.34k stars 255 forks source link

ROT.Color.randomize returns valid color triplets #23

Closed bob0the0mighty closed 10 years ago

bob0the0mighty commented 10 years ago

Changed randomize so that it returns only valid color triplets.

ondras commented 10 years ago

1) there already is a _clamp method for doing this,

2) your patch fails in the case when diff is not an Array,

3) I do not see clamping colors in randomize() as a wise choice. Colors are best manipulated unclamped - you fix only the final value (as we do in ROT.Color.to{RGB,Hex}). This is similar to float number manipulation - you only want to round the final value, not intermediate results.

bob0the0mighty commented 10 years ago

Cool. So I was using it incorrectly :-). Thanks for clearing that up.