zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    SQL Server 2008 官方简体中文正式版【附开发版和企业版序列号】
    安装SQL 2008 重启之后 一再提示重启计算机问题
    wp7使用C#通过后台动态生成Grid网格布局
    wp7中空格的编码
    vs.php 2.10 for 2010 注册码
    hive 优化
    Remove '@Override' annotation错误
    ucfirst
    Hadoop错误
    git patch 转帖
  • 原文地址:https://www.cnblogs.com/sea-stream/p/11100319.html
Copyright © 2011-2022 走看看