Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5.  
  6. namespace Graphics2nd
  7. {
  8. public partial class ThreeDimencions : Form
  9. {
  10. delegate double Func(double aa, double bb);
  11.  
  12. struct Point3d
  13. {
  14. public double x, y, z;
  15. public Point3d(double a, double b, double c)
  16. {
  17. x = a; y = b; z = c;
  18. }
  19. }
  20. struct _Graph
  21. {
  22. public double phi, psi;
  23. public double a, b, c, d;
  24. public double Max, Min;
  25. public Func[] current;
  26. }
  27. struct Point
  28. {
  29. public double X;
  30. public double Y;
  31. public Point(double x, double y)
  32. {
  33. this.X = x;
  34. this.Y = y;
  35. }
  36. }
  37.  
  38. _Graph graph;
  39. Point3d E1, E2, E3;
  40. Point From, Delta;
  41. Bitmap bitmap;
  42. double fAngle, sAngle;
  43. bool isButtonPressed = false;
  44. double mass;
  45. List<List<Point>> toDraw;
  46. List<List<Point3d>> Calculated;
  47. int Closeness = 9;
  48. double[,] ZBUF;
  49. int[,] ZCOLOR;
  50.  
  51.  
  52. public ThreeDimencions()
  53. {
  54. InitializeComponent();
  55. Delta = new Point(Width/2, Height/2);
  56. toDraw = new List<List<Point>>();
  57. Calculated = new List<List<Point3d>>();
  58. graph = new _Graph();
  59. graph.a = -1;
  60. graph.b = 1;
  61. graph.current = new Func[3];
  62.  
  63. graph.c = -1;
  64. graph.d = 1;
  65.  
  66. fAngle = 0;
  67. sAngle = 0;
  68. graph.phi = fAngle * Math.PI / 180;
  69. graph.psi = sAngle * Math.PI / 180;
  70.  
  71. E1 = new Point3d(Math.Cos(graph.phi), Math.Sin(graph.phi), 0);
  72. E2 = new Point3d(-Math.Sin(graph.phi) * Math.Sin(graph.psi), Math.Cos(graph.phi) *Math.Sin(graph.psi) , Math.Cos(graph.psi));
  73. E3 = vectVect(E1, E2);
  74.  
  75. mass = 0.5;
  76.  
  77. ZBUF = new double[Width, Height];
  78. ZCOLOR = new int[Width, Height];
  79.  
  80. bitmap = new Bitmap(Width, Height);
  81. Paint += (object a, PaintEventArgs e) => { e.Graphics.DrawImage(bitmap, 0, 0, bitmap.Width, bitmap.Height); };
  82. MouseWheel += (object a, MouseEventArgs e) =>
  83. {
  84. if (e.Delta > 0) mass *= 1.1; else mass *= 0.9;
  85. bitmap = new Bitmap(bitmap.Width, bitmap.Height);
  86. FindProjection();
  87. DrawAxis();
  88. Draw();
  89. };
  90. //Log();
  91. //FillAndDraw();
  92.  
  93. initzbuf();
  94. fill_tr(new Point3d(0.5, 0.5, 0.5), new Point3d(0.3, 0.3, 0.3), new Point3d(0.9, 0.2, 0.8), 130);
  95. Display();
  96. DoubleBuffered = true;
  97. }
  98.  
  99. private void initzbuf()
  100. {
  101. for (int i = 0; i < Width; i++)
  102. for (int j = 0; j < Height; j++)
  103. ZBUF[i, j] = float.MaxValue;
  104. }
  105.  
  106. private void Display()
  107. {
  108. for (int i = 0; i < Width; i++)
  109. for (int j = 0; j < Height; j++)
  110. bitmap.SetPixel(i, j , Color.FromArgb(ZCOLOR[i, j]));
  111. }
  112.  
  113. private void Put_In_Zbuf(int x, int y, double z, int c)
  114. {
  115. if (z < ZBUF[x, y])
  116. {
  117. ZBUF[x, y] = z;
  118. ZCOLOR[x, y] = c;
  119. }
  120. }
  121.  
  122. private void fill_tr(Point3d A, Point3d B, Point3d C, int color)
  123. {
  124. double SX, SY;
  125. SX = mass * Width;
  126. SY = mass * Height;
  127. double u, v, du, dv;
  128. Point3d R = new Point3d();
  129. int X, Y;
  130. du = 0.007;
  131. dv = 0.007;
  132. for (u = 0; u <= 1.0; u += du)
  133. for (v = 0; v <= 1 - u; v += dv)
  134. {
  135. R.x = A.x + u * (B.x - A.x) + v * (C.x - A.x);
  136. R.y = A.y + u * (B.y - A.y) + v * (C.y - A.y);
  137. R.z = A.z + u * (B.z - A.z) + v * (C.z - A.z);
  138. X = (int)((SX * vectScalar(R, E1)) + Delta.X);
  139. Y = (int)((SX * vectScalar(R, E2)) + Delta.Y);
  140. Put_In_Zbuf(X, Y, R.z, color);
  141. }
  142. }
  143.  
  144. private void Test()
  145. {
  146. graph.a = -Math.PI;
  147. graph.b = Math.PI;
  148. graph.c = -Math.PI;
  149. graph.d = Math.PI;
  150.  
  151. graph.current[0] = new Func((u, v) => { return Math.Cos(u); });
  152. graph.current[1] = new Func((u, v) => { return v; });
  153. graph.current[2] = new Func((u, v) => { return u; });
  154. }
  155.  
  156. private void Paraboloid()
  157. {
  158. graph.a = -Math.PI;
  159. graph.b = Math.PI;
  160. graph.c = -2;
  161. graph.d = 2 ;
  162.  
  163. graph.current[0] = new Func((u, v) => { return Math.Cosh(u) * v; });
  164. graph.current[1] = new Func((u, v) => { return Math.Sinh(u) *v; });
  165. graph.current[2] = new Func((u, v) => { return v*v; });
  166. }
  167. private void Mebius()
  168. {
  169. graph.a = 0;
  170. graph.b = 2 * Math.PI;
  171. graph.c = -1;
  172. graph.d = 1;
  173.  
  174. graph.current[0] = new Func((u, v) => { return (1+v/2*Math.Cos(u/2))*Math.Cos(u); });
  175. graph.current[1] = new Func((u, v) => { return (1 + v / 2 * Math.Cos(u / 2)) * Math.Sin(u); });
  176. graph.current[2] = new Func((u, v) => { return v / 2 * Math.Sin(u / 2); });
  177. }
  178. private void Thor()
  179. {
  180. graph.a = -Math.PI-1;
  181. graph.b = Math.PI+1;
  182. graph.c = -Math.PI-1;
  183. graph.d = Math.PI+1;
  184.  
  185. graph.current[0] = new Func((u, v) => { return Math.Cos(u) * (3 + Math.Cos(v)); });
  186. graph.current[1] = new Func((u, v) => { return Math.Sin(u) * (3 + Math.Cos(v)); });
  187. graph.current[2] = new Func((u, v) => { return Math.Sin(v); });
  188. }
  189. private void Dini()
  190. {
  191. graph.a = 0;
  192. graph.b = 4 * Math.PI;
  193. graph.c = 0.001;
  194. graph.d = 2;
  195.  
  196. graph.current[0] = new Func((u, v) => { return Math.Cos(u) * Math.Sin(v); });
  197. graph.current[1] = new Func((u, v) => { return Math.Sin(u) * Math.Cos(v); });
  198. graph.current[2] = new Func((u, v) => { return Math.Cos(v) + Math.Log(Math.Tan(v / 2)) + 0.2 * u - 4; });
  199. }
  200. private void Cube()
  201. {
  202. graph.a = 0;
  203. graph.b = 2*Math.PI;
  204. graph.c = 0;
  205. graph.d = Math.PI;
  206.  
  207. graph.current[0] = new Func((u, v) => { return 2 * Math.Cos(u) * Math.Cos(v); });
  208. graph.current[1] = new Func((u, v) => { return 2 * Math.Cos(u) * Math.Sin(v); });
  209. graph.current[2] = new Func((u, v) => { return 2*Math.Sin(u); });
  210.  
  211. }
  212. private void Log()
  213. {
  214. graph.a = 0;
  215. graph.b = 3 * Math.PI;
  216. graph.c = -Math.PI;
  217. graph.d = Math.PI;
  218.  
  219. graph.current[0] = new Func((u, v) => { return u * Math.Cos(u) * (Math.Cos(v) + 1); });
  220. graph.current[1] = new Func((u, v) => { return u * Math.Sin(u) * (Math.Cos(v) + 1); });
  221. graph.current[2] = new Func((u, v) => { return u * Math.Sin(v); });
  222. }
  223.  
  224. private void ThreeDimencions_MouseDown(object sender, MouseEventArgs e)
  225. {
  226. From = new Point(PointToClient(MousePosition).X, PointToClient(MousePosition).Y);
  227. if (e.Button == MouseButtons.Left)
  228. {
  229. isButtonPressed = true;
  230. }
  231. }
  232. private void ThreeDimencions_MouseUp(object sender, MouseEventArgs e)
  233. {
  234. isButtonPressed = false;
  235. if(e.Button == MouseButtons.Right)
  236. {
  237. bitmap = new Bitmap(bitmap.Width, bitmap.Height);
  238. Delta.X += PointToClient(MousePosition).X - From.X;
  239. Delta.Y += PointToClient(MousePosition).Y - From.Y;
  240. FindProjection();
  241. DrawAxis();
  242. Draw();
  243. }
  244. }
  245. private void ThreeDimencions_MouseMove(object sender, MouseEventArgs e)
  246. {
  247. if (isButtonPressed)
  248. {
  249. bitmap = new Bitmap(bitmap.Width, bitmap.Height);
  250. double OnX = (PointToClient(MousePosition).X - From.X) * 0.0001;
  251. double OnY = (PointToClient(MousePosition).Y - From.Y) * 0.0001;
  252. for (int i = 0; i < Calculated.Count; i++)
  253. {
  254. for (int j = 0; j < Calculated[i].Count; j++)
  255. {
  256. Calculated[i][j] = new Point3d(Calculated[i][j].x, Calculated[i][j].y * Math.Cos(OnY) + Calculated[i][j].z * Math.Sin(OnY),
  257. -Calculated[i][j].y * Math.Sin(OnY) + Calculated[i][j].z * Math.Cos(OnY));
  258. Calculated[i][j] = new Point3d(Calculated[i][j].x * Math.Cos(OnX) + Calculated[i][j].z * Math.Sin(OnX), Calculated[i][j].y,
  259. -Calculated[i][j].x * Math.Sin(OnX) + Calculated[i][j].z * Math.Cos(OnX));
  260. }
  261. }
  262. FindProjection();
  263. DrawAxis();
  264. Draw();
  265. }
  266. }
  267.  
  268. void FillAndDraw()
  269. {
  270. double x, y, dx, dy;
  271. dx = (graph.b - graph.a) / 20;
  272. dy = (graph.d - graph.c) / 20;
  273. List<Point3d> toAdd;
  274.  
  275. for (x = graph.a; x <= graph.b; x += dx)
  276. {
  277. toAdd = new List<Point3d>();
  278. y = graph.c;
  279. toAdd.Add(new Point3d(graph.current[0](x, y), graph.current[1](x, y), graph.current[2](x, y)));
  280. for (y = graph.c; y <= graph.d; y += dy)
  281. {
  282. toAdd.Add(new Point3d(graph.current[0](x, y), graph.current[1](x, y), graph.current[2](x, y)));
  283. }
  284. Calculated.Add(new List<Point3d>(toAdd));
  285. }
  286.  
  287. for (y = graph.c; y <= graph.d; y += dy)
  288. {
  289. toAdd = new List<Point3d>();
  290. x = graph.a;
  291. toAdd.Add(new Point3d(graph.current[0](x, y), graph.current[1](x, y), graph.current[2](x, y)));
  292. for (x = graph.a; x <= graph.b; x += dx)
  293. {
  294. toAdd.Add(new Point3d(graph.current[0](x, y), graph.current[1](x, y), graph.current[2](x, y)));
  295. }
  296. Calculated.Add(new List<Point3d>(toAdd));
  297. }
  298.  
  299. FindProjection();
  300. DrawAxis();
  301. Draw();
  302.  
  303. }
  304. void FindProjection()
  305. {
  306. double SX, SY;
  307. List<Point> toAdd;
  308. SX = mass * Width;
  309. SY = mass * Height;
  310.  
  311. foreach(List<Point3d> list in Calculated)
  312. {
  313. toAdd = new List<Point>();
  314. foreach(Point3d p in list)
  315. {
  316. toAdd.Add(new Point((int)(SX * vectScalar(p, E1)) + Delta.X, (int)(SY * vectScalar(p, E2)) + Delta.Y));
  317. }
  318. toDraw.Add(toAdd);
  319. }
  320. }
  321. void DrawAxis()
  322. {
  323. double SX, SY;
  324. SX = 500;
  325. SY = 500;
  326.  
  327. Line((int)(SX * vectScalar(E1, new Point3d(1,0,0)) + Delta.X) ,(int)Delta.X,
  328. (int)(SY * vectScalar(E1, new Point3d(0,0,1)) + Delta.Y), (int)Delta.Y, bitmap, Color.Red);
  329. Line((int)(SX * vectScalar(E2, new Point3d(1, 0, 0)) + Delta.X), (int)Delta.X,
  330. (int)(SY * vectScalar(E2, new Point3d(0, 0, 1)) + Delta.Y), (int)Delta.Y, bitmap, Color.Green);
  331. Line((int)(SX * vectScalar(E3, new Point3d(1, 0, 0)) + Delta.X), (int)Delta.X,
  332. (int)(SY * vectScalar(E3, new Point3d(0, 0, 1)) + Delta.Y), (int)Delta.Y, bitmap, Color.Blue);
  333. }
  334. void Draw()
  335. {
  336. for (int i = 0; i < toDraw.Count; i++)
  337. {
  338. for (int j = 0; j < toDraw[i].Count-1; j++)
  339. {
  340. Line((int)toDraw[i][j].X, (int)toDraw[i][j+1].X, (int)toDraw[i][j].Y, (int)toDraw[i][j+1].Y, bitmap, Color.Black);
  341. }
  342. }
  343. toDraw = new List<List<Point>>();
  344. }
  345.  
  346. private void ThreeDimencions_KeyDown(object sender, KeyEventArgs e)
  347. {
  348. if(e.KeyCode == Keys.Down)
  349. {
  350. bitmap = new Bitmap(bitmap.Width, bitmap.Height);
  351. graph.psi += 22.5 * Math.PI / 180;
  352. E1 = new Point3d(Math.Cos(graph.phi), Math.Sin(graph.phi), 0);
  353. E2 = new Point3d(-Math.Sin(graph.phi) * Math.Sin(graph.psi), Math.Cos(graph.phi) * Math.Sin(graph.psi), Math.Cos(graph.psi));
  354. E3 = vectVect(E1, E2);
  355. FindProjection();
  356. DrawAxis();
  357. Draw();
  358. }
  359. if(e.KeyCode == Keys.Up)
  360. {
  361. bitmap = new Bitmap(bitmap.Width, bitmap.Height);
  362. graph.psi -= 22.5*Math.PI/180;
  363. E1 = new Point3d(Math.Cos(graph.phi), Math.Sin(graph.phi), 0);
  364. E2 = new Point3d(-Math.Sin(graph.phi) * Math.Sin(graph.psi), Math.Cos(graph.phi) * Math.Sin(graph.psi), Math.Cos(graph.psi));
  365. E3 = vectVect(E1, E2);
  366. FindProjection();
  367. DrawAxis();
  368. Draw();
  369. }
  370. if(e.KeyCode == Keys.Left)
  371. {
  372. bitmap = new Bitmap(bitmap.Width, bitmap.Height);
  373. graph.phi += 22.5 * Math.PI / 180;
  374. E1 = new Point3d(Math.Cos(graph.phi), Math.Sin(graph.phi), 0);
  375. E2 = new Point3d(-Math.Sin(graph.phi) * Math.Sin(graph.psi), Math.Cos(graph.phi) * Math.Sin(graph.psi), Math.Cos(graph.psi));
  376. E3 = vectVect(E1,E2);
  377. FindProjection();
  378. DrawAxis();
  379. Draw();
  380. }
  381. if(e.KeyCode == Keys.Right)
  382. {
  383. bitmap = new Bitmap(bitmap.Width, bitmap.Height);
  384. graph.phi -= 22.5 * Math.PI / 180;
  385. E1 = new Point3d(Math.Cos(graph.phi), Math.Sin(graph.phi), 0);
  386. E2 = new Point3d(-Math.Sin(graph.phi) * Math.Sin(graph.psi), Math.Cos(graph.phi) * Math.Sin(graph.psi), Math.Cos(graph.psi));
  387. E3 = vectVect(E1, E2);
  388. FindProjection();
  389. DrawAxis();
  390. Draw();
  391. }
  392. if(e.KeyCode == Keys.Space)
  393. {
  394. List<Point3d> toAdd = new List<Point3d>();
  395. Calculated = new List<List<Point3d>>();
  396. toAdd.Add(new Point3d(0, 0, 0));
  397. toAdd.Add(new Point3d(0, 1, 0));
  398. toAdd.Add(new Point3d(1, 1, 0));
  399. toAdd.Add(new Point3d(1, 0, 0));
  400. toAdd.Add(new Point3d(0, 0, 0));
  401. Calculated.Add(toAdd);
  402. toAdd = new List<Point3d>();
  403. toAdd.Add(new Point3d(0, 0, 1));
  404. toAdd.Add(new Point3d(0, 1, 1));
  405. toAdd.Add(new Point3d(1, 1, 1));
  406. toAdd.Add(new Point3d(1, 0, 1));
  407. toAdd.Add(new Point3d(0, 0, 1));
  408. Calculated.Add(toAdd);
  409. toAdd = new List<Point3d>();
  410. toAdd.Add(new Point3d(0, 0, 0));
  411. toAdd.Add(new Point3d(0, 0, 1));
  412. Calculated.Add(toAdd);
  413. toAdd = new List<Point3d>();
  414. toAdd.Add(new Point3d(0, 1, 0));
  415. toAdd.Add(new Point3d(0, 1, 1));
  416. Calculated.Add(toAdd);
  417. toAdd = new List<Point3d>();
  418. toAdd.Add(new Point3d(1, 0, 0));
  419. toAdd.Add(new Point3d(1, 0, 1));
  420. Calculated.Add(toAdd);
  421. toAdd = new List<Point3d>();
  422. toAdd.Add(new Point3d(1, 1, 0));
  423. toAdd.Add(new Point3d(1, 1, 1));
  424. Calculated.Add(toAdd);
  425. toAdd = new List<Point3d>();
  426. Text += "1";
  427. FindProjection();
  428. DrawAxis();
  429. Draw();
  430. }
  431. }
  432.  
  433. private void bezieToolStripMenuItem_Click(object sender, EventArgs e)
  434. {
  435. FindProjection();
  436. bitmap = new Bitmap(bitmap.Width, bitmap.Height);
  437. Text = toDraw.Count.ToString();
  438. foreach (List<Point> Points in toDraw)
  439. {
  440. List<Point> List = new List<Point>();
  441. List.Add(Points[0]);
  442.  
  443. for (int i = 1; i < Points.Count - 1; i++)
  444. {
  445. for (int j = 0; j < Closeness; j++)
  446. {
  447. List.Add(Points[i]);
  448. }
  449. }
  450.  
  451. List.Add(Points[Points.Count - 1]);
  452.  
  453. Text += "2";
  454. DeKastell(List, Closeness, bitmap, Color.Black);
  455. }
  456. toDraw.Clear();
  457. }
  458. private void DeKastell(List<Point> LIST, int Closeness, Bitmap bmp, Color color)//ШАГ МЕНЯТЬ
  459. {
  460. Point New, Old;
  461. int n;
  462. List<Point> R = new List<Point>(LIST.Count);
  463. List<Point> Q = new List<Point>(LIST.Count);
  464. for (int j = 0; j < LIST.Count; j++)
  465. {
  466. Q.Add(new Point(0, 0));
  467. }
  468.  
  469. Old = new Point(LIST[0].X, LIST[0].Y);
  470.  
  471. for (double t = 0; t < 1; t += 0.001)
  472. {
  473. n = LIST.Count;
  474. foreach (Point a in LIST)
  475. {
  476. R.Add(new Point(a.X, a.Y));
  477. }
  478.  
  479. while (n > 0)
  480. {
  481. for (int j = 0; j < n - 1; j++)
  482. {
  483. Q[j] = new Point(R[j].X + t * (R[j + 1].X - R[j].X),
  484. R[j].Y + t * (R[j + 1].Y - R[j].Y));
  485. }
  486. n--;
  487. for (int j = 0; j < n; j++)
  488. {
  489. R[j] = new Point(Q[j].X, Q[j].Y);
  490. }
  491. }
  492.  
  493. New = new Point(R[0].X, R[0].Y);
  494. Line((int)Old.X, (int)New.X, (int)Old.Y, (int)New.Y, bmp, color);
  495. Old = new Point(New.X, New.Y);
  496.  
  497. R = new List<Point>();
  498. for (int j = 0; j < LIST.Count; j++)
  499. {
  500. Q[j] = new Point(0, 0);
  501. }
  502. }
  503. Line((int)Old.X, (int)LIST[LIST.Count-1].X, (int)Old.Y, (int)LIST[LIST.Count-1].Y, bmp, color);
  504. }
  505. private void splineToolStripMenuItem_Click(object sender, EventArgs e)
  506. {
  507. FindProjection();
  508. bitmap = new Bitmap(bitmap.Width, bitmap.Height);
  509. foreach (List<Point> points in toDraw)
  510. {
  511. if (points.Count > 2)
  512. {
  513. points.Add(points[0]);
  514. points.Add(points[1]);
  515. }
  516. Quadratic(points,bitmap, Color.Black);
  517. }
  518. toDraw.Clear();
  519. }
  520. private void Quadratic(List<Point> Points, Bitmap bitmap, Color color)//ШАГ МЕНЯТЬ
  521. {
  522. Point Old;
  523. Point New;
  524. int i = 0;
  525.  
  526. Old = new Point((Points[i].X + Points[i + 1].X) / 2, (Points[i].Y + Points[i + 1].Y) / 2);
  527.  
  528. for (i = 0; i < Points.Count - 2; i++)
  529. {
  530. for (double j = 0; j < 1.0; j += 0.01)
  531. {
  532. New = new Point((0.5 * (1 - j) * (1 - j) * Points[i].X
  533. + (0.75 - (j - 0.5) * (j - 0.5)) * Points[i + 1].X
  534. + 0.5 * j * j * Points[i + 2].X),
  535. (0.5 * (1 - j) * (1 - j) * Points[i].Y
  536. + (0.75 - (j - 0.5) * (j - 0.5)) * Points[i + 1].Y + 0.5 * j * j * Points[i + 2].Y));
  537. Line((int)Old.X, (int)New.X, (int)Old.Y, (int)New.Y, bitmap, Color.Black);
  538. Old = new Point(New.X, New.Y);
  539. }
  540. }
  541. }
  542.  
  543. private void ThreeDimencions_FormClosed(object sender, FormClosedEventArgs e)
  544. {
  545. Form1.IsWindowOpened = false;
  546. }
  547. Point3d vectVect(Point3d a, Point3d b)
  548. {
  549. return new Point3d(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
  550. }
  551. double vectScalar(Point3d a, Point3d b)
  552. {
  553. return a.x * b.x + a.y * b.y + a.z * b.z;
  554. }
  555. private void Line(int FirstPointX, int SecondPointX, int FirstPointY, int SecondPointY, Bitmap map, Color color)
  556. {
  557. if (!(FirstPointX == SecondPointX && SecondPointY == FirstPointY))
  558. {
  559. int A = SecondPointY - FirstPointY;
  560. int B = FirstPointX - SecondPointX;
  561. int sgn = Math.Abs(A) > Math.Abs(B) ? 1 : -1;
  562. int sgnA = A < 0 ? -1 : 1;
  563. int sgnB = B < 0 ? -1 : 1;
  564.  
  565. int f = 0;
  566. if (FirstPointX > 0 && FirstPointX < map.Width && FirstPointY > 0 && FirstPointY < map.Height)
  567. map.SetPixel(FirstPointX, FirstPointY, color);
  568. int x = FirstPointX, y = FirstPointY;
  569.  
  570.  
  571. if (sgn == -1)
  572. {
  573. do
  574. {
  575. f += 2 * A * sgnA;
  576. if (f > 1)
  577. {
  578. f -= 2 * B * sgnB;
  579. y += sgnA;
  580. }
  581. x -= sgnB;
  582. if (x > 0 && x < map.Width && y > 0 && y < map.Height)
  583. map.SetPixel(x, y, color);
  584. } while (x != SecondPointX || y != SecondPointY);
  585. }
  586. else
  587. {
  588. do
  589. {
  590. f += 2 * B * sgnB;
  591. if (f > 1)
  592. {
  593. f -= 2 * A * sgnA;
  594. x -= sgnB;
  595. }
  596. y += sgnA;
  597. if (x > 0 && x < map.Width && y > 0 && y < map.Height)
  598. map.SetPixel(x, y, color);
  599. } while (x != SecondPointX || y != SecondPointY);
  600. }
  601.  
  602. Invalidate();
  603. }
  604. } // линия
  605. }
  606. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement