1234567891011121314151617181920212223242526272829 |
- #!/usr/bin/ruby
- #
- ## https://rosettacode.org/wiki/Color_wheel
- #
- require('Imager')
- var (width, height) = (300, 300)
- var center = Complex(width/2 , height/2)
- var img = %O<Imager>.new(xsize => width, ysize => height)
- define(
- PI = Num.pi,
- TAU = Num.tau,
- )
- for y=(^height), x=(^width) {
- var vector = (center - x - y.i)
- var magnitude = (2*vector.abs / width)
- var direction = ((PI + atan2(vector.real, vector.imag)) / TAU)
- img.setpixel(x => x, y => y,
- color => Hash(hsv => [360*direction, magnitude, magnitude < 1 ? 1 : 0])
- )
- }
- img.write(file => 'color_wheel.png')
|