? Simple Trigonometric Hue ● SmileBASIC Source

Sign In

*Usernames are case-sensitive
Forgot my password

Simple Trigonometric Hue

Some hue algorithms can appear overly choppy when dealing with color blending. Most programmers seem to use linear algorithms to calculate hue, but the complexity, speed, and overall look can be greatly improved by simply implementing SINE as the blending method. This definition will change GCOLOR depending on what hues and values are given to it: '1st parameter = hue = 0 to 1 will cover the entire spectrum '2nd parameter = value = 0 (black) to 1, anything above 1 will separate the colors further DEF HUE H,V VAR R,G,B,P=PI() R=SIN(P*H)*V G=SIN(P*(H+1/3))*V B=SIN(P*(H+2/3))*V GCOLOR RGB(R*R*255,G*G*255,B*B*255) END Here is a test program: FOR Y=0 TO 240 FOR X=0 TO 400 HUE X/400,Y/240*2 GPSET X,Y NEXT NEXT GLINE 0,120,400,120,#WHITE Which will display this output: Where the white line represents a value of one, a.k.a. a perfect hue.


Only hue and value can be controlled, no saturation, therefore this function cannot cover every possible color, but only those that are considered hue colors.
5 votes
1 Comment(s) 12Me21 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself PI() is a constant, so using P=PI() is actually slower than writing PI() each time. DATA 1,2,3,PI(),4 ?CHKCALL("PI") '0 ?CALL("PI") 'errorDEF PI() 'no error RETURN 3.2 ENDSB is weird...