首页 > 编程语言 > 详细

c++ 珊格画椭圆

时间:2019-06-28 00:11:08      阅读:90      评论:0      收藏:0      [点我收藏+]

 

#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

 

 

 

 

c++ 珊格画椭圆

原文:https://www.cnblogs.com/sea-stream/p/11100319.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!