diff options
author | Toby Vincent <tobyv13@gmail.com> | 2021-04-20 13:34:37 -0500 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2021-04-20 13:34:37 -0500 |
commit | d2dea1b16ff29f6e45fca971290f94d4e0ed2467 (patch) | |
tree | 755be27957462fb0288d3a985eb86ded0aa63cee /src/CS340.Plotter/Plot.cs | |
parent | 3af8b7c9846e34fdf39f0364394c40f3c833d465 (diff) |
added Canvas
Diffstat (limited to 'src/CS340.Plotter/Plot.cs')
-rw-r--r-- | src/CS340.Plotter/Plot.cs | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/src/CS340.Plotter/Plot.cs b/src/CS340.Plotter/Plot.cs index 7b274d8..f26978f 100644 --- a/src/CS340.Plotter/Plot.cs +++ b/src/CS340.Plotter/Plot.cs @@ -1,21 +1,45 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; namespace Plotter { public partial class Plot : Form { + Random rand = new Random(); public Plot() { InitializeComponent(); + Render(); + } + void Render() + { + using var bmp = new Bitmap(Canvas.Width, Canvas.Height); + using var gfx = Graphics.FromImage(bmp); + using var pen = new Pen(Color.White); + // draw one thousand random white lines on a dark blue background + gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; + gfx.Clear(Color.Navy); + for (int i = 0; i < 1000; i++) + { + var pt1 = new Point(rand.Next(bmp.Width), rand.Next(bmp.Height)); + var pt2 = new Point(rand.Next(bmp.Width), rand.Next(bmp.Height)); + gfx.DrawLine(pen, pt1, pt2); + } + + // copy the bitmap to the picturebox (double buffered) + Canvas.Image?.Dispose(); + Canvas.Image = (Bitmap)bmp.Clone(); + } + + private void Canvas_SizeChanged(object sender, EventArgs e) + { + Render(); } + private void Canvas_MouseDown(object sender, MouseEventArgs e) + { + Render(); + } } } |