#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include <iostream>
using namespace std;
int main() {
float PI = 3.14159;
initgraph(800, 600);
setbkcolor(RGB(128, 128, 128));//设置背景颜色为灰色
cleardevice();//用新背景色去清空屏幕,没有这句的话,背景还会是默认的黑色
int circle_x, circle_y, radius;
circle_x = 100; circle_y = 100; radius = 100;
float offset;
float totaloffset = 0;
int i;
for (int x=0;x<3;x++)//一行行画
{
for (int y = 0; y < 4; y++)//一行画了四个彩色圆
{
float h = rand() % 180;
COLORREF color1 = HSVtoRGB(h, 0.9, 0.8);
COLORREF color2 = HSVtoRGB(h+180, 0.9, 0.8);//扇形有四种颜色,除黑白二色外,其他颜色是随机的
for (radius = 100; radius > 0; radius = radius - 25)//画同心圆先画大的后画小的,因为先画的会覆盖后画的
{
int left = circle_x - radius;
int right = circle_x + radius;
int top = circle_y - radius;
int bottom = circle_y + radius;//用圆心和半径去描述扇形外界矩形的左上和右下坐标,方便思考
for (i = 0; i < 20; i++)//每组扇形有四个颜色,占角度PI/10,所以要画20组
{
offset = i * PI / 10 + totaloffset;//totaloffset是因为每个同心圆扭一些角度
setfillcolor(color1);
solidpie(left, top, right, bottom, offset, offset + 2 * PI / 60);
setfillcolor(RGB(255, 255, 255));
solidpie(left, top, right, bottom, offset + 2 * PI / 60, offset + 3 * PI / 60);
setfillcolor(color2);
solidpie(left, top, right, bottom, offset + 3 * PI / 60, offset + 5 * PI / 60);
setfillcolor(RGB(0, 0, 0));
solidpie(left, top, right, bottom, offset + 5 * PI / 60, offset + 6 * PI / 60);
}
totaloffset = totaloffset + PI / 20;//记住设定好类型,totaloffset是float型不是int
}
circle_x += 200;//画一行的时候要画四个,每个之间间隔200
}
circle_x = 100;//记得重置cicle_x再开始画下一行
circle_y += 200;
}
_getch();
closegraph();
return 0;
}