Rainbow

The program is HSL color model application example, the program by adjusting the brightness of HSL model to draw the gradient of the sky, and adjusting the hue to draw seven colors of the rainbow.

// Compiler Env: Visual C++ 6.0~2019,EasyX_20190719
// https://easyx.cn
//
#include <graphics.h>
#include <conio.h>

int main()
{
	// Create a graphics window
	initgraph(640, 480);

	// Draw a gradual sky (gradual increase through brightness)
	float H = 190;		// Hue
	float S = 1;		// Saturation
	float L = 0.7f;		// Lightness
	for(int y = 0; y < 480; y++)
	{
		L += 0.0005f;
		setlinecolor( HSLtoRGB(H, S, L) );
		line(0, y, 639, y);
	}

	// Draw a rainbow (gradually increase through the hue)
	H = 0;
	S = 1;
	L = 0.5f;
	setlinestyle(PS_SOLID, 2);		// Set the line width to 2
	for(int r = 400; r > 344; r--)
	{
		H += 5;
		setlinecolor( HSLtoRGB(H, S, L) );
		circle(500, 480, r);
	}

	// Press any key to exit
	_getch();
	closegraph();
	return 0;
}

For more examples, please refer to https://codebus.cn