1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WinFlattenPath
{
public partial class Form1 : Form
{
private List<PointF> pts=new List<PointF>();
public Form1()
{
InitializeComponent();
this.ResizeRedraw = true;
}
private void button1_Click(object sender, EventArgs e)
{
this.Invalidate ();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics gr = e.Graphics;
gr.Clear(Color.White);
DrawCurvePointFSegmentTension(gr);
}
private void DrawCurvePointFSegmentTension(Graphics gr)
{
// Create pens.
Pen redPen = new Pen(Color.Red, 3);
Pen greenPen = new Pen(Color.Green, 3);
Pen yellowPen = new Pen(Color.Yellow , 3);
// Create points that define curve.
PointF point1 = new PointF(50.0F, 50.0F);
PointF point2 = new PointF(100.0F, 25.0F);
PointF point3 = new PointF(200.0F, 5.0F);
PointF point4 = new PointF(250.0F, 50.0F);
PointF point5 = new PointF(300.0F, 100.0F);
PointF point6 = new PointF(350.0F, 200.0F);
PointF point7 = new PointF(250.0F, 250.0F);
PointF[] curvePoints = { point1, point2, point3, point4, point5, point6, point7 };
// Draw lines between original points to screen.
gr.DrawLines(redPen, curvePoints);
// Draw default curve to screen.
gr.DrawCurve(greenPen, curvePoints);
// Create offset, number of segments, and tension.
int offset = 0;
int numSegments = curvePoints.Length-1;
float tension = 0.2F;
// Draw curve to screen.
gr.DrawCurve(yellowPen, curvePoints, offset, numSegments, tension);
}
}
} |
Partager