高分求画五角星源代码,在线等待

shibill 2005-12-09 11:47:56
要求提供一个矩形,然后画出五角星,十个点的,可以填充的
...全文
252 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
shibill 2005-12-09
  • 打赏
  • 举报
回复
谢谢喽
jiang8282 2005-12-09
  • 打赏
  • 举报
回复
中午帮你写
zteclx 2005-12-09
  • 打赏
  • 举报
回复
画72度弧,一个圆就得到五个点,将这五个点连起来,就是五星
这是一种算法
大可山人 2005-12-09
  • 打赏
  • 举报
回复
以前我自己写过一个画正五角星的代码,但现在不知跑到哪里去了
大可山人 2005-12-09
  • 打赏
  • 举报
回复
private void DrawStar(Graphics g, int center_x, int center_y, int inner_radius, int outer_radius, int number_of_arms, Color fillColor, Color outlineColor)
{
Brush fillBrush;
Pen outlinePen = new Pen(outlineColor);
fillBrush = new SolidBrush(fillColor);

PointF[] p = new PointF[number_of_arms*2];

for (int i=0; i<number_of_arms; i++)
{
p[i*2].X = center_x + (float)Math.Cos(i*2*Math.PI/number_of_arms) * outer_radius;
p[i*2].Y = center_y + (float)Math.Sin(i*2*Math.PI/number_of_arms) * outer_radius;
}

for (int i=0; i<number_of_arms; i++)
{
p[i*2+1].X = center_x + (float)Math.Cos(i*2*Math.PI/number_of_arms + 2*Math.PI/(2*number_of_arms)) * inner_radius;
p[i*2+1].Y = center_y + (float)Math.Sin(i*2*Math.PI/number_of_arms + 2*Math.PI/(2*number_of_arms)) * inner_radius;
}

g.FillPolygon(fillBrush, p);
g.DrawPolygon(outlinePen, p);
}

for example:
DrawStar(g, 100, 100, 12, 30, 5, Color.Yellow, Color.Orange);
大可山人 2005-12-09
  • 打赏
  • 举报
回复
http://www.codeproject.com/cs/miscctrl/cs_star_rating_control.asp
shibill 2005-12-09
  • 打赏
  • 举报
回复
还是感谢你支持,分儿肯定有
jiang8282 2005-12-09
  • 打赏
  • 举报
回复
我就是不记得公式才这样用笨方法画的,唉,你以为我想呀.
shibill 2005-12-09
  • 打赏
  • 举报
回复
哈,你这是什么呀,当然要公式的了,这样才通用阿,要随便给一矩形,就画出五角星
兔子-顾问 2005-12-09
  • 打赏
  • 举报
回复
五角星好像有公式。忘记了
jiang8282 2005-12-09
  • 打赏
  • 举报
回复
using System.Drawing.Imaging;
public class _A : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Point[] pt=new Point[11];
pt[0]=new Point(0,12);
pt[1]=new Point(12,12);
pt[2]=new Point(16,0);
pt[3]=new Point(20,12);
pt[4]=new Point(32,12);
pt[5]=new Point(24,20);
pt[6]=new Point(26,32);
pt[7]=new Point(16,24);
pt[8]=new Point(6,32);
pt[9]=new Point(10,20);
pt[10]=new Point(0,12);
Bitmap bm=new Bitmap(75,75,PixelFormat.Format32bppArgb);
SChart chart=new SChart(bm,pt);
bm.Save("c:\\inetpub\\wwwroot\\test\\images\\chart.gif",ImageFormat.Gif);
//图片保存在能写的一个目录下;
}
}
//
public class SChart
{
public SChart(Bitmap bm,Point[] pt)
{
System.Drawing.Graphics g= Graphics.FromImage(bm);
Drawlines(g,pt);
}

protected void Drawlines(System.Drawing.Graphics g,Point[] pt)
{
System.Drawing.SolidBrush b=new SolidBrush(Color.White);//新建画布清空
g.FillRectangle(b,0,0,75,75);//画图片区域
System.Drawing.Pen pen=new Pen(Color.Black);
g.DrawLines(pen,pt);//画线,楼主,你慢慢改成画区域的
}
}

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧