旋转蛇

基于VS2019   EasyX插件   C/C++

 旋转蛇

#include<conio.h>
#include<graphics.h>
#include<iostream>
using namespace std;

int main()
{
	float Pi = 3.14159;
	initgraph(800, 600);

	setbkcolor(RGB(128, 128, 128));//设置背景颜色为灰色
	cleardevice();//以背景颜色清空画布

	int centerX = 150;//圆心
	int centerY = 150;
	int radius = 100;//圆半径
	setlinecolor(RED);
	//circle(centerX, centerY, radius);

	int left, right, top, bottom;
	left = centerX - radius;//圆外切矩形左上角x坐标
	top = centerY - radius;//圆外切矩形左上角y坐标
	right = centerX + radius;//圆外切矩形右下角y坐标
	bottom = centerY + radius;//圆外切矩形右下角y坐标

	float offset;
	float totalOffset = 0;//不同半径之间的角度偏移量

	//void solidpie(
	//	int left,//圆外切矩形左上角x坐标
	//	int top,//圆外切矩形左上角y坐标
	//	int right,//圆外切矩形右下角y坐标
	//	int bottom,//圆外切矩形右下角y坐标
	//	double stangle,//扇形的起始角的弧度
	//	double endangle//扇形的终止角的弧度
	//);
	while (1)
	{
		for (centerX = 100; centerX < 800; centerX = centerX + 200)
		{
			for (centerY = 100; centerY < 600; centerY = centerY + 200)
			{
				for (int radius = 100; radius > 0; radius = radius - 25)
				{
					left = centerX - radius;//圆外切矩形左上角x坐标
					top = centerY - radius;//圆外切矩形左上角y坐标
					right = centerX + radius;//圆外切矩形右下角y坐标
					bottom = centerY + radius;//圆外切矩形右下角y坐标

					for (int j = 0; j < 20; j++)
					{
						float h = rand() % 180;//使用随机数
						COLORREF color1 = HSVtoRGB(h, 0.9, 0.8);//利用HSV函数来随机生成两种颜色
						COLORREF color2 = HSVtoRGB(h + 180, 0.9, 0.8);
						offset = j * Pi / 10 + totalOffset;
						setfillcolor(color1);
						solidpie(left, top, right, bottom, offset, 2 * Pi / 60 + offset);
						setfillcolor(RGB(255, 255, 255));
						solidpie(left, top, right, bottom, 2 * Pi / 60 + offset, 3 * Pi / 60 + offset);
						setfillcolor(color2);
						solidpie(left, top, right, bottom, 3 * Pi / 60 + offset, 5 * Pi / 60 + offset);
						setfillcolor(RGB(0, 0, 0));
						solidpie(left, top, right, bottom, 5 * Pi / 60 + offset, 6 * Pi / 60 + offset);
					}
					totalOffset = totalOffset + Pi / 20;
				}
			}
		}
		_getch();
	}
	closegraph();
	return 0;
}

注释

1、solidpie()

该函数使用当前填充样式绘制无外框的填充扇形
void solidpie(
int left,//圆外切矩形左上角x坐标
int top,//圆外切矩形左上角y坐标
int right,//圆外切矩形右下角y坐标
int bottom,//圆外切矩形右下角y坐标
double stangle,//扇形的起始角的弧度
double endangle//扇形的终止角的弧度
);

2、setbkcolor()

这个函数用于设置当前设备绘图背景色
void setbkcolor(COLORREF color);
eg:设置背景颜色为灰色
setbkcolor(RGB(128, 128, 128));

3、setfillcolor()

这个函数用于设置当前设备填充颜色
void setfillcolor(COLORREF color);
eg:
setfillcolor(RGB(255, 255, 255));
setfillcolor(color1);

4、HSVtoRGB

该函数用于转换 HSV 颜色为 RGB 颜色
COLORREF HSVtoRGB(
	float H,
	float S,
	float V
);

H
原 HSV 颜色模型的 Hue(色相) 分量,0 <= H < 360。
S
原 HSV 颜色模型的 Saturation(饱和度) 分量,0 <= S <= 1。
V
原 HSV 颜色模型的 Value(明度) 分量,0 <= V <= 1。

eg:
COLORREF color1 = HSVtoRGB(h, 0.9, 0.8);
COLORREF color2 = HSVtoRGB(h + 180, 0.9, 0.8);

成品截图

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值