像素画第一篇C++

37 篇文章 2 订阅
#include<iostream>
#include<windows.h>
#include<conio.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stdio.h>
#include<iostream>
#include<string>
#include<cstring>
#include<windows.h>
#include<conio.h>
#include<cstdlib>
#include<ctime>
#include<fstream>
using namespace std;
void gotoxy(int y,int x) 
{
    COORD  coord;     
    coord.X=x;         
    coord.Y=y;
    HANDLE a=GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(a,coord);    
}
void bukakeqingping(){
    gotoxy(0,0);
    for (int i = 0; i < 70; i++) {
        cout << "                                                                                                        " << endl;
    }
    gotoxy(0,0);
}
void color(int a)//打印颜色
{
/*亮白*/    if(a==0) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
/*蓝色*/    if(a==1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);
/*绿色*/    if(a==2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
/*紫色*/    if(a==3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE);
/*红色*/    if(a==4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
/*黄色*/    if(a==5) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
/*深蓝色*/    if(a==6) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE);
/*土黄色or金黄色*/    if(a==7) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN);
/*灰色接近白*/    if(a==8) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
}
long long numberaio(string n){
    for (int i = 0; i < 100000; i++) {
        if(n[i]=='\0')
        {
            return i;
        }
    }
}
void coutAIO(string b,int truefalse0 = 1,bool truefalse1 = 1,bool truefalse3 = 0){
    int i=0,s=0;
    long long a=numberaio(b);
    while(a!=0){
        s=rand()%9;
        if(a!=0&&s==0)
        {
            color(0);
            cout << b[i];
            a--;
            i++;
        }
        if(a!=0&&s==1)
        {
            color(1);
            cout << b[i];
            a--;
            i++;
        }
        if(a!=0&&s==2)
        {
            color(2);
            cout << b[i];
            a--;
            i++;
        }
        if(a!=0&&s==3)
        {
            color(3);
            cout << b[i];
            a--;
            i++;
            if(truefalse0!=false){
                Sleep(20);
            }
        }
        if(a!=0&&s==4)
        {
            color(4);
            cout << b[i];
            a--;
            i++;
        }
        if(a!=0&&s==5)
        {
            color(5);
            cout << b[i];
            a--;
            i++;
        }
        if(a!=0&&s==6)
        {
            color(6);
            cout << b[i];
            a--;
            i++;
        }
        if(a!=0&&s==7)
        {
            color(7);
            cout << b[i];
            a--;
            i++;
        }
        if(a!=0&&s==8)
        {
            color(8);
            cout << b[i];
            a--;
            i++;
        }
        if(truefalse0 ==1){
            Sleep(10);
        }
        if(truefalse0 ==2){
            Sleep(20);
        }
        if(truefalse0 ==3){
            Sleep(40);
        }
        if(truefalse0 ==4){
            Sleep(100);
        }
        if(truefalse0 ==5){
            Sleep(300);
        }
        if(truefalse0 ==6){
            Sleep(1000);
        }
        if(truefalse0 ==100){
            Sleep(1);
        }
    }
    if(truefalse1!=false){
        cout << endl;
    }
    if(truefalse3!=false){
        getch();
        bukakeqingping();
    }
}
void start(int n)
{
    int g=n;
	system("cls");
    Sleep(1000);
    gotoxy(0,0);
	for (int i=1;i<=n; i++)
	{
		for (int i=1;i<=g; i++)
	    {
		    coutAIO("▓▓▓",0,0);
	    }
	    cout<<endl;
	}
	coutAIO("华丽!!",4);
    Sleep(5000);
    system("cls");
    Sleep(5000);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
计算机图形学中点画椭圆算法是一种常用的绘制椭圆形的方法,下面是一个简单的C++代码示例: ```cpp #include <iostream> #include <graphics.h> void drawEllipse(int xc, int yc, int a, int b) { int x = 0; int y = b; int a_sqr = a * a; int b_sqr = b * b; int two_a_sqr = 2 * a_sqr; int two_b_sqr = 2 * b_sqr; int four_a_sqr = 4 * a_sqr; int four_b_sqr = 4 * b_sqr; int p; // 绘制第一象限的椭圆弧 p = b_sqr - a_sqr * b + 0.25 * a_sqr; while (four_b_sqr * x <= four_a_sqr * y) { putpixel(xc + x, yc + y, WHITE); putpixel(xc - x, yc + y, WHITE); putpixel(xc + x, yc - y, WHITE); putpixel(xc - x, yc - y, WHITE); if (p < 0) { x++; p += two_b_sqr * x + b_sqr; } else { x++; y--; p += two_b_sqr * x - two_a_sqr * y + b_sqr; } } // 绘制第二象限的椭圆弧 p = b_sqr * (x + 0.5) * (x + 0.5) + a_sqr * (y - 1) * (y - 1) - a_sqr * b_sqr; while (y >= 0) { putpixel(xc + x, yc + y, WHITE); putpixel(xc - x, yc + y, WHITE); putpixel(xc + x, yc - y, WHITE); putpixel(xc - x, yc - y, WHITE); if (p > 0) { y--; p += a_sqr - two_a_sqr * y; } else { y--; x++; p += two_b_sqr * x - two_a_sqr * y + a_sqr; } } } int main() { int gd = DETECT, gm; initgraph(&gd, &gm, ""); int xc = 320; // 椭圆中心点的x坐标 int yc = 240; // 椭圆中心点的y坐标 int a = 200; // 长轴的长度 int b = 100; // 短轴的长度 drawEllipse(xc, yc, a, b); getch(); closegraph(); return 0; } ``` 这段代码使用了Bresenham算法来绘制椭圆,通过调用`putpixel`函数来在图形窗口中绘制像素点。你可以根据自己的需求修改椭圆的中心点坐标和长短轴的长度。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值