= =结帖了,不然我还想写一个的~~
回复 21楼 StarWing83
来一个嘛,就算结贴也能继续。不用图形,就以DOS下输出一格为一个像素点画不出完美的五角星(星的面积不能太大),我倒觉得我那个算是漂亮的了(但还是很丑)。
#include <stdio.h> #include <math.h> #define MIN(x, y) ((y) < (x) ? (y) : (x)) #define MAX(x, y) ((x) < (y) ? (y) : (x)) #define RAD(x) ((x) * M_PI / 180.0) #define F1(x) (tan(RAD(162)) * (x) + 1 + cos(RAD(72))) #define F2(x) (tan(RAD(18)) * (x) + 1 + cos(RAD(72))) #define F3(x) (tan(RAD(54)) * (x) - sin(RAD(72)) * tan(RAD(54))) #define F4(x) (tan(RAD(126)) * (x) + 2 + 2 * cos(RAD(72)) \ + sin(RAD(72)) * tan(RAD(54))) void draw_star(int scale) { int i, end = rint(scale * sin(RAD(72)) / 2), end2; for (i = 0; i <= end; ++i) { int y1 = rint(F1(i*2.0/scale)*scale), y2 = rint(F2(i*2.0/scale)*scale); if (y1 != y2) printf("%*c%*c\n", y1 + 1, '*', y2 - y1, '*'); else printf("%*c\n", y1 + 1, '*'); } for (i = 0; i < scale; ++i) putchar('*'); end2 = rint(scale * cos(RAD(72)) * 2); for (i = 0; i <= end2; ++i) putchar(' '); for (i = 0; i < scale; ++i) putchar('*'); putchar('\n'); for (i = end + 1; ; ++i) { int y1 = rint(F1(i*2.0/scale)*scale), y2 = rint(F2(i*2.0/scale)*scale), y3 = rint(F3(i*2.0/scale)*scale), y4 = rint(F4(i*2.0/scale)*scale); if (y4 <= y1 || y3 >= y2) { printf("%*c%*c\n", y1 + 1, '*', y2 - y1, '*'); break; } if (y3 < y4) { int ymin = MIN(y1, y3); printf("%*c%*c\n", ymin + 1, '*', MAX(y2, y4) - ymin, '*'); } else printf("%*c%*c%*c%*c\n", y1 + 1, '*', y4 - y1, '*', y3 - y4, '*', y2 - y3, '*'); } } int main(void) { int scale; while (scanf("%d", &scale) == 1) draw_star(scale); return 0; } /* - cc: flags+='-lm' */