How to resolve the algorithm Color wheel step by step in the XPL0 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Color wheel step by step in the XPL0 programming language
Table of Contents
Problem Statement
Write a function to draw a HSV color wheel 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.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Color wheel step by step in the XPL0 programming language
Source code in the xpl0 programming language
def Radius = 480/2;
real Hue, Sat, Dist, I, F, P, Q, T;
real XX, YY, RR, GG, BB;
int X, Y, R, G, B;
def Pi = 3.141592654;
def V = 1.; \Value
[SetVid($112); \640x480x24 graphics
for Y:= -Radius to Radius do
for X:= -Radius to Radius do
[XX:= float(X);
YY:= float(Y);
Dist:= sqrt(XX*XX + YY*YY);
if Dist <= float(Radius) then
[Sat:= Dist/float(Radius); \0 >= Sat <= 1
Hue:= ATan2(YY, XX); \-Pi >= Hue <= Pi
if Hue < 0. then Hue:= Hue + 2.*Pi;
Hue:= Hue * 180./Pi; \radians to degrees
Hue:= Hue / 60.; \0 >= Hue < 6
I:= Floor(Hue); \integer part of Hue
F:= Hue - I; \fractional part of Hue
P:= 1. - Sat;
Q:= 1. - Sat*F;
T:= 1. - Sat*(1.-F);
case fix(I) of
0: [RR:= V; GG:= T; BB:= P];
1: [RR:= Q; GG:= V; BB:= P];
2: [RR:= P; GG:= V; BB:= T];
3: [RR:= P; GG:= Q; BB:= V];
4: [RR:= T; GG:= P; BB:= V];
5: [RR:= V; GG:= P; BB:= Q]
other [exit 1];
R:= fix(RR*255.);
G:= fix(GG*255.);
B:= fix(BB*255.);
Point(X+Radius, Radius-Y, R<<16+G<<8+B);
];
];
]
You may also check:How to resolve the algorithm Validate International Securities Identification Number step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm Abundant, deficient and perfect number classifications step by step in the MAD programming language
You may also check:How to resolve the algorithm Zig-zag matrix step by step in the Tcl programming language
You may also check:How to resolve the algorithm Esthetic numbers step by step in the Wren programming language
You may also check:How to resolve the algorithm Fusc sequence step by step in the Python programming language