C语言中关于画圆程序

C语言中关于画圆程序,第1张

#include<stdio.h>

#include<math.h>

main()

{

double y

int x,m

for(y=10y>=-10y--) //表示图形的第y行,通过for循环打印所有行

{

m=2.5*sqrt(100-y*y) //用y作为自变量,根据弦长与纵坐标y的腔迹函数关系计算出此行上的弦长的一半也就是两个星形符号之间的距离的一半,并用m表示。

for(x=1x<50-mx++)//以50个字符长度为基准根据弦长来确定每行左数第一个星形的位 置,此位置前全印空格

printf(" ")

printf("*")

for(x<50+mx++) //以50个字符宽度为基准来确定每行第二个星形的位置

printf(" ")

printf("*\n")

}

}

//此庆歼程序打印的只是个大概的圆形,因为运行输出窗口里,相邻的行距和邻字符的列距是不相等的,所以语句 m=2.5*sqrt(100-y*y)中的2.5是用来修正此误差的。可根据具体运行平台适当修改。 如果还看不懂,再伍差并问

circle函数是TURBO C提供的图形接口,用来画圆。不属于标准库函数,不具备可移植性。

函数名:circle

功 能: 在给定半径以(x, y)为圆心画圆

用 法:void far circle(int x, int y, int radius)

随时间变化,可以用cleardevice函数清除屏幕,不断画半径不同的圆。看起来就像是一个随辩逗迅时间变化的圆形。

函数名: cleardevice

功 能: 清除图形屏幕

用 法: void far cleardevice(void)

例程:

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

int main(void)

{

/* request auto detection */

int gdriver = DETECT, gmode, errorcode

int midx, midy

int radius = 100

/* initialize graphics and local variables */

initgraph(&gdriver, &gmode, "")

/* read result of initialization 携此*/

errorcode = graphresult()

if (errorcode != grOk) /* an error occurred */

{

printf("Graphics error: %s\n", grapherrormsg(errorcode))

printf("Press any 指改key to halt:")

getch()

exit(1) /* terminate with an error code */

}

midx = getmaxx() / 2

midy = getmaxy() / 2

setcolor(getmaxcolor())

for(i=0i<1000000i++) if(i%50000==0){

    cleardevice()/* clean the screen */

    circle(midx, midy, radius--)/* draw the circle */

}

getch()

closegraph()

return 0

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/8239441.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-14
下一篇2023-04-14

发表评论

登录后才能评论

评论列表(0条)

    保存