Color wheel: Difference between revisions
Content added Content deleted
m (used better phrasing in the "recommendation" sentence.) |
(→{{header|zkl}}: re-invent the wheel) |
||
Line 76: | Line 76: | ||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
⚫ | |||
A color square - I just fill a square with the color wheel, it could be clipped to a circle if needed. |
|||
⚫ | |||
Uses the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl |
Uses the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl |
||
Line 85: | Line 84: | ||
fcn colorWheel(ppm){ |
fcn colorWheel(ppm){ |
||
zero,R:=ppm.w/2, zero; |
|||
d:=centerX.toFloat().hypot(centerY); |
|||
foreach x,y in (w,h){ |
foreach x,y in (w,h){ |
||
v,hue:=(x - |
v,hue:=(x - zero).toFloat().toPolar(y - zero); |
||
if( |
if(v<=R){ // only render in the circle |
||
if((hue = hue.toDeg())<0) hue+=360; // (-pi..pi] to [0..2pi) |
|||
s:=v/R; // scale saturation zero at center to 1 at edge |
|||
ppm[x,y]=hsv2rgb(hue,1.0,s); |
|||
} |
|||
} |
} |
||
} |
} |