このプログラムでは楕円上に五芒星を描いていますが幅と高さを同じにすれば円上に五芒星を描いているのと同じになります
コンソール上で丸に見えるようにするには高さを幅の半分にしてください
■参考Webページ
楕円を描く
https://daeudaeu.com/circle/
点/線を描画する
https://daeudaeu.com/figure/
N芒星を描く
https://qiita.com/kaityo256/items/a81a4168429bfed9c7eb
#include <stdio.h> #include <stdlib.h> #include <string.h> #define _USE_MATH_DEFINES #include <math.h> //M_PI 円周率 void drawLineTwoPixels( unsigned char *data, unsigned int width, unsigned int height, unsigned int xs, unsigned int ys, unsigned int xe, unsigned int ye ){ unsigned int x, y; unsigned char *p; int dx, dy; double rad; unsigned int length; unsigned int l; int sigx, sigy; dx = xe - xs; dy = ye - ys; length = sqrt(dx * dx + dy * dy); rad = atan2(dy, dx); for(l = 0; l < length; l++){ x = xs + l * cos(rad); y = ys + l * sin(rad); if((x >=0 && x < width) && (y >= 0 && y < height)){ p = data + y * width + x; p[0] = 2; } } } void drawEllipse( unsigned char *data, unsigned int width, unsigned int height, unsigned int rx, unsigned int ry, unsigned int x1, unsigned int y1 ){ unsigned int x, y; int dx, dy; unsigned char *p; for(y = 0; y < height; y++){ for(x = 0; x < width; x++){ dx = (int)x - (int)x1; dy = (int)y - (int)y1; if((double)(dx * dx) / (double)(rx * rx) + (double)(dy * dy) / (double)(ry * ry) <= 1){ p = data + y * width + x; p[0] = 1; } } } } int main(){ unsigned char *data; unsigned int width,height; printf("width height を入力してください "); scanf("%d %d",&width,&height); data=(unsigned char*)malloc(sizeof(unsigned char) * width * height); memset(data,0,width*height); //楕円を作る drawEllipse(data,width,height,(int)width/2,(int)height/2,(int)width/2,(int)height/2); //n芒星を作る unsigned int N=5; //五芒星 unsigned int k=2; unsigned int r1=width/2; unsigned int r2=height/2; double s,s1,s2,x1,y1,x2,y2; s=2*M_PI/N; for(int i=0;i<N;i++){ s1 = ((i*k) % N)*s - 0.5*M_PI; s2 = s1 + s*k; x1 = r1*cos(s1)+width/2; y1 = r2*sin(s1)+height/2; x2 = r1*cos(s2)+width/2; y2 = r2*sin(s2)+height/2; drawLineTwoPixels(data,width,height,(int)x1,(int)y1,(int)x2,(int)y2); } unsigned int x, y; unsigned int cnt=0; for(y=0;y<height;y++){ for(x=0;x<width;x++){ if(data[cnt]==1){ printf("."); }else if(data[cnt]==2){ printf("*"); }else{ printf(" "); } cnt++; } printf("\n"); } free(data); return 0; }