Advertisement
Adik28

1 + 1 / A

Jan 22nd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.69 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Threading.Tasks;
  4. using System.Windows.Forms;
  5. using System.Windows.Forms.DataVisualization.Charting;
  6.  
  7. namespace jedenplusjeden
  8. {
  9.     public partial class Form1 : Form
  10.     {
  11.         public double rozrzut = 10;
  12.         public double wspp = 1.1;
  13.         public int l_iteracji = 100;
  14.         public double x = 0;
  15.         public double y = 0;
  16.  
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.            
  21.         }
  22.  
  23.         public double ObliczY(double x)
  24.         {
  25.             return Math.Sin((double)x / 10) * Math.Sin((double)x / 200);
  26.         }
  27.  
  28.         public void UstawXiY()
  29.         {
  30.             var random = new Random();
  31.             x = random.Next(0, 100);
  32.             y = ObliczY(x);
  33.         }
  34.  
  35.         public void RysujLinie()
  36.         {
  37.             chart1.Series.Clear();
  38.             var seria = new Series() { ChartType = SeriesChartType.Line };
  39.  
  40.             for (int x = 0; x < 101; x++)
  41.             {
  42.                 var y = ObliczY(x);
  43.                 seria.Points.Add(new DataPoint(x, y));
  44.             }
  45.  
  46.             chart1.Series.Add(seria);
  47.  
  48.             var seria2 = new Series() { ChartType = SeriesChartType.Point };
  49.             chart1.Series.Add(seria2);
  50.         }
  51.  
  52.         public void SzukajPunktu()
  53.         {
  54.             var random = new Random();
  55.             var r = random.Next(Convert.ToInt32(rozrzut * -100), Convert.ToInt32(rozrzut * 100));
  56.             var xPot = x + (double)r / 100;
  57.             if (xPot > 100)
  58.             {
  59.                 xPot -= rozrzut;
  60.             }
  61.             else if (xPot < 0)
  62.             {
  63.                 xPot += rozrzut;
  64.             }
  65.             var yPot = ObliczY(xPot);
  66.             if (yPot > y)
  67.             {
  68.                 var point = new DataPoint(xPot, yPot) { Color = Color.Green };
  69.                 chart1.Series[1].Points.Add(point);
  70.                 rozrzut *= 1.1;
  71.  
  72.                 x = xPot;
  73.                 y = yPot;
  74.             }
  75.             else
  76.             {
  77.                 var point = new DataPoint(xPot, yPot) { Color = Color.Red };
  78.                 chart1.Series[1].Points.Add(point);
  79.                 rozrzut /= 1.1;
  80.             }
  81.         }
  82.  
  83.         private void button1_Click(object sender, EventArgs e)
  84.         {
  85.             SzukajPunktow();
  86.         }
  87.  
  88.         public async void SzukajPunktow()
  89.         {
  90.             RysujLinie();
  91.             UstawXiY();
  92.  
  93.             for (int i = 0; i < 100; i++)
  94.             {
  95.                 await Task.Delay(1000);
  96.                 SzukajPunktu();
  97.                 textBox1.Text = "Krok: " + (i + 1) + ". x-" + x + " y-" + y + " rozrzut-" + rozrzut;
  98.             }
  99.         }
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement