Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. namespace AnimacjaPoSINorazCOS
  2. {
  3. public partial class SIN_COS : Form
  4. {
  5. const int Margines = 20;
  6.  
  7. const int PromieńKulki = 10;
  8.  
  9. Graphics Rysownica;
  10.  
  11. Pen PióroXY, PióroSIN, PióroCOS;
  12.  
  13. int Xmax, Ymax, Xs, Ys;
  14.  
  15. float WspółczynnikSkaliDlaOsiY;
  16.  
  17. int PunktyWjednostkachMiaryOsiY,
  18. PunktyWjednostkachMiaryOsiX;
  19.  
  20. Timer timer1;
  21.  
  22. int IndexPołożeniaKulek;
  23.  
  24. Point[] PunktyNaTorzeLiniiSIN;
  25. Point[] PunktyNaTorzeLiniiCOS;
  26.  
  27.  
  28. public SIN_COS()
  29. {
  30. InitializeComponent();
  31.  
  32. this.Location = new Point(10, 10);
  33.  
  34. this.Width = (int)(Screen.PrimaryScreen.Bounds.Width * 0.7F);
  35. this.Height = (int)(Screen.PrimaryScreen.Bounds.Height * 0.75);
  36. this.StartPosition = FormStartPosition.Manual;
  37.  
  38. Rysownica = this.CreateGraphics();
  39.  
  40. PióroSIN = new Pen(Color.Red, 1F);
  41. PióroSIN.DashStyle = DashStyle.Solid;
  42.  
  43. PióroCOS = new Pen(Color.Blue, 1F);
  44. PióroCOS.DashStyle = DashStyle.Solid;
  45.  
  46. Xmax = this.Size.Width - 2 * Margines;
  47. Ymax = this.Size.Height - 2 * Margines;
  48.  
  49. Xs = Xmax / 2;
  50. Ys = Ymax / 2;
  51.  
  52. WspółczynnikSkaliDlaOsiY = Ymax / 8;
  53.  
  54. PunktyWjednostkachMiaryOsiY = (int)(WspółczynnikSkaliDlaOsiY * Math.PI);
  55.  
  56. PunktyWjednostkachMiaryOsiX = 4 * PunktyWjednostkachMiaryOsiY;
  57.  
  58. PunktyNaTorzeLiniiSIN = new Point[PunktyWjednostkachMiaryOsiX + 1];
  59. PunktyNaTorzeLiniiCOS = new Point[PunktyWjednostkachMiaryOsiX + 1];
  60.  
  61. IndexPołożeniaKulek = 0;
  62.  
  63. int Dx = (Xmax - 2 * Margines) / PunktyWjednostkachMiaryOsiX;
  64.  
  65. int Fi;
  66.  
  67. float Fi_w_Radianach;
  68.  
  69. int IndexPunktówOsiX;
  70.  
  71.  
  72. for (Fi = Xs - PunktyWjednostkachMiaryOsiX / 2 + Margines, IndexPunktówOsiX = 0;
  73. IndexPunktówOsiX <= PunktyWjednostkachMiaryOsiX; Fi += Dx)
  74. {
  75. Fi_w_Radianach = (float)((Fi * Math.PI) / 180);
  76.  
  77. PunktyNaTorzeLiniiSIN[IndexPunktówOsiX] = new Point(Fi,
  78. Ys - (int)(WspółczynnikSkaliDlaOsiY * Math.Sin(Fi_w_Radianach)));
  79. PunktyNaTorzeLiniiCOS[IndexPunktówOsiX] = new Point(Fi,
  80. Ys - (int)(WspółczynnikSkaliDlaOsiY * Math.Cos(Fi_w_Radianach)));
  81. IndexPunktówOsiX++;
  82. }
  83.  
  84. this.DoubleBuffered = true;
  85.  
  86. timer1.Interval = 200;
  87.  
  88. timer1.Enabled = true;
  89.  
  90. }
  91.  
  92. private void InitializeComponent()
  93. {
  94. throw new NotImplementedException();
  95. }
  96.  
  97. private void SIN_COS_Paint(object sender, PaintEventArgs e)
  98. {
  99. PióroXY.StartCap = LineCap.Flat;
  100. PióroXY.EndCap = LineCap.ArrowAnchor;
  101.  
  102. e.Graphics.DrawLine(PióroXY,
  103. Xs - PunktyWjednostkachMiaryOsiX / 2 + Margines, Ymax / 2,
  104. Xs + PunktyWjednostkachMiaryOsiX / 2 + Margines, Ymax / 2);
  105.  
  106. e.Graphics.DrawLine(PióroXY, Xs + Margines, Ymax - Margines,
  107. Xs + Margines, Margines);
  108.  
  109. e.Graphics.DrawCurve(PióroSIN, PunktyNaTorzeLiniiSIN);
  110. e.Graphics.DrawCurve(PióroCOS, PunktyNaTorzeLiniiCOS);
  111.  
  112. e.Graphics.FillEllipse(Brushes.Yellow,
  113. PunktyNaTorzeLiniiSIN[IndexPołożeniaKulek].X - PromieńKulki,
  114. PunktyNaTorzeLiniiSIN[IndexPołożeniaKulek].Y - PromieńKulki,
  115. PromieńKulki + PromieńKulki, PromieńKulki + PromieńKulki);
  116.  
  117. e.Graphics.FillEllipse(Brushes.Green,
  118. PunktyNaTorzeLiniiCOS[IndexPołożeniaKulek].X - PromieńKulki,
  119. PunktyNaTorzeLiniiCOS[IndexPołożeniaKulek].Y - PromieńKulki,
  120. PromieńKulki + PromieńKulki, PromieńKulki + PromieńKulki);
  121. }
  122.  
  123.  
  124. private void timer1_Tick(object sender, EventArgs e)
  125. {
  126. if (IndexPołożeniaKulek < PunktyWjednostkachMiaryOsiX)
  127. IndexPołożeniaKulek++;
  128. else
  129. IndexPołożeniaKulek = 0;
  130.  
  131. this.Refresh();
  132. }
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement