Advertisement
Guest User

Untitled

a guest
Nov 21st, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace linia
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19.  
  20. private void Form1_Load(object sender, EventArgs e)
  21. {
  22.  
  23. }
  24.  
  25. private void button1_Click(object sender, EventArgs e)
  26. {
  27. Bitmap pom = new Bitmap(pictureBox1.Width, pictureBox1.Height);
  28. int y2, y1, x1, x2;
  29. x1 = (int)numericUpDown1.Value;
  30. x2 = (int)numericUpDown3.Value;
  31. y1 = (int)numericUpDown2.Value;
  32. y2 = (int)numericUpDown4.Value;
  33. float m, y,dy, dx;
  34. int start = System.Environment.TickCount;
  35. dy = y2 - y1;
  36. dx = x2 - x1;
  37.  
  38. m = dy / dx;
  39.  
  40. for (int i = 0; i < 10000; i++)
  41. {
  42.  
  43. y = y1;
  44. for (int x = x1; x <= x2; x++)
  45. {
  46. pom.SetPixel(x, (int)Math.Round(y), Color.Red);
  47. y += m;
  48. }
  49. }
  50. pictureBox1.Image = pom;
  51. int stop = System.Environment.TickCount;
  52. MessageBox.Show("Obliczenia przyrostowe trwały " + (stop - start).ToString() + "ms");
  53. }
  54.  
  55. private void button2_Click(object sender, EventArgs e)
  56. {
  57. Bitmap pom = new Bitmap(pictureBox1.Width, pictureBox1.Height);
  58. int dx, dy,incrE, incrNE, d ,x ,y;
  59. int x2, x1, y2, y1;
  60.  
  61. x1 = (int)numericUpDown1.Value;
  62. x2 = (int)numericUpDown3.Value;
  63. y1 = (int)numericUpDown2.Value;
  64. y2 = (int)numericUpDown4.Value;
  65. int start = System.Environment.TickCount;
  66.  
  67. dx = x2 - x1;
  68. dy = y2 - y1;
  69. d = 2 * dy - dx;
  70. incrE = dy * 2;
  71. incrNE = (dy - dx) * 2;
  72. for (int i = 0; i < 10000; i++)
  73. {
  74. x = x1;
  75. y = y1;
  76. pom.SetPixel(x, y, Color.Aqua);
  77.  
  78. while (x < x2)
  79. {
  80. if (d <= 0)
  81. {
  82. d += incrE;
  83. x++;
  84. }
  85. else
  86. {
  87. d += incrNE;
  88. x++;
  89. y++;
  90. }
  91. pom.SetPixel(x, y, Color.Aqua);
  92. }
  93.  
  94. }
  95. int stop = System.Environment.TickCount;
  96.  
  97. pictureBox1.Image = pom;
  98. MessageBox.Show("Obliczenia przyrostowe trwały " + (stop - start).ToString() + "ms");
  99. }
  100.  
  101.  
  102.  
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement