C++ Program to Draw a 5-Pointed Star with Explicit Angles
#include
int main() { int radius = 100; // radius of the star int centerX = 250; // x-coordinate of the center of the star int centerY = 250; // y-coordinate of the center of the star int numPoints = 10; // number of points in the star int angle = 36; // angle between the points in degrees
// calculate the coordinates of the points
int x[numPoints], y[numPoints];
for(int i=0;i<numPoints;i++)
{
if(i%2==0)
{
x[i] = centerX + radius*cos(i*angle*M_PI/180);
y[i] = centerY + radius*sin(i*angle*M_PI/180);
}
else
{
x[i] = centerX + (radius/2)*cos(i*angle*M_PI/180);
y[i] = centerY + (radius/2)*sin(i*angle*M_PI/180);
}
}
// print the coordinates of the points
for(int i=0;i<numPoints;i++)
{
cout<'Point '<<i+1<<': ('<<x[i]<<', '<<y[i]<<')'<<endl;
}
// draw the star using graphics library
// code to draw the star using graphics library goes here
return 0;
}
原文地址: https://www.cveoy.top/t/topic/l6IO 著作权归作者所有。请勿转载和采集!