c#画五角星的问题

publicdouble[]GetAngles(doublestartAngle,intpointed){double[]angles=newdouble[pointed... public double[] GetAngles(double startAngle, int pointed)
{
double[] angles = new double[pointed];
angles[0] = startAngle;
for (int i = 1; i < angles.Length; i++)
{
angles[i] = angles[i - 1] + GetAngleLength(pointed);
}
return angles;
}

public double GetAngleLength(int pointed)
{
return 2 * Math.PI / pointed;
}

public PointF GetPoint(PointF ptCenter, double length, double angle)
{
return new PointF(
(float)(ptCenter.X + length * Math.Cos(angle)),
(float)(ptCenter.Y + length * Math.Sin(angle)));
}

public PointF[] GetPoints(PointF ptCenter, double length, params double[] angles)
{
PointF[] points = new PointF[angles.Length];
for (int i = 0; i < points.Length; i++)
{
points[i] = GetPoint(ptCenter, length, angles[i]);
}
return points;
}
public void button1_Click(object sender, EventArgs e)
{

g.CompositingQuality = CompositingQuality.HighQuality;//设置图像呈现的质量
g.SmoothingMode = SmoothingMode.HighQuality;//对图片进行平滑处理
Pen p = new Pen(Color.Red);//画笔的颜色
double[] angles1 = GetAngles(-Math.PI / 2, pointed);//五角星外围的点角度的一个数组
double[] angles2 = GetAngles(-Math.PI / 2+Math.PI/pointed, pointed);//五角星内围的点角度的一个数组
PointF[] points1 = GetPoints(new PointF(300, 300), 100, angles1);//五角星外围的点的一个数组
PointF[] points2 = GetPoints(new PointF(300, 300), 50, angles2);//五角星内围的点的一个数组
PointF[] points = new PointF[points1.Length+points2.Length];//最终合成多边形所有点的数组
for (int i = 0,j=0; i < points.Length; i+=2,j++)
{
points[i] = points1[j];
points[i + 1] = points2[j];
}
g.DrawPolygon(p,points);//画一个多边形
g.FillPolygon(Brushes.Aqua,points);//填充颜色

}
哪位大神帮我看一吓为什么提示上下文中不存在pointed
展开
 我来答
草原上之狼
高粉答主

2017-11-16 · 醉心答题,欢迎关注
知道大有可为答主
回答量:2.9万
采纳率:93%
帮助的人:4033万
展开全部
试试:

void MyDraw(Graphics g,Point center,int radius){
Point[] pts = new Point[5];
//获取五角星5个顶点
pts[0] = new Point(center.X,center.Y - radius);
pts[1] = Rotate72(pts[0],center);
pts[2] = Rotate72(pts[1],center);
pts[3] = Rotate72(pts[2],center);
pts[4] = Rotate72(pts[3],center);

//简单地拉5条线
Pen pen = new Pen(new SolidBrush(Color.Blue));
g.DrawLine(pen,pts[0],pts[2]);
g.DrawLine(pen,pts[0],pts[3]);
g.DrawLine(pen,pts[1],pts[3]);
g.DrawLine(pen,pts[1],pts[4]);
g.DrawLine(pen,pts[2],pts[4]);

}

//旋转72
private Point Rotate72(Point pt,Point center){
int x = (int)(center.X + (pt.X - center.X) * Math.Cos(72.0 * Math.PI/180) - (pt.Y - center.Y) * Math.Sin(72.0 * Math.PI/180)),
y = (int)(center.Y + (pt.X - center.X) * Math.Sin(72.0 * Math.PI/180) + (pt.Y - center.Y) * Math.Cos(72.0 * Math.PI/180));
return new Point(x,y);
}

这样画出来的五角星是中间有五条线的,如果你想画的是中间没有五条线,看看上面的代码自己就可以搞定了。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式