// SineWave Demonstration Program

using System;
using System.Windows.Forms;

using Calculus;

using IPlusPlus;
using IPlusPlus.Windows;
using IPlusPlus.Graphics;

class SineWaveDemonstration : Form
{
    [STAThread]
    public static void Main()
    {
        application.Run(new SineWaveDemonstration());
    }

    SineWaveDemonstration()
    {
        Text = "SineWave Demonstration";
        BackColor = System.Drawing.Color.white;

        Paint += OnPaint;
        Resize += OnSize;
    }

    void OnPaint(object source, PaintEventArgs e)
    {
        DeviceContext deviceContext = new DeviceContext(this);

        System.Drawing.Size sizeClient = ClientSize;

        deviceContext.CurrentPosition = new Point(0,sizeClient.Height/2);
        deviceContext.DrawLineTo(sizeClient.Width,sizeClient.Height/2);

        Array<Point> SineLines = new Array<Point>();

        int NumberOfPoints = 1000;

        for (int i=0; i<NumberOfPoints; i++)
          SineLines[i] = new Point(i * sizeClient.Width/NumberOfPoints,
                                   (int)(sizeClient.Height/2 * (1 - Math.Sin(2*Maths.Pi*i/NumberOfPoints))));

        deviceContext.DrawLines(SineLines);
     }

    void OnSize(object sender, EventArgs e)
    {
        Invalidate();
    }
}