1. 程式人生 > >C#繪圖 正弦曲線

C#繪圖 正弦曲線

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;
using System.Drawing.Drawing2D;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Pen p = new Pen(Color.Black);
            p.EndCap = LineCap.ArrowAnchor;
            g.DrawLine(p, new Point(100, this.Height - 100), new Point(this.Width - 100, this.Height - 100));
            g.DrawString("x", this.Font, new SolidBrush(Color.Black), new Point(this.Width - 100 + 5, this.Height - 100));
            p.EndCap = LineCap.ArrowAnchor;
            g.DrawLine(p, new Point(150, this.Height - 50), new Point(150,  100));
            g.DrawString("y", this.Font, new SolidBrush(Color.Black), new Point(150, 100-10));
            Point []point=new Point[9];
            int h = 50,w=(Width-250-50)/8;
            for (int i = 0; i < 9; i++)
			{
                point[i] = new Point(150 + i * w, this.Height - 100 -Convert.ToInt32(h * Math.Sin(2 * Math.PI / 360 * 90 * i)));
			}
            g.DrawCurve(p, point, 0.4f);
           
        }
    }
}