09/07/19 03:14:40
>>167 C++ で提出すれば君はヒーローだ。(星形の座標列を生成する)
#include <fstream>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
using namespace std;
#define PI 3.1415926535897932384
void draw_star(ofstream &fout, float x1, int y1) {
int i, dot;
dot = abs(y1) + 4;
for( i = 0; i <= dot; i++ ) {
fout<<setw(6)<< cos(2*PI/dot*i)/2+x1 <<','<<setw(7)<< sin(2*PI/dot*i)/2+y1 <<endl;
if( i < dot )
fout<<setw(6)<< cos(2*PI/dot*(i+0.5))/4+x1 <<','<<setw(7)<< sin(2*PI/dot*(i+0.5))/4+y1 <<endl;
}
fout<<endl;
}
int main() {
float x, xstep; int y;
ofstream fout("polygon_29.csv");
if(!fout) return 1;
fout<<fixed<<setprecision(3);
for( y = -10; y <= 10; y++ ) {
xstep = 2.0 + 0.3 * abs(y);
for( x=0.0; x<40.0; x += xstep ) {
draw_star(fout, x, y);
}
}
fout.close();
}