C 练习实例65

C语言教程评论阅读模式

C 练习实例65

题目:一个最优美的图案(在TC中实现)。

程序分析:无。

实例

#include "graphics.h"
#include "math.h"
#include "dos.h"
#include "conio.h"
#include "stdlib.h"
#include "stdio.h"
#include "stdarg.h"
#define MAXPTS 15
#define PI 3.1415926
struct PTS {
    int x,y;
};
double AspectRatio=0.85;
void LineToDemo(void)
{
    struct viewporttype vp;
    struct PTS points[MAXPTS];
    int i, j, h, w, xcenter, ycenter;
    int radius, angle, step;
    double rads;
    printf(" MoveTo / LineTo Demonstration" );
    getviewsettings( &vp );
    h = vp.bottom - vp.top;
    w = vp.right - vp.left;
    xcenter = w / 2; /* Determine the center of circle */
    ycenter = h / 2;
    radius = (h - 30) / (AspectRatio * 2);
    step = 360 / MAXPTS; /* Determine # of increments */
    angle = 0; /* Begin at zero degrees */
    for( i=0 ; i<MAXPTS ; ++i ){ /* Determine circle intercepts */
        rads = (double)angle * PI / 180.0; /* Convert angle to radians */
        points[i].x = xcenter + (int)( cos(rads) * radius );
        points[i].y = ycenter - (int)( sin(rads) * radius * AspectRatio );
        angle += step; /* Move to next increment */
    }
    circle( xcenter, ycenter, radius ); /* Draw bounding circle */
    for( i=0 ; i<MAXPTS ; ++i ){ /* Draw the cords to the circle */
        for( j=i ; j<MAXPTS ; ++j ){ /* For each remaining intersect */
            moveto(points[i].x, points[i].y); /* Move to beginning of cord */
            lineto(points[j].x, points[j].y); /* Draw the cord */
        }
    }
}
int main()
{
    int driver,mode;
    driver=CGA;mode=CGAC0;
    initgraph(&driver,&mode,"");
    setcolor(3);
    setbkcolor(GREEN);
    LineToDemo();
}

继续阅读
weinxin
我的微信
运营不易,
感谢支持!
公式库网
  • 本文由 发表于 2021年12月6日 20:51:59
  • 转载请务必保留本文链接:https://www.gongshiku.com/html/202112/c-lianxishili65.html
C语言教程

C 标准库 –

C 标准库 - <time.h> 简介 time.h 头文件定义了四个变量类型、两个宏和各种操作日期和时间的函数。 库变量 下面是头文件 time.h 中定义的变量类型: ...
C语言教程

C 标准库 –

C 标准库 - <string.h> 简介 string .h 头文件定义了一个变量类型、一个宏和各种操作字符数组的函数。 库变量 下面是头文件 string.h 中定义的变量类型...
C语言教程

C 标准库 –

C 标准库 - <stdlib.h> 简介 stdlib .h 头文件定义了四个变量类型、一些宏和各种通用工具函数。 库变量 下面是头文件 stdlib.h 中定义的变量类型: ...
C语言教程

C 标准库 –

C 标准库 - <stdio.h> 简介 stdio .h 头文件定义了三个变量类型、一些宏和各种函数来执行输入和输出。 库变量 下面是头文件 stdio.h 中定义的变量类型: ...

发表评论