Color wheel: Difference between revisions

m
 
(41 intermediate revisions by 18 users not shown)
Line 7:
 
 
 
=={{header|Applesoft BASIC}}==
The lo-resolution GRaphics screen is limited to 16 colors. Ordered dithering is used for the saturation. Pink is mixed with violet and magenta, and aqua is mixed with light blue and green. These lighter colors are randomly mixed with the saturation dither. Note that the four Apple II colors can be seen at the 90 degree marks: orange at 30 degrees, green at 120 degrees, cyan (blue) at 210 degrees, and violet at 300 degrees.
<syntaxhighlight lang="gwbasic"> 100 LET R = 3.1415926535 / 180
110 LET YO = 20
120 LET XO = YO
130 LET MS = INT (YO * 7 / 8)
140 LET O$ = "1111111111.1111111110.1111011110.1101110110.1101010110.1010101010.0010101001.0010001001.0000100001.0000000001.0000000000"
150 GR
160 FOR S = 0 TO MS
170 LET D = S / MS
180 LET P$ = MID$ (O$, INT (D * 10) * 11 + 1,11)
190 LET SY = S
200 LET SX = S * 4 / 7
210 LET P = 0
220 FOR I = 0 TO 360
230 LET X = XO + SIN (I * R) * SX
240 LET Y = YO + COS (I * R) * SY
250 LET W = 15
260 IF I > = 30 - 22.4 AND I < 30 + 22.5 THEN COLOR= 9
270 IF I > = 75 - 22.5 AND I < 75 + 22.5 THEN COLOR= 13
280 IF I > = 120 - 22.5 AND I < 120 + 22.5 THEN COLOR= 12:W = 14
290 IF I > = 165 - 22.5 AND I < 165 + 22.5 THEN COLOR= 7:W = 14
300 IF I > = 210 - 22.5 AND I < 210 + 22.5 THEN COLOR= 6
310 IF I > = 255 - 22.5 AND I < 255 + 22.5 THEN COLOR= 2
320 IF I > = 300 - 22.5 AND I < 300 + 22.5 THEN COLOR= 3:W = 11
330 IF I > = 345 - 22.5 OR I < 345 + 22.5 - 360 THEN COLOR= 1:W = 11
340 IF D < .2 THEN W = 15
350 IF RND (1) < D THEN W = 15
360 IF VAL ( MID$ (P$,P + 1,1)) THEN COLOR= W
370 IF SCRN( X,Y) = 0 THEN PLOT X,Y:P = P + 1: IF P > = 9 THEN P = 0
380 NEXT I,S</syntaxhighlight>
 
=={{header|AppleScript}}==
 
<syntaxhighlight lang="applescript">
<lang AppleScript>
choose color default color {0, 0, 0, 0}
</syntaxhighlight>
</lang>
 
=={{header|C++}}==
{{libheader|Qt}}
This program draws an HSV color wheel in a window.
<langsyntaxhighlight lang="cpp">// colorwheelwidget.cpp
#include "colorwheelwidget.h"
#include <QPainter>
Line 86 ⟶ 118:
painter.drawPie(rect, angle * 16, 16);
}
}</langsyntaxhighlight>
 
<langsyntaxhighlight lang="cpp">// colorwheelwidget.h
#ifndef COLORWHEELWIDGET_H
#define COLORWHEELWIDGET_H
Line 102 ⟶ 134:
};
 
#endif // COLORWHEELWIDGET_H</langsyntaxhighlight>
 
<langsyntaxhighlight lang="cpp">// main.cpp
#include "colorwheelwidget.h"
#include <QApplication>
Line 113 ⟶ 145:
widget.show();
return app.exec();
}</langsyntaxhighlight>
 
{{out}}
[[Media:Colorwheel cpp.png]]
Screenshot: [https://slack-files.com/T0CNUL56D-F016R0KR727-8f0ed6a40d colorwheel.png] (offsite PNG image)
 
=={{header|C#}}==
 
<syntaxhighlight lang="csharp">
// constructor of main window
// in MainWindow.xaml just create <Image Name="imgMain" />
public MainWindow()
{
InitializeComponent();
RenderOptions.SetBitmapScalingMode(imgMain, BitmapScalingMode.HighQuality);
imgMain.Source = new WriteableBitmap(480, 480, 96, 96, PixelFormats.Bgr32, null);
// using slider you can change saturation and call DrawHue with different level
DrawHue(100);
}
 
void DrawHue(int saturation)
{
var bmp = (WriteableBitmap)imgMain.Source;
 
int centerX = (int)bmp.Width / 2;
int centerY = (int)bmp.Height / 2;
int radius = Math.Min(centerX, centerY);
int radius2 = radius - 40;
 
bmp.Lock();
unsafe{
var buf = bmp.BackBuffer;
IntPtr pixLineStart;
for(int y=0; y < bmp.Height; y++){
pixLineStart = buf + bmp.BackBufferStride * y;
double dy = (y - centerY);
for(int x=0; x < bmp.Width; x++){
double dx = (x - centerX);
double dist = Math.Sqrt(dx * dx + dy * dy);
if (radius2 <= dist && dist <= radius) {
double theta = Math.Atan2(dy, dx);
double hue = (theta + Math.PI) / (2.0 * Math.PI);
*((int*)(pixLineStart + x * 4)) = HSB_to_RGB((int)(hue * 360), saturation, 100);
}
}
}
}
bmp.AddDirtyRect(new Int32Rect(0, 0, 480, 480));
bmp.Unlock();
}
 
static int HSB_to_RGB(int h, int s, int v)
{
var rgb = new int[3];
 
var baseColor = (h + 60) % 360 / 120;
var shift = (h + 60) % 360 - (120 * baseColor + 60 );
var secondaryColor = (baseColor + (shift >= 0 ? 1 : -1) + 3) % 3;
 
//Setting Hue
rgb[baseColor] = 255;
rgb[secondaryColor] = (int) ((Math.Abs(shift) / 60.0f) * 255.0f);
 
//Setting Saturation
for (var i = 0; i < 3; i++)
rgb[i] += (int) ((255 - rgb[i]) * ((100 - s) / 100.0f));
 
//Setting Value
for (var i = 0; i < 3; i++)
rgb[i] -= (int) (rgb[i] * (100-v) / 100.0f);
 
return RGB2int(rgb[0], rgb[1], rgb[2]);
}
 
public static int RGB2int(int r, int g, int b) => r << 16 | g << 8 | b;
</syntaxhighlight>
 
{{out}}
[[File:ColorRing.PNG]]
 
=={{header|Delphi}}==
{{libheader| Winapi.Windows}}
Line 124 ⟶ 231:
{{libheader| Vcl.Imaging.pngimage}}
{{Trans|Kotlin}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Color_wheel;
 
Line 219 ⟶ 326:
Free;
end;
end.</langsyntaxhighlight>
{{out}}
Png Image [https://ibb.co/T0w8KyF].
=={{header|EasyLang}}==
[https://easylang.dev/show/#cod=bZLdboMwDIXveYpzSagaCrTVqi4Pw08CSHSBkG3w9pOBCjK4AKJzPtvBdmt0jqrPYlNmqL4l+tQiMzU4DEpk4B6ACgI+uWeoRmtDJEOAO5kKAtXqkNRCTEkC+BHOlJOR3O1kBFCTZY+s6agYe19hU6FWk3KhMwCzhD9RQsDiiQwCLbmyWdhow3YLOcfs2XjDtjvWOmxywHYLmZnaYa8b1i5s+5/t5eFfvbmOXO5xr6XZ5b+VlA34PCilDUbqC6zG9fFYEhWkjTgjvr07RuSwJwkmeXBgUuueZtR3xsIvBgTEnShzgGJkK1irmf0UbgIaciVtCoHUpl8xhRaD49OGCfgzdkL0cWEIkdzdLNtt9adSIVViiOaVdeBcN9okB8ZL/0gMCHHDSG/HNDK3uPCEntXg3uZLA5h773l/ Run it]
 
{{trans|Go}}
<syntaxhighlight>
proc hsb2rgb hue sat bri . r g b .
h = (hue - floor hue) * 6
f = h - floor h
p = bri * (1 - sat)
q = bri * (1 - sat * f)
t = bri * (1 - sat * (1 - f))
h = floor h
if h = 0
r = bri ; g = t ; b = p
elif h = 1
r = q ; g = bri ; b = p
elif h = 2
r = p ; g = bri ; b = t
elif h = 3
r = p ; g = q ; b = bri
elif h = 4
r = t ; g = p ; b = bri
else
r = bri ; g = p ; b = q
.
.
proc cwheel . .
for y = 0 to 499
dy = y - 250
for x = 0 to 499
dx = x - 250
dist = sqrt (dx * dx + dy * dy)
if dist <= 250
theta = atan2 dy dx
hue = (theta + 180) / 360
hsb2rgb hue (dist / 250) 1 r g b
color3 r g b
move x / 5 y / 5
rect 0.3 0.3
.
.
.
.
cwheel
 
</syntaxhighlight>
 
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Color_wheel}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
'''Solution'''
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
[[File:Fōrmulæ - Color wheel 01.png]]
In '''[https://formulae.org/?example=Color_wheel this]''' page you can see the program(s) related to this task and their results.
 
'''Test case'''
 
Generating a color wheel of 300x300 pixels:
 
[[File:Fōrmulæ - Color wheel 02.png]]
 
[[File:Fōrmulæ - Color wheel 03.png]]
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">#include "fbgfx.bi"
 
Sub HSVtoRGB(h As Single, s As Integer, v As Integer, Byref r As Integer, Byref g As Integer, Byref b As Integer)
If s = 0 Then
r = v
g = v
b = v
Return
End If
h = h Mod 360
Dim As Single hue = h
Select Case h
Case 0f To 51.5f
hue = ((hue ) * (30f / (51.5f )))
Case 51.5f To 122f
hue = ((hue - 51.5f) * (30f / (122f - 51.5f))) + 30
Case 122f To 142.5f
hue = ((hue - 122f) * (30f / (142.5f - 122f))) + 60
Case 142.5f To 165.5f
hue = ((hue - 142.5f) * (30f / (165.5f - 142.5f))) + 90
Case 165.5f To 192f
hue = ((hue - 165.5f) * (30f / (192f - 165.5f))) + 120
Case 192f To 218.5f
hue = ((hue - 192f) * (30f / (218.5f - 192f))) + 150
Case 218.5f To 247f
hue = ((hue - 218.5f) * (30f / (247f - 218.5f))) + 180
Case 247f To 275.5f
hue = ((hue - 247f) * (30f / (275.5f - 247f))) + 210
Case 275.5f To 302.5f
hue = ((hue - 275.5f) * (30f / (302.5f - 275.5f))) + 240
Case 302.5f To 330f
hue = ((hue - 302.5f) * (30f / (330f - 302.5f))) + 270
Case 330f To 344.5f
hue = ((hue - 330f) * (30f / (344.5f - 330f))) + 300
Case 344.5f To 360f
hue = ((hue - 344.5f) * (30f / (360f - 344.5f))) + 330
End Select
h = hue
h = h Mod 360
Dim As Single h1 = h / 60
Dim As Integer i = Int(h1)
Dim As Single f = h1 - i
Dim As Integer p = v * (255 - s) / 256
Dim As Integer q = v * (255 - f * s) / 256
Dim As Integer t = v * (255 - (1 - f) * s) / 256
Select Case As Const i
Case 0
r = v
g = t
b = p
Return
Case 1
r = q
g = v
b = p
Return
Case 2
r = p
g = v
b = t
Return
Case 3
r = p
g = q
b = v
Return
Case 4
r = t
g = p
b = v
Return
Case 5
r = v
g = p
b = q
Return
End Select
End Sub
 
Const pi As Single = 4 * Atn(1)
Const radius = 160
Const xres = (radius * 2) + 1, yres = xres
 
Screenres xres, yres, 32
Windowtitle "Color wheel"
 
Dim As Integer r,g,b
Dim As Single dx, dy, dist, angle
 
Do
Screenlock
Cls
For x As Integer = 0 To (radius * 2) - 1
For y As Integer = 0 To (radius * 2) - 1
dx = x - radius
dy = radius - y
dist = Sqr(dx * dx + dy * dy)
If dist < radius Then
angle = Atan2(dy, dx) * (180/pi)
If angle < 0 Then angle += 360
If angle > 360 Then angle -= 360
HSVtoRGB(angle, (dist / radius) * 255, 255, r, g, b)
Pset(x, y), Rgb(r, g, b)
End If
Next y
Next x
Screenunlock
Loop Until Inkey = Chr(27)</syntaxhighlight>
 
 
 
=={{header|FutureBasic}}==
FB has native functions for programmatically building color wheels.
<syntaxhighlight lang="futurebasic">
_window = 1
begin enum output 1
_colorwheelImageView
end enum
 
void local fn BuildWindow
CGRect r = fn CGRectMake( 0, 0, 400, 400 )
window _window, @"Programmatic Color Wheel", r, NSWindowStyleMaskTitled + NSWindowStyleMaskClosable
r = fn CGRectMake( 20, 20, 360, 360 )
imageview _colorwheelImageView, YES, , r, NSImageScaleProportionallyUpOrDown, NSImageAlignCenter, NSImageFrameNone, _window
end fn
 
local fn CIImageToImageRef( ciImage as CIImageRef ) as ImageRef
CIImageRepRef rep = fn CIImageRepWithCIImage( ciImage )
CGSize size = fn ImageRepSize( rep )
ImageRef image = fn ImageWithSize( size )
ImageAddRepresentation( image, rep )
end fn = image
 
local fn ColorWheelImage( colorSpace as CGColorSpaceRef, dither as CFNumberRef, radius as CFNumberRef, softness as CFNumberRef, lightness as CFNumberRef ) as CIImageRef
CIFilterRef filter = fn CIFilterWithName( @"CIHueSaturationValueGradient" )
ObjectSetValueForkey( filter, colorSpace, @"inputColorSpace" )
ObjectSetValueForkey( filter, dither, @"inputDither" )
ObjectSetValueForkey( filter, radius, @"inputRadius" )
ObjectSetValueForkey( filter, softness, @"inputSoftness" )
ObjectSetValueForkey( filter, lightness, @"inputValue" )
CIImageRef outputCIImage = fn CIFilterOutputImage( filter )
end fn = outputCIImage
 
local fn BuildColorWheel
CIImageRef colorWheelCIImage = fn ColorWheelImage( fn CGColorSpaceCreateDeviceRGB, @0, @160, @0, @1 )
ImageRef colorWheelImage = fn CIImageToImageRef( colorWheelCIImage )
ImageViewSetImage( _colorwheelImageView, colorWheelImage )
end fn
 
fn BuildWindow
fn BuildColorWheel
 
HandleEvents
</syntaxhighlight>
{{output}}
[[File:Programmatic Color Wheel.png]]
 
=={{header|GML}}==
<syntaxhighlight lang="gml">
<lang GML>
for (var i = 1; i <= 360; i++) {
for (var j = 0; j < 255; j++) {
Line 252 ⟶ 579:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Go}}==
{{libheader|Go Graphics}}
{{trans|Kotlin}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 324 ⟶ 651:
colorWheel(dc)
dc.SavePNG("color_wheel.png")
}</langsyntaxhighlight>
 
{{out}}
Line 330 ⟶ 657:
Image is same as Kotlin entry
</pre>
 
=={{header|J}}==
 
<syntaxhighlight lang="j">rgbc=: {{1-x*0>.1<.(<.4&-)6|m+y%60}}
hsv=: 5 rgbc(,"0 1) 3 rgbc(,"0) 1 rgbc
degrees=: {{180p_1*{:"1+.^.y}}
wheel=: {{((1>:|)*|hsv degrees)j./~y%~i:y}}
require'viewmat'
'rgb' viewmat 256#.<.255*wheel 400</syntaxhighlight>
 
The right argument to wheel determines the radius (in pixels) of the color wheel (with a white pixel in the center), so the diameter of the above color wheel is 801 pixels.
 
Here's a representation of wheel 5:
 
<div style="text-align: center; vertical-align: middle; background-color: #000; width: 80px; height: 80px"><br /><div style="font-family: monospace; font-size: 8px; line-height: 0.5em"><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #00ffff">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><br /><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #0062ff">&nbsp;</span><span style="background-color: #1a9aff">&nbsp;</span><span style="background-color: #2ccdff">&nbsp;</span><span style="background-color: #33ffff">&nbsp;</span><span style="background-color: #2cffcd">&nbsp;</span><span style="background-color: #1aff9a">&nbsp;</span><span style="background-color: #00ff62">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><br /><span style="background-color: #000">&nbsp;</span><span style="background-color: #001dff">&nbsp;</span><span style="background-color: #265cff">&nbsp;</span><span style="background-color: #4797ff">&nbsp;</span><span style="background-color: #5dcdff">&nbsp;</span><span style="background-color: #66ffff">&nbsp;</span><span style="background-color: #5dffcd">&nbsp;</span><span style="background-color: #47ff97">&nbsp;</span><span style="background-color: #26ff5c">&nbsp;</span><span style="background-color: #00ff1d">&nbsp;</span><span style="background-color: #000">&nbsp;</span><br /><span style="background-color: #000">&nbsp;</span><span style="background-color: #271aff">&nbsp;</span><span style="background-color: #4752ff">&nbsp;</span><span style="background-color: #6e92ff">&nbsp;</span><span style="background-color: #8cccff">&nbsp;</span><span style="background-color: #99ffff">&nbsp;</span><span style="background-color: #8cffcc">&nbsp;</span><span style="background-color: #6eff92">&nbsp;</span><span style="background-color: #47ff52">&nbsp;</span><span style="background-color: #27ff1a">&nbsp;</span><span style="background-color: #000">&nbsp;</span><br /><span style="background-color: #000">&nbsp;</span><span style="background-color: #642cff">&nbsp;</span><span style="background-color: #7c5dff">&nbsp;</span><span style="background-color: #938cff">&nbsp;</span><span style="background-color: #b6c8ff">&nbsp;</span><span style="background-color: #ccffff">&nbsp;</span><span style="background-color: #b6ffc8">&nbsp;</span><span style="background-color: #93ff8c">&nbsp;</span><span style="background-color: #7cff5d">&nbsp;</span><span style="background-color: #64ff2c">&nbsp;</span><span style="background-color: #000">&nbsp;</span><br /><span style="background-color: #7f00ff">&nbsp;</span><span style="background-color: #9933ff">&nbsp;</span><span style="background-color: #b266ff">&nbsp;</span><span style="background-color: #cc99ff">&nbsp;</span><span style="background-color: #e5ccff">&nbsp;</span><span style="background-color: #ffffff">&nbsp;</span><span style="background-color: #e5ffcc">&nbsp;</span><span style="background-color: #ccff99">&nbsp;</span><span style="background-color: #b2ff66">&nbsp;</span><span style="background-color: #99ff33">&nbsp;</span><span style="background-color: #7fff00">&nbsp;</span><br /><span style="background-color: #000">&nbsp;</span><span style="background-color: #c72cff">&nbsp;</span><span style="background-color: #df5dff">&nbsp;</span><span style="background-color: #f88cff">&nbsp;</span><span style="background-color: #ffb6ec">&nbsp;</span><span style="background-color: #ffcccc">&nbsp;</span><span style="background-color: #ffecb6">&nbsp;</span><span style="background-color: #f8ff8c">&nbsp;</span><span style="background-color: #dfff5d">&nbsp;</span><span style="background-color: #c7ff2c">&nbsp;</span><span style="background-color: #000">&nbsp;</span><br /><span style="background-color: #000">&nbsp;</span><span style="background-color: #f11aff">&nbsp;</span><span style="background-color: #ff47f3">&nbsp;</span><span style="background-color: #ff6eda">&nbsp;</span><span style="background-color: #ff8cbf">&nbsp;</span><span style="background-color: #ff9999">&nbsp;</span><span style="background-color: #ffbf8c">&nbsp;</span><span style="background-color: #ffda6e">&nbsp;</span><span style="background-color: #fff347">&nbsp;</span><span style="background-color: #f1ff1a">&nbsp;</span><span style="background-color: #000">&nbsp;</span><br /><span style="background-color: #000">&nbsp;</span><span style="background-color: #ff00e1">&nbsp;</span><span style="background-color: #ff26c8">&nbsp;</span><span style="background-color: #ff47ae">&nbsp;</span><span style="background-color: #ff5d8f">&nbsp;</span><span style="background-color: #ff6666">&nbsp;</span><span style="background-color: #ff8f5d">&nbsp;</span><span style="background-color: #ffae47">&nbsp;</span><span style="background-color: #ffc826">&nbsp;</span><span style="background-color: #ffe100">&nbsp;</span><span style="background-color: #000">&nbsp;</span><br /><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #ff009c">&nbsp;</span><span style="background-color: #ff1a7f">&nbsp;</span><span style="background-color: #ff2c5d">&nbsp;</span><span style="background-color: #ff3333">&nbsp;</span><span style="background-color: #ff5d2c">&nbsp;</span><span style="background-color: #ff7f1a">&nbsp;</span><span style="background-color: #ff9c00">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><br /><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #ff0000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><br /><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><span style="background-color: #000">&nbsp;</span><br /></div></div>
 
<hr />
 
Here's an online implementation for [https://jsoftware.github.io/j-playground/bin/html2/#code=rgbc%3D%3A%20%7B%7B1-x*0%3E.1%3C.%28%3C.4%26-%296%7Cm%2By%2560%7D%7D%0Ahsv%3D%3A%205%20rgbc%28%2C%220%201%29%203%20rgbc%28%2C%220%29%201%20rgbc%0Adegrees%3D%3A%20%7B%7B180p_1*%7B%3A%221%2B.%5E.y%7D%7D%0Awheel%3D%3A%20%7B%7B%28%281%3E%3A%7C%29*%7Chsv%20degrees%29j.%2F~y%25~i%3Ay%7D%7D%0Arequire'viewmat'%0A'rgb'%20viewmat%20256%23.%3C.255*wheel%2080 wheel 80] (hit "Run" in the upper right corner).
 
=={{header|Java}}==
This program draws a color wheel in a window.
<langsyntaxhighlight lang="java">import java.awt.*;
import javax.swing.*;
 
Line 412 ⟶ 758:
return new Color((int)(r * 255), (int)(g * 255), (int)(b * 255));
}
}</langsyntaxhighlight>
 
{{out}}
[[Media:Color_wheel_java.png]]
Screenshot: [https://slack-files.com/T0CNUL56D-F016R4Q5J3D-1b15b1286a color_wheel_java.png] (offsite PNG image)
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Gtk, Graphics, Colors
 
const win = GtkWindow("Color Wheel", 450, 450) |> (const can = @GtkCanvas())
Line 444 ⟶ 790:
signal_connect(endit, win, :destroy)
wait(condition)
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
We reuse the class in the Bitmap task for this and add a member function to draw the color wheel. To give a more 'wheel-like' image, a constant 'saturation' of 1.0 has been used rather than one which varies in line with distance from the center.
<langsyntaxhighlight lang="scala">// Version 1.2.41
 
import java.awt.Color
Line 499 ⟶ 845:
}
}
</syntaxhighlight>
</lang>
 
{{output}}
Line 505 ⟶ 851:
Looks like mirror image of Smart BASIC entry
</pre>
 
 
=={{header|Lua}}==
{{libheader|LÖVE}}
<syntaxhighlight lang="lua">
local function hsv_to_rgb (h, s, v) -- values in ranges: [0, 360], [0, 1], [0, 1]
local r = math.min (math.max (3*math.abs (((h )/180)%2-1)-1, 0), 1)
local g = math.min (math.max (3*math.abs (((h -120)/180)%2-1)-1, 0), 1)
local b = math.min (math.max (3*math.abs (((h +120)/180)%2-1)-1, 0), 1)
local k1 = v*(1-s)
local k2 = v - k1
return k1+k2*r, k1+k2*g, k1+k2*b -- values in ranges: [0, 1], [0, 1], [0, 1]
end
 
function love.load()
local w, h, r = 256, 256, 128-0.5
local cx, cy = w/2, h/2
canvas = love.graphics.newCanvas ()
love.graphics.setCanvas(canvas)
for x = 0, w do
for y = 0, h do
local dx, dy = x-cx, y-cy
if dx*dx + dy*dy <= r*r then
local h = math.deg(math.atan2(dy, dx))
local s = (dx*dx + dy*dy)^0.5/r
local v = 1
love.graphics.setColor (hsv_to_rgb (h, s, v))
love.graphics.points (x, y)
end
end
end
love.graphics.setCanvas()
end
 
function love.draw()
love.graphics.setColor (1,1,1)
love.graphics.draw (canvas)
end
</syntaxhighlight>
 
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module Check {
\\ we use an internal object for Math functions (here for Atan2)
Line 587 ⟶ 972:
}
Check
</syntaxhighlight>
</lang>
{{out}}
see [https://4.bp.blogspot.com/-0swVvNDaTjE/XDlPfuGQkBI/AAAAAAAAHno/wU3eyo1BUIEtPjZMyjGXkbN425zHJlc7wCLcBGAs/s1600/colorwheel.png this image]
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">r = 100;
Image[Table[
If[x^2 + y^2 <= r^2,
Line 600 ⟶ 985:
{1, 1, 1}
], {x, -r, r}, {y, -r, r}]
]</langsyntaxhighlight>
{{out}}
Outputs an image.
Line 610 ⟶ 995:
As Rust code does, we store the color wheel in a PNG image.
 
<langsyntaxhighlight Nimlang="nim">import math
 
import imageman
Line 676 ⟶ 1,061:
image.buildColorWheel()
 
image.savePNG(Output, compression = 9)</langsyntaxhighlight>
 
=={{header|Perl}}==
{{trans|Sidef}}
<langsyntaxhighlight lang="perl">use Imager;
use Math::Complex qw(cplx i pi);
 
Line 701 ⟶ 1,086:
}
 
$img->write(file => 'color_wheel.png');</langsyntaxhighlight>
 
=={{header|Phix}}==
Line 707 ⟶ 1,092:
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/Colour_wheel.htm here].
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Colour_wheel.exw
Line 766 ⟶ 1,151:
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
 
=={{header|Processing}}==
 
<langsyntaxhighlight lang="java">size(300, 300);
background(0);
float radius = min(width, height) / 2.0;
Line 787 ⟶ 1,172:
}
}
}</langsyntaxhighlight>
 
==={{header|Processing Python mode}}===
 
<langsyntaxhighlight lang="python">size(300, 300)
background(0)
radius = min(width, height) / 2.0
Line 804 ⟶ 1,189:
colorMode(HSB)
c = color(int(h * 255), int(s * 255), 255)
set(x, y, c) # note set() used as Processing set() not as Python set()</langsyntaxhighlight>
 
 
=={{header|Plain English}}==
<syntaxhighlight lang="plainenglish">
To draw the color wheel:
Start with the red color.
Turn right 80 points.
Loop.
If the user clicks on the screen, break.
Move to the center of the screen.
Draw a line 2 inches long.
Refresh the screen.
Change the current hue by 10 points.
Turn right 10 points.
Add 1 to a count.
If the count is 384, break. \ Plain English uses a circle divided into 384 degrees
Repeat.
Start in the middle of the screen facing north minus 80 points.
Use medium-sized letters.
Write "RED......YELLOW.....GREEN......CYAN......BLUE.....MAGENTA......" with the white pen 2-1/4 inches from the screen's center.
Refresh the screen.
Shut down.
</syntaxhighlight>
 
=={{header|Python}}==
 
<langsyntaxhighlight lang="python">from PIL import Image
import colorsys
import math
Line 829 ⟶ 1,237:
pix[x,y] = tuple([int(round(c*255.0)) for c in rgb])
 
im.show()</langsyntaxhighlight>
 
=={{header|Racket}}==
Line 835 ⟶ 1,243:
With the colors package
 
<langsyntaxhighlight lang="racket">#lang racket
 
(require racket/draw
Line 858 ⟶ 1,266:
(send dc draw-point x y))
 
target</langsyntaxhighlight>
 
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2016.08}}
[[File:Color-wheel-perl6.png|thumb]]
 
<syntaxhighlight lang="raku" perl6line>use Image::PNG::Portable;
 
my ($w, $h) = 300, 300;
Line 899 ⟶ 1,307:
when 5/6..1 { $c, 0, $x }
} ).map: ((*+$m) * 255).Int
}</langsyntaxhighlight>
 
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|Ring}}==
 
[https://kepfeltoltes.zapto.org/public/20210909181910ColorWheel20210912082335ColorWheel.jpg Color wheel - image]
 
<syntaxhighlight lang="ring">
#===================================================================#
# Sample: Color Wheel
# Author: Gal Zsolt, Bert Mariani, Ilir Liburn & Mahmoud Fayed
#===================================================================#
 
<lang ring>
load "stdlib.ring"
load "guilib.ring"
xWidth = 400
yHeight = 400
MyApp = new qapp
{
win1 = new qwidget()
{ setwindowtitle("ColorWheel-FastDraw")
setgeometry(500,150,xWidth,yHeight)
Canvas = new qlabel(win1)
{ ### daVinci paints the MonaLisa on the Canvas
MonaLisa = new qPixMap2( xWidth, yHeight)
color = new qcolor(){ setrgb(255,255,255,0) }
pen = new qpen() { setwidth(1) }
MonaLisa.fill(color)
 
daVinci = new qpainter()
paint = null
{ begin(MonaLisa)
#endpaint() ### This will Stop the Painting. For Animation comment it out
}
setPixMap(MonaLisa)
}
show()
}
ColorWheel()
exec()
}
//=====================
Func colorWheel
 
#=====================================================================#
new qapp { win1 = new qwidget()
? "Start Processing..."
{
t1 = clock()
setwindowtitle("Color wheel")
? "Clock : " + t1
setgeometry(540,140,400,400)
#=====================================================================#
label1 = new qlabel(win1) {
setgeometry(30,30,320,320)
settext("")
}
show()
}
draw()
exec()
}
 
aList = []
func draw
pi p1 = new qpicture() = 3.14159265359
paintdiameter = newpi qpainter()* {2
radius = yHeight / 2
begin(p1)
v = 1 // value/brightness 1 to 100 1=bright 0=dark
colorWheel()
 
endpaint()
for i }= 1 to xWidth
iradius = i - radius
label1 { setpicture(p1) show() }
p = pow( iradius, 2)
 
for j = 1 to yHeight
 
h = (atan2( iradius, j-radius ) + pi ) / diameter // hue/color 1 to 360
s = sqrt( p + pow( j-radius, 2)) / radius // saturation/intensity 1 to 100
if s <= 1 and h <= 1
aList + [i,j,h,s,v,1]
ok
next
next
 
#=====================================================================#
func colorWheel()
? "Start pi = 3drawing.14.."
radiust2 = 150clock()
? "Clock x: =" win1.width()+ t2
#=====================================================================#
y = win1.height()
 
daVinci.drawHSVFList(aList)
for i=1 to x
Canvas.setPixMap(MonaLisa)
for j=1 to y
color = new qcolor(){ setrgb(255,255,255,255) }
h = (atan2(i-radius,j-radius)+pi)/(2*pi)
s = sqrt(pow(i-radius,2)+pow(j-radius,2))/radius
v = 1
if s < = 1 and h < = 1
color.setHsvF(h,s,v,1)
pen1 = new qpen() { setcolor(color) setwidth(5) }
paint.setPen(pen1)
paint.drawPoint(i,j)
ok
 
#=====================================================================#
next
? next"Done..."
t3 = clock()
</lang>
? "Clock : " + t3
#=====================================================================#
? "Processing Time: " + ( (t2-t1)/ClocksPerSecond() ) + " seconds "
? "Drawing Time: " + ( (t3-t2)/ClocksPerSecond() ) + " seconds "
? "Total Time: " + ( (t3-t1)/ClocksPerSecond() ) + " seconds "
#=====================================================================#
return
//==================
</syntaxhighlight>
 
=={{header|Ruby}}==
{{libheader|RubyGems}}
{{libheader|JRubyArt}}
<langsyntaxhighlight lang="ruby">
def settings
size(300, 300)
Line 984 ⟶ 1,433:
end
end
</syntaxhighlight>
</lang>
 
=={{header|Run BASIC}}==
<langsyntaxhighlight Runbasiclang="runbasic">' -----------------------------------
' color wheel
' -----------------------------------
global pi
pi = 22 / 7
steps = 1
 
graphic #g, 525, 525
Line 998 ⟶ 1,447:
 
for x =0 to 525 step steps
for y =0 to 525 step steps
angle = atan2(y - 250, x - 250) * 360 / 2 / pi ' full degrees....
sector = int(angle / 60) ' 60 degree sectors (0 to 5)
slope = (angle mod 60) /60 * 255 ' 1 degree sectors.
if sector = 0 then col$ = "255 "; str$( int( slope)); " 0"
if sector = 1 then col$ = str$(int(256 - slope)); " 255 0"
if sector = 2 then col$ = "0 255 "; str$( int( slope))
if sector = 3 then col$ = "0 "; str$( int( 256 -slope)); " 255"
if sector = 4 then col$ = str$(int(slope)); " 0 255"
if sector = 5 then col$ = "255 0 "; str$( int( 256 -slope))
red = val( word$( col$, 1))
grn = val( word$( col$, 2))
blu = val( word$( col$, 3))
p = ((x -270)^2 +(y -270)^2)^0.5 / 250
r = min(255,p * red)
g = min(255,p * grn)
b = min(255,p * blu)
if p > 1 then #g "color white" else #g color(r,g,b)
#g "set "; x; " "; y
next y
next x
render #g
Line 1,026 ⟶ 1,475:
function atan2(y,x)
if (x = 0) and (y <> 0) then
r$ = "Y"
if y > 0 then atan2 = pi /2
if y < 0 then atan2 = 3 * pi /2
end if
 
if y = 0 and (x <> 0) then
r$ = "Y"
if x > 0 then atan2 = 0
if x < 0 then atan2 = pi
end if
 
If r$ <> "Y" then
if x = 0 and y = 0 then
atan2 = 0
else
baseAngle = atn(abs(y) / abs(x))
if x > 0 then
if y > 0 then atan2 = baseAngle
If y < 0 then atan2 = 2 * pi - baseAngle
end if
if x < 0 then
If y > 0 then atan2 = pi - baseAngle
If y < 0 then atan2 = pi + baseAngle
end if
end if
end if
end function</langsyntaxhighlight>
 
=={{header|Rust}}==
Output is a file in PNG format.
<langsyntaxhighlight lang="rust">// [dependencies]
// image = "0.23"
 
Line 1,122 ⟶ 1,571:
Err(error) => eprintln!("{}", error),
}
}</langsyntaxhighlight>
 
{{out}}
[[Media:Color_wheel_rust.png]]
See: [https://slack-files.com/T0CNUL56D-F016QPS7D98-a25dc55ad4 color_wheel.png] (offsite PNG image)
 
=={{header|Sidef}}==
{{trans|Raku}}
<langsyntaxhighlight lang="ruby">require('Imager')
 
var (width, height) = (300, 300)
Line 1,145 ⟶ 1,594:
}
 
img.write(file => 'color_wheel.png')</langsyntaxhighlight>
Output image: [https://github.com/trizen/rc/blob/master/img/color-wheel-sidef.png Color wheel]
=={{header|Smart BASIC}}==
<langsyntaxhighlight lang="smart basic">' Runs on iOS
GET SCREEN SIZE sw,sh
xmax=0.45*3/7*(sw+sh)
Line 1,193 ⟶ 1,642:
s5: r=f ! g=0 ! b=1 ! GOTO done
s6: r=1 ! g=0 ! b=z ! done:
END DEF</langsyntaxhighlight>
View the output on Dropbox
https://www.dropbox.com/s/g3l5rbywo34bnp6/IMG_4600.PNG?dl=0
This file is no longer there!!! 10 Sep 2021
 
=={{header|Vala}}==
{{trans|Julia}}
<syntaxhighlight lang="vala">public class Example: Gtk.Application {
private Gtk.ApplicationWindow window;
private Gtk.DrawingArea drawing_area;
public Example() {
Object(application_id: "my.application", flags: ApplicationFlags.FLAGS_NONE);
this.activate.connect(() => {
window = new Gtk.ApplicationWindow(this);
drawing_area = new Gtk.DrawingArea();
drawing_area.set_draw_func(draw_circle);
window.set_child(drawing_area);
window.present();
});
}
 
private void draw_circle(Gtk.DrawingArea area, Cairo.Context cr, int width, int height) {
int centerx = width / 2;
int centery = height / 2;
double anglestep = 1.0 / width;
for (float theta = (float) 0.0; theta < 360; theta += (float) 0.1) {
float r;
float g;
float b;
Gtk.hsv_to_rgb(theta / (float) 360.0, 1, 1, out r, out g, out b);
cr.set_source_rgb(r, g, b);
cr.line_to(centerx, centery);
cr.arc(centerx, centery, ((double) width) / 2.2, GLib.Math.PI * 2 * theta / 360.0, anglestep);
cr.line_to(centerx, centery);
cr.stroke();
}
}
 
public static int main(string[] argv) {
var app = new Example();
return app.run(argv);
}
}</syntaxhighlight>
=={{header|VBScript}}==
Building a BMP file and opening it with the default viewer. It takes 5 seconds in my 5 years old notebook. Run with Cscript if you don want to be clicking at annoying message boxes.
<syntaxhighlight lang="vb">
Option explicit
 
Class ImgClass
Private ImgL,ImgH,ImgDepth,bkclr,loc,tt
private xmini,xmaxi,ymini,ymaxi,dirx,diry
public ImgArray() 'rgb in 24 bit mode, indexes to palette in 8 bits
private filename
private Palette,szpal
public property get xmin():xmin=xmini:end property
public property get ymin():ymin=ymini:end property
public property get xmax():xmax=xmaxi:end property
public property get ymax():ymax=ymaxi:end property
public property let depth(x)
if x<>8 and x<>32 then err.raise 9
Imgdepth=x
end property
public sub set0 (x0,y0) 'sets the new origin (default tlc). The origin does'nt work if ImgArray is accessed directly
if x0<0 or x0>=imgl or y0<0 or y0>imgh then err.raise 9
xmini=-x0
ymini=-y0
xmaxi=xmini+imgl-1
ymaxi=ymini+imgh-1
end sub
'constructor
Public Default Function Init(name,w,h,orient,dep,bkg,mipal)
'offx, offy posicion de 0,0. si ofx+ , x se incrementa de izq a der, si offy+ y se incrementa de abajo arriba
dim i,j
ImgL=w
ImgH=h
tt=timer
loc=getlocale
' not useful as we are not using SetPixel and accessing ImgArray directly
set0 0,0 'origin blc positive up and right
redim imgArray(ImgL-1,ImgH-1)
bkclr=bkg
if bkg<>0 then
for i=0 to ImgL-1
for j=0 to ImgH-1
imgarray(i,j)=bkg
next
next
end if
Select Case orient
Case 1: dirx=1 : diry=1
Case 2: dirx=-1 : diry=1
Case 3: dirx=-1 : diry=-1
Case 4: dirx=1 : diry=-1
End select
filename=name
ImgDepth =dep
'load user palette if provided
if imgdepth=8 then
loadpal(mipal)
end if
set init=me
end function
 
private sub loadpal(mipale)
if isarray(mipale) Then
palette=mipale
szpal=UBound(mipale)+1
Else
szpal=256
'Default palette recycled from ATARI
'removed
 
, not relevant
End if
End Sub
 
'class termination writes it to a BMP file and displays it
'if an error happens VBS terminates the class before exiting so the BMP is displayed the same
Private Sub Class_Terminate
if err<>0 then wscript.echo "Error " & err.number
wscript.echo "copying image to bmp file"
savebmp
wscript.echo "opening " & filename & " with your default bmp viewer"
CreateObject("Shell.Application").ShellExecute filename
wscript.echo timer-tt & " iseconds"
End Sub
function long2wstr( x) 'falta muy poco!!!
dim k1,k2,x1
k1= (x and &hffff&)' or (&H8000& And ((X And &h8000&)<>0)))
k2=((X And &h7fffffff&) \ &h10000&) Or (&H8000& And (x<0))
long2wstr=chrw(k1) & chrw(k2)
end function
function int2wstr(x)
int2wstr=ChrW((x and &h7fff) or (&H8000 And (X<0)))
End Function
 
 
Public Sub SaveBMP
'Save the picture to a bmp file
Dim s,ostream, x,y,loc
const hdrs=54 '14+40
dim bms:bms=ImgH* 4*(((ImgL*imgdepth\8)+3)\4) 'bitmap size including padding
dim palsize:if (imgdepth=8) then palsize=szpal*4 else palsize=0
 
with CreateObject("ADODB.Stream") 'auxiliary ostream, it creates an UNICODE with bom stream in memory
.Charset = "UTF-16LE" 'o "UTF16-BE"
.Type = 2' adTypeText
.open
'build a header
'bmp header: VBSCript does'nt have records nor writes binary values to files, so we use strings of unicode chars!!
'BMP header
.writetext ChrW(&h4d42) ' 0 "BM" 4d42
.writetext long2wstr(hdrs+palsize+bms) ' 2 fiesize
.writetext long2wstr(0) ' 6 reserved
.writetext long2wstr (hdrs+palsize) '10 image offset
'InfoHeader
.writetext long2wstr(40) '14 infoheader size
.writetext long2wstr(Imgl) '18 image length
.writetext long2wstr(imgh) '22 image width
.writetext int2wstr(1) '26 planes
.writetext int2wstr(imgdepth) '28 clr depth (bpp)
.writetext long2wstr(&H0) '30 compression used 0= NOCOMPR
.writetext long2wstr(bms) '34 imgsize
.writetext long2wstr(&Hc4e) '38 bpp hor
.writetext long2wstr(&hc43) '42 bpp vert
.writetext long2wstr(szpal) '46 colors in palette
.writetext long2wstr(&H0) '50 important clrs 0=all
'write bitmap
'precalc data for orientation
Dim x1,x2,y1,y2
If dirx=-1 Then x1=ImgL-1 :x2=0 Else x1=0:x2=ImgL-1
If diry=-1 Then y1=ImgH-1 :y2=0 Else y1=0:y2=ImgH-1
Select Case imgdepth
Case 32
For y=y1 To y2 step diry
For x=x1 To x2 Step dirx
'writelong fic, Pixel(x,y)
.writetext long2wstr(Imgarray(x,y))
Next
Next
Case 8
'palette
For x=0 to szpal-1
.writetext long2wstr(palette(x)) '52
Next
'image
dim pad:pad=ImgL mod 4
For y=y1 to y2 step diry
For x=x1 To x2 step dirx*2
.writetext chrw((ImgArray(x,y) and 255)+ &h100& *(ImgArray(x+dirx,y) and 255))
Next
'line padding
if pad and 1 then .writetext chrw(ImgArray(x2,y))
if pad >1 then .writetext chrw(0)
Next
Case Else
WScript.Echo "ColorDepth not supported : " & ImgDepth & " bits"
End Select
 
'use a second stream to save to file starting past the BOM the first ADODB.Stream has added
Dim outf:Set outf= CreateObject("ADODB.Stream")
outf.Type = 1 ' adTypeBinary
outf.Open
.position=2 'remove bom (1 wchar)
.CopyTo outf
.close
outf.savetofile filename,2 'adSaveCreateOverWrite
outf.close
end with
End Sub
end class
 
 
 
function hsv2rgb( Hue, Sat, Value) 'hue 0-360 0-ro 120-ver 240-az ,sat 0-100,value 0-100
dim Angle, Radius,Ur,Vr,Wr,Rdim
dim r,g,b, rgb
Angle = (Hue-150) *0.01745329251994329576923690768489
Ur = Value * 2.55
Radius = Ur * tan(Sat *0.01183199)
Vr = Radius * cos(Angle) *0.70710678 'sqrt(1/2)
Wr = Radius * sin(Angle) *0.40824829 'sqrt(1/6)
r = (Ur - Vr - Wr)
g = (Ur + Vr - Wr)
b = (Ur + Wr + Wr)
'clamp values
if r >255 then
Rdim = (Ur - 255) / (Vr + Wr)
r = 255
g = Ur + (Vr - Wr) * Rdim
b = Ur + 2 * Wr * Rdim
elseif r < 0 then
Rdim = Ur / (Vr + Wr)
r = 0
g = Ur + (Vr - Wr) * Rdim
b = Ur + 2 * Wr * Rdim
end if
 
if g >255 then
Rdim = (255 - Ur) / (Vr - Wr)
r = Ur - (Vr + Wr) * Rdim
g = 255
b = Ur + 2 * Wr * Rdim
elseif g<0 then
Rdim = -Ur / (Vr - Wr)
r = Ur - (Vr + Wr) * Rdim
g = 0
b = Ur + 2 * Wr * Rdim
end if
if b>255 then
Rdim = (255 - Ur) / (Wr + Wr)
r = Ur - (Vr + Wr) * Rdim
g = Ur + (Vr - Wr) * Rdim
b = 255
elseif b<0 then
Rdim = -Ur / (Wr + Wr)
r = Ur - (Vr + Wr) * Rdim
g = Ur + (Vr - Wr) * Rdim
b = 0
end If
'b lowest byte, red highest byte
hsv2rgb= ((b and &hff)+256*((g and &hff)+256*(r and &hff))and &hffffff)
end function
 
function ang(col,row)
'if col =0 then if row>0 then ang=0 else ang=180:exit function
if col =0 then
if row<0 then ang=90 else ang=270 end if
else
if col>0 then
ang=atn(-row/col)*57.2957795130
else
ang=(atn(row/-col)*57.2957795130)+180
end if
end if
ang=(ang+360) mod 360
end function
 
 
Dim X,row,col,fn,tt,hr,sat,row2
const h=160
const w=160
const rad=159
const r2=25500
tt=timer
fn=CreateObject("Scripting.FileSystemObject").GetSpecialFolder(2)& "\testwchr.bmp"
Set X = (New ImgClass)(fn,w*2,h*2,1,32,0,0)
 
x.set0 w,h
'wscript.echo x.xmax, x.xmin
 
for row=x.xmin+1 to x.xmax
row2=row*row
hr=int(Sqr(r2-row2))
For col=hr To 159
Dim a:a=((col\16 +row\16) And 1)* &hffffff
x.imgArray(col+160,row+160)=a
x.imgArray(-col+160,row+160)=a
next
for col=-hr to hr
sat=100-sqr(row2+col*col)/rad *50
' wscript.echo c,r
x.imgArray(col+160,row+160)=hsv2rgb(ang(row,col)+90,100,sat)
next
'script.echo row
next
Set X = Nothing
 
 
</syntaxhighlight>
 
=={{out}}==
[[File:Colorwheel vbs.png]]
 
=={{header|Wren}}==
{{libheader|DOME}}
<langsyntaxhighlight ecmascriptlang="wren">import "graphics" for Canvas, Color
import "dome" for Window
import "random" for Random
Line 1,235 ⟶ 2,010:
 
static draw(alpha) {}
}</langsyntaxhighlight>
 
=={{header|XPL0}}==
Algorithm is from "Computer Graphics ..." by Foley et al. The output is the same as Zkl.
<langsyntaxhighlight XPL0lang="xpl0">def Radius = 480/2;
real Hue, Sat, Dist, I, F, P, Q, T;
real XX, YY, RR, GG, BB;
Line 1,276 ⟶ 2,051:
];
];
]</langsyntaxhighlight>
 
=={{header|zkl}}==
Uses Image Magick and
the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl
<langsyntaxhighlight lang="zkl">var w=300,h=300,out=PPM(w,h);
colorWheel(out);
out.writeJPGFile("colorWheel.zkl.jpg");
Line 1,290 ⟶ 2,065:
v,hue:=(x - zero).toFloat().toPolar(y - zero);
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);
}
}
Line 1,298 ⟶ 2,073:
 
fcn hsv2rgb(hue,v,s){ // 0<=H<360, 0<=v(brightness)<=1, 0<=saturation<=1
// --> 24 bit RGB each R,G,B in [0..255]
to24bit:=fcn(r,g,b,m){
r,g,b=((r+m)*255).toInt(),((g+m)*255).toInt(),((b+m)*255).toInt();
Line 1,311 ⟶ 2,086:
else if(180<=hue<240) return(to24bit(0.0,x, c, m));
else if(240<=hue<300) return(to24bit(x, 0.0,c, m));
else return(to24bit(c, 0.0,x, m));
}</langsyntaxhighlight>
{{out}}
See [http://www.zenkinetic.com/Images/RosettaCode/colorWheel.zkl.jpg this image]
1,973

edits