Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.IO;
  8.  
  9. public partial class LDforma : System.Web.UI.Page
  10. {
  11. static int R = 5;
  12.  
  13. static int centerX = R;
  14. static int centerY = R;
  15.  
  16. protected void Page_Load(object sender, EventArgs e)
  17. {
  18. Table1.Visible = false;
  19. Label2.Text = R.ToString();
  20. }
  21.  
  22. protected void Button1_Click(object sender, EventArgs e)
  23. {
  24. Rasymas();
  25. }
  26.  
  27. private void Rasymas()
  28. {
  29. using (StreamWriter writer = new StreamWriter(Server.MapPath("App_Data/U3rez.txt")))
  30. {
  31. writer.WriteLine(" Circle radius is {0}", R);
  32.  
  33. writer.WriteLine("The matrix is:");
  34.  
  35.  
  36. Table1.Visible = true;
  37.  
  38. int[][] grid = new int[2 * R][];
  39.  
  40. for (int i = 0; i < 2 * R; i++)
  41. grid[i] = new int[2 * R];
  42.  
  43. int counter = 1;
  44.  
  45. for (int y = 0; y < 2 * R; y++)
  46. {
  47. for (int x = 0; x < 2 * R; x++)
  48. {
  49. int cornerX = x >= R ? x + 1 : x;
  50. int cornerY = y >= R ? y + 1 : y;
  51. if (distToCenter(cornerX, cornerY) <= R)
  52. {
  53. grid[y][x] = counter++;
  54. }
  55. }
  56. }
  57.  
  58. for (int y = 0; y < 2 * R; y++)
  59. {
  60. TableRow row = new TableRow();
  61. Table1.Rows.Add(row);
  62.  
  63. for (int x = 0; x < 2 * R; x++)
  64. {
  65. writer.Write(String.Format("{0, 3}", grid[y][x]) + " ");
  66.  
  67. TableCell cell = new TableCell();
  68. cell.Text = grid[y][x].ToString();
  69. row.Cells.Add(cell);
  70. }
  71. writer.WriteLine();
  72. }
  73. }
  74. }
  75.  
  76. private static double distToCenter(int x, int y)
  77. {
  78. return Math.Sqrt(Math.Pow(x - centerX, 2) + Math.Pow(y - centerY, 2));
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement