用C语言编写程序在屏幕上画一个矩形

用C语言编写程序在屏幕上画一个矩形,第1张

#include <math.h>

#include <stdio.h>

#include <conio.h>

#include <stdlib.h>

#include <graphics.h>

void polygon(int n, int x, int y, int r, int color, float arg, int fillstyle)

int main()

{

int GraphDriver

int GraphMode

float arg = 45, argd

int a

int direction

int r

int n = 4

FILE *fp

char szfilename[255] = {"c:\\cube.txt"}

GraphDriver = DETECT

printf("Input size of cube: ")

scanf("%d", &r)

printf("Input direction(0-1): ")

scanf("%d", &direction)

if (direction == 0)

{

argd = 45

}

else

{

argd = -45

}

initgraph(&GraphDriver, &GraphMode, "")

polygon(n, 300, 200, r, 12, arg, 0)

while(1)

{

while(kbhit())

{

a = getch()

if (a == 27)

{

if ((fp = fopen(szfilename, "wt")) != NULL)

{

fprintf(fp, "%d\n%d\n", r, direction)

fclose(fp)

}

closegraph()

return 0

}

if (a == 0)

{

getch()

polygon(n, 300, 200, r, 0, arg, 0)

arg += argd

polygon(n, 300, 200, r, 12, arg, 0)

}

else

{

polygon(n, 300, 200, r, 0, arg, 0)

arg += argd

polygon(n, 300, 200, r, 12, arg, 0)

}

}

}

}

void polygon(int n, int x, int y, int r, int color, float arg, int fillstyle)

{

double pi

int i

float x1[10], y1[10]

setcolor(color)

pi = atan(1) * 4

arg = atan(1) / 45 * arg

x1[1] = x + r * cos(2 * pi / n + arg)

y1[1] = y + r * sin(2 * pi / n + arg)

moveto(x1[1], y1[1])

for (i = 2i <= ni++)

{

x1[i] = x + r * cos(2 * pi * i / n + arg)

y1[i] = y + r * sin(2 * pi * i / n + arg)

lineto(x1[i], y1[i])

}

lineto(x1[1], y1[1])

if (fillstyle != 0)

{

setfillstyle(SOLID_FILL, color)

floodfill(x, y, color)

}

}

参考代码如下:

#include<stdio.h>

int main()

{

int m,n,i,j

scanf("%d%d",&m,&n)

if(m>80||n>80)

return 0

for(i=1i<=m++i){

for(j=1j<=n++j)

printf("%c",i%2==1?'c':'d')

printf("\n")

}

return 0

}


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

原文地址: http://outofmemory.cn/yw/12063738.html

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

发表评论

登录后才能评论

评论列表(0条)

保存