Anonymous user
Color wheel: Difference between revisions
no edit summary
(Added Sidef) |
No edit summary |
||
Line 2:
;Task:
Write a function to draw a HSV color wheel<ref>[https://en.wikipedia.org/wiki/HSL_and_HSV]</ref> completely with code.
This is strictly for learning purposes only. It's highly recommended that you use an image in an actual application to actually draw the color wheel (as procedurally drawing is super slow). This does help you understand how color wheels work and this can easily be used to determine a color value based on a position within a circle.
Line 75 ⟶ 74:
Until local image uploading is re-enabled, see [https://github.com/thundergnat/rc/blob/master/img/Color-wheel-perl6.png Color-wheel-perl6.png]
=={{header|Python}}==
<lang python>from PIL import Image
import colorsys
import math
if __name__ == "__main__":
im = Image.new("RGB", (300,300))
radius = min(im.size)/2.0
centre = im.size[0]/2, im.size[1]/2
pix = im.load()
for x in range(im.width):
for y in range(im.width):
rx = x - centre[0]
ry = y - centre[1]
s = ((x - centre[0])**2.0 + (y - centre[1])**2.0)**0.5 / radius
if s <= 1.0:
h = ((math.atan2(ry, rx) / math.pi) + 1.0) / 2.0
rgb = colorsys.hsv_to_rgb(h, s, 1.0)
pix[x,y] = tuple([int(round(c*255.0)) for c in rgb])
im.show()</lang
=={{header|Sidef}}==
Line 138 ⟶ 162:
}</lang>
Until local image uploading is re-enabled, see [http://www.zenkinetic.com/Images/RosettaCode/colorWheel.zkl.jpg this image].
==References==
<references/>
|