Created
September 21, 2018 13:30
-
-
Save markknol/9af927988acafd59afa1c4a787b1d9e7 to your computer and use it in GitHub Desktop.
Rainbow colors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getRainbow(size:Int) { | |
| inline function sinToHex(i, phase) { | |
| var sin = Math.sin(Math.PI / size * 2 * i + phase); | |
| var int = Math.floor(sin * 127) + 128; | |
| return StringTools.hex(int, 2); | |
| } | |
| return [for (i in 0...size) { | |
| var red = sinToHex(i, 0 * Math.PI * 2/3); | |
| var blue = sinToHex(i, 1 * Math.PI * 2/3); | |
| var green = sinToHex(i, 2 * Math.PI * 2/3); | |
| "#"+ red + green + blue; | |
| }]; | |
| } | |
| // usage | |
| var rainbowColors = getRainbow(total * 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment