旋转蛇代码

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值