Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.IO;
- public partial class LDforma : System.Web.UI.Page
- {
- static int R = 5;
- static int centerX = R;
- static int centerY = R;
- protected void Page_Load(object sender, EventArgs e)
- {
- Table1.Visible = false;
- Label2.Text = R.ToString();
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- Rasymas();
- }
- private void Rasymas()
- {
- using (StreamWriter writer = new StreamWriter(Server.MapPath("App_Data/U3rez.txt")))
- {
- writer.WriteLine(" Circle radius is {0}", R);
- writer.WriteLine("The matrix is:");
- Table1.Visible = true;
- int[][] grid = new int[2 * R][];
- for (int i = 0; i < 2 * R; i++)
- grid[i] = new int[2 * R];
- int counter = 1;
- for (int y = 0; y < 2 * R; y++)
- {
- for (int x = 0; x < 2 * R; x++)
- {
- int cornerX = x >= R ? x + 1 : x;
- int cornerY = y >= R ? y + 1 : y;
- if (distToCenter(cornerX, cornerY) <= R)
- {
- grid[y][x] = counter++;
- }
- }
- }
- for (int y = 0; y < 2 * R; y++)
- {
- TableRow row = new TableRow();
- Table1.Rows.Add(row);
- for (int x = 0; x < 2 * R; x++)
- {
- writer.Write(String.Format("{0, 3}", grid[y][x]) + " ");
- TableCell cell = new TableCell();
- cell.Text = grid[y][x].ToString();
- row.Cells.Add(cell);
- }
- writer.WriteLine();
- }
- }
- }
- private static double distToCenter(int x, int y)
- {
- return Math.Sqrt(Math.Pow(x - centerX, 2) + Math.Pow(y - centerY, 2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement