Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace WpfApplicationGraphics
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- double x0 = 250;
- double y0 = 150;
- double r = 100;
- double a = 0;
- Point pt = new Point();
- int numPoints = 300;
- Polyline pline = new Polyline();
- Random rand = new Random((int)DateTime.Now.Ticks);
- BackgroundWorker Worker = new BackgroundWorker();
- public MainWindow()
- {
- InitializeComponent();
- Worker.DoWork += (o, e) => DrawSpiroGraph();
- }
- public void SetLineFeatures()
- {
- pline = new Polyline();
- pline.Stroke = Brushes.Blue;
- }
- public void DrawSpiroGraph()
- {
- double aaFactor = (rand.Next(10, 96)) * (-0.01);
- for (int i = 0; i <= numPoints; i++)
- {
- Thread.Sleep(25);
- pt = new Point();
- pt.X = x0 + r * Math.Cos(a);
- pt.Y = y0 + r * Math.Sin(a);
- double rr = 0.5 * r;
- double aa = aaFactor * a;
- Point pnt = new Point();
- pnt.X = pt.X + rr * Math.Cos(aa);
- pnt.Y = pt.Y + rr * Math.Sin(aa);
- a += 0.5;
- //System.Threading.Thread.Sleep(1000);
- pline.Dispatcher.BeginInvoke((Action)(() => pline.Points.Add(pnt)));
- }
- }
- private void button1_Click(object sender, RoutedEventArgs e)
- {
- if (canvas.Children.Contains(pline))
- canvas.Children.Remove(pline);
- SetLineFeatures();
- Worker.RunWorkerAsync();
- canvas.Children.Add(pline);
- }
- private void button2_Click(object sender, RoutedEventArgs e)
- {
- this.Close();
- }
- }
- }
Add Comment
Please, Sign In to add comment