Your challenge is to write a program that takes input from stdin, creates a set of 1
to n
colors and outputs them on stdout, formatted as a 6-digit-hex value with a prefixed #.
- The starting color should have following values (in a hsv colorspace) (pesudocode)
h=rand(), s=0.5, v=0.95
.
- Every subsequent color should have its hue value increased by
1/Φ
- After every 5th color, the saturation and value for the forthcoming colors should be
- saturation - increased by
0.1
- value - decreased by
0.2
- saturation - increased by
e.g.
Color # h s v
1 0.5 0.5 0.95
2 0.118... 0.5 0.95
11 0.680... 0.7 0.55
Input
Your program shall receive an Integer n
as input (stdin), which defines the number of colors, to be generated. Where 0 < n < 16
Output
- On each call, the hues' start value should be different from the last call (Don't just take the same random start number on every call)
- Output should be on stdout with one color per line.
- The array shall contain
n
different hex codes. - The hex codes should be prefixed with a "#" and be padded with a "0", such that you always get a 7 character string like "#FFFFFF"
Additional Rules
- The use of built in functions/tools/etc for the following conversions is forbidden
- HSV->RGB
- RGB->HEX representation of RGBa function which specifically converts rgb to hex, generic tools like
sprintf
are ok. - HSV->HEX representation of RGBjust to make sure...
Scoring
The size of your code in bytes.
Test Cases(result of rand() in parantheses)
3 (0.35389856481924653) ->
#79f388
#f3798e
#79b1f3
8 (0.763850917108357) ->
#c079f3
#79f39d
#f37979
#4c6ec0
#90c04c
#c04cb1
#4cc0ac
#c08b4c
15 (0.10794945224188268) ->
#f3c879
#a479f3
#79f381
#f37995
#79b8f3
#aac04c
#b44cc0
#4cc092
#c0704c
#4f4cc0
#448c2a
#8c2a61
#2a7e8c
#8c7e2a
#612a8c
for a visualization of the codes, you can paste your output here
I will change the accepted Answer, as soon as new appear
rand()
in the test cases to make testing easier? \$\endgroup\$sprintf("%2x"*3,r,g,b)
count? \$\endgroup\$sprintf
is definetly eligible \$\endgroup\$