1、结果展示
2、数据处理
首先,我们在网上找了一个新加坡图片的矢量图,将其放进CAD 中进行测量,采集数据。数据结果如下:
找出图形之间位置关系:
对采集的数据进行处理:
3、代码展示:
1)先完成国旗底部颜色的填充;
2)完成月亮形状图形的绘制;
3)根据位置关系找到五角的圆心位置和半径,绘制相应的图形。
namespace WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
var g = this.pictureBox1.CreateGraphics();
var p = new Pen(Color.Black);
var point0 = new Point(200,50);
int w = 50;
g.Clear(Color.White);
g.DrawRectangle(p,point0.X,point0.Y,w*9,w*6);
var brush = new SolidBrush(Color.Red);
g.FillRectangle(brush,200,50,450,150);
g.FillEllipse(new SolidBrush(Color.White), (float)242.4, (float)68.5, 113,113);
g.FillEllipse(new SolidBrush(Color.Red), (float)262.6, (float)71.9, (float)106.2, (float)106.2);
//第一个五角星
var pen1 = new Pen(Color.White);
double R1 = 13.7;
const double PI1 = Math.PI;
double ct1 = PI1 / 10.0;
Point pt1 = new Point(323, 93);
Point[] pts1 = new Point[10];
double dct1 = PI1 / 5.0;
var brush1 = new SolidBrush(Color.White);
double r1 = R1 * Math.Cos(2 * ct1) / 2;
int i = 0;
for (i = 0; i < 9; i += 2)
{
pts1[i].X = (int)Math.Round(pt1.X + R1 * Math.Cos(3*PI1/2+i * dct1));
pts1[i].Y = (int)Math.Round(pt1.Y + R1 * Math.Sin(3*PI1/2+i * dct1));
}
for (i = 1; i < 10; i += 2)
{
pts1[i].X = (int)Math.Round(pt1.X + r1 * Math.Cos(3 * PI1 / 2 + i * dct1));
pts1[i].Y = (int)Math.Round(pt1.Y + r1 * Math.Sin(3 * PI1 / 2 + i * dct1));
}
g.FillPolygon(brush1, pts1);
//第二个五角星
var pen2 = new Pen(Color.White);
double R2 = 13.7;//
const double PI2 = Math.PI;
double ct2 = PI2 / 10.0;
Point pt2 = new Point(293, 115);
Point[] pts2 = new Point[10];
double dct2 = PI2 / 5.0;
var brush2 = new SolidBrush(Color.White);
double r2 = R2 * Math.Cos(2 * ct2) / 2;
int j = 0;
for (j = 0; j < 9; j += 2)
{
pts2[j].X = (int)Math.Round(pt2.X + R2 * Math.Cos(3 * PI2 / 2 + j * dct2));
pts2[j].Y = (int)Math.Round(pt2.Y + R2 * Math.Sin(3 * PI2 / 2 + j * dct2));
}
for (j = 1; j < 10; j += 2)
{
pts2[j].X = (int)Math.Round(pt2.X + r2 * Math.Cos(3 * PI2 / 2 + j * dct2));
pts2[j].Y = (int)Math.Round(pt2.Y + r2 * Math.Sin(3 * PI2 / 2 + j * dct2));
}
g.FillPolygon(brush2, pts2);
//第三个五角星
var pen3 = new Pen(Color.White);
double R3 = 13.7;
const double PI3 = Math.PI;
double ct3 = PI3 / 10.0;
Point pt3 = new Point(305, 150);
Point[] pts3 = new Point[10];
double dct3 = PI3 / 5.0;
var brush3 = new SolidBrush(Color.White);
double r3 = R3 * Math.Cos(2 * ct3) / 2;
int m = 0;
for (m = 0; m < 9; m += 2)
{
pts3[m].X = (int)Math.Round(pt3.X + R3 * Math.Cos(3 * PI3 / 2 + m * dct3));
pts3[m].Y = (int)Math.Round(pt3.Y + R3 * Math.Sin(3 * PI3 / 2 + m * dct3));
}
for (m = 1; m < 10; m += 2)
{
pts3[m].X = (int)Math.Round(pt3.X + r3 * Math.Cos(3 * PI3 / 2 + m * dct3));
pts3[m].Y = (int)Math.Round(pt3.Y + r3 * Math.Sin(3 * PI3 / 2 + m * dct3));
}
g.FillPolygon(brush3, pts3);
//第四个五角星
var pen4 = new Pen(Color.White);
double R4 = 13.7;
const double PI4 = Math.PI;
double ct4 = PI4 / 10.0;
Point pt4 = new Point(342, 150);
Point[] pts4 = new Point[10];
double dct4 = PI4 / 5.0;
var brush4 = new SolidBrush(Color.White);
double r4 = R4 * Math.Cos(2 * ct4) / 2;
int n = 0;
for (n = 0; n < 9; n += 2)
{
pts4[n].X = (int)Math.Round(pt4.X + R4 * Math.Cos(3 * PI4 / 2 + n * dct4));
pts4[n].Y = (int)Math.Round(pt4.Y + R4 * Math.Sin(3 * PI4 / 2 + n * dct4));
}
for (n = 1; n < 10; n += 2)
{
pts4[n].X = (int)Math.Round(pt4.X + r4 * Math.Cos(3 * PI4 / 2 + n * dct4));
pts4[n].Y = (int)Math.Round(pt4.Y + r4 * Math.Sin(3 * PI4 / 2 + n * dct4));
}
g.FillPolygon(brush4, pts4);
//第五个五角星
var pen5 = new Pen(Color.White);
double R5 = 13.7;
const double PI5 = Math.PI;
double ct5 = PI5 / 10.0;
Point pt5 = new Point(352, 115);
Point[] pts5 = new Point[10];
double dct5 = PI5 / 5.0;
var brush5 = new SolidBrush(Color.White);
double r5 = R5 * Math.Cos(2 * ct5) / 2;
int a = 0;
for (a = 0; a < 9; a += 2)
{
pts5[a].X = (int)Math.Round(pt5.X + R5 * Math.Cos(3 * PI5 / 2 + a * dct5));
pts5[a].Y = (int)Math.Round(pt5.Y + R5 * Math.Sin(3 * PI5 / 2 + a * dct5));
}
for (a = 1; a < 10; a += 2)
{
pts5[a].X = (int)Math.Round(pt5.X + r5 * Math.Cos(3 * PI5 / 2 + a * dct5));
pts5[a].Y = (int)Math.Round(pt5.Y + r5 * Math.Sin(3 * PI5 / 2 + a * dct5));
}
g.FillPolygon(brush5, pts5);
}
}
}
4、运行结果展示