Jump to content

Color wheel: Difference between revisions

→‎{{header|zkl}}: re-invent the wheel
m (used better phrasing in the "recommendation" sentence.)
(→‎{{header|zkl}}: re-invent the wheel)
Line 76:
 
=={{header|zkl}}==
Each point in the square is converted to polar coordinates, the angle is hue and the radius is saturation (which is scaled by the distance from the pole). If the radius/saturation is in the circle, render it.
A color square - I just fill a square with the color wheel, it could be clipped to a circle if needed.
Each point in the square is converted to polar coordinates, the angle is hue and the radius is saturation (which is scaled by the distance from the pole).
 
Uses the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl
Line 85 ⟶ 84:
fcn colorWheel(ppm){
centerXzero,centerYR:=ppm.w/2,ppm.h/2 zero;
d:=centerX.toFloat().hypot(centerY);
foreach x,y in (w,h){
v,hue:=(x - centerXzero).toFloat().toPolar(y - centerYzero);
if((hue v<= hue.toDeg())<0R){ hue+=360; // (-pi..pi]only torender [0..2pi)in the circle
if((hue = hue.toDeg())<0) hue+=360; // (-pi..pi] to [0..2pi)
s:=v/dR; // scale saturation zero at center to 1 at edge
ppm[x,y]=hsv2rgb(hue,1.0,s);
}
}
}
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.