1

I saw here a spin function that goes from -360 to 360, which doesn't make sense to me, I would think it would go from 0-360.

I would like to extend the concept of complementary color, triad, and tetrad (which were built into another library), and generate an arbitrary n-gon equivalent of a color palette, so a pentad, hexad, heptad, etc. I tried simply doing angle * position to get the pentad, but 2 of the 5 colors were duplicate (this is because I'm going from 0-360).

Not sure how to get that working.

1 Answer 1

2

The reason it lets you do rotations from -360 to 360 even though a lot of those are the same thing is because they are all the values you'd conceptually use. So -20 degrees of hue makes sense so does +340 degrees of hue even though they are the same thing.

var tc = tinycolor({
  r: Math.floor(Math.random() * 0xFF),
  g: Math.floor(Math.random() * 0xFF),
  b: Math.floor(Math.random() * 0xFF)
})
colors = []
var parts = 2 + Math.floor(Math.random() * 5);
for (var i = 0; i < parts; i++) {
  tc = tc.spin(360 / parts);
  colors.push('#' + tc.toHex())
}

div = document.createElement("div");
document.body.appendChild(div);
colors.forEach(function(element) {
  var d = document.createElement("button");
  d.style.cssText = 'padding:5px; font-size:22px; width:50px; height:50px; background-color:' + element;
  div.appendChild(d);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/tinycolor/1.4.1/tinycolor.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

2
  • Wondering if you could show a demo, I tried this like I mentioned and it didn't work.
    – Lance
    Commented Jun 11, 2019 at 9:54
  • Go ahead and hit run code snippet a few times, should see it works. @LancePollard
    – Tatarize
    Commented Jun 11, 2019 at 11:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.