c++ 珊格画椭圆

#ifndef _TEST_H
#define _TEST_H
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    const double pi=3.14159,p=16.0; //圆周率和圆的半径
    double angle;                    //角度
    int x,y;                        //计算存储数组的坐标
    char rose[25][80];                //模拟屏幕为25*80个像素构成
    for (x=0;x<80;x++)                //置空
    {
        for (y=0;y<25;y++)
        {
            rose[y][x]=' ';
        }
    }
    for (int i=0;i<20;i++)            //把图形经过的轨迹位置置为*
    {
        //注意x坐标值实际是列数,y坐标值实际才是行数
        angle=i*pi/10;
        x=int(p*cos(angle))*2+40;    //乘以2和除以二只是为了调整显示效果
        y=int(p*sin(angle))/2+13;   //因为控制台显示字符的时候宽和高不等比例
        rose[y][x]='*';                //以40和13为圆心是模拟屏幕像素决定,当然可以另外设置
    }
    for (y=0;y<25;y++)
    {
        for (x=0;x<80;x++)
        {
            cout<<rose[y][x];
        }
        cout << endl;
    }
    /*const double pi=3.14159,a=16.0;
     const int aspect = 2;
     double angle,p=16;
     int x,y;
     char rose[25][80];
     for (x=0;x<80;x++)
     {
     for (y=0;y<25;y++)
     {
     rose[y][x]=' ';
     }
     }
     for (int i=0;i<128;i++)
     {
     angle=i*pi/64;
     p=a*sin(2*angle);
     x=int(p*cos(angle))*aspect+40;
     //x=int(p*cos(angle))+40;
     y=int(p*sin(angle))+13;
     rose[y][x]='*';
     }
     
     for (y=0;y<25;y++)
     {
     for (x=0;x<80;x++)
     {
     cout<<rose[y][x];
     }
     cout << endl;
     }*/
    return 0;
}
#endif //_TEST_H

输出

                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                *       *       *                               
                      *                                   *                     
                                                                                
                *                                               *               
                                                                                
          *                                                           *         
                                                                                
          *                                                             *       
                                                                                
          *                                                           *         
                                                                                
                *                                               *               
                                                                                
                      *                                   *                     
                                *       *       *                               
                                                                                
                                                                                
                                                                                
                                                                                
Program ended with exit code: 0

猜你喜欢

转载自www.cnblogs.com/sea-stream/p/11100319.html