Untitled

mail@pastecode.io avatarunknown
csharp
2 months ago
7.9 kB
1
Indexable
Never
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace DrawSpral_Pattern_test1
//{
//    internal class PatternnaDrawnaDrawnaDraw
//    {
//        public void Draw()
//        {
//            Random r = new Random();
//            int size = r.Next(1, 5);
//            int r_size = (4 * size) + 1;
//            int mid = (r_size - 1) / 2;
//            int x, y;

//            string[,] array = new string[r_size, r_size];
//            for (y = 0; y < r_size; y++)
//            {
//                for (x = 0; x < r_size; x++)
//                {
//                    array[y, x] = "*";
//                }
//            }

//            int point_x = mid + 1;
//            int point_y = mid - 1;
//            int walk = 2;
//            x = mid + 1;
//            y = mid - 1;


//            while (x <= array.GetUpperBound(1) && y <= array.GetUpperBound(0))
//            {
//                for (x = point_x; x > point_x - walk; x--)
//                {
//                    array[y, x] = " ";
//                }
//                point_x = x;

//                for (y = point_y; y < point_y + walk; y++)
//                {
//                    array[y, x] = " ";
//                }
//                point_y = y;
//                walk = walk + 2;

//                for (x = point_x; x < point_x + walk; x++)
//                {
//                    array[y, x] = " ";
//                    if (x >= array.GetUpperBound(1))
//                        break;
//                }
//                if (x >= array.GetUpperBound(1))
//                {
//                    if (y >= array.GetUpperBound(0) - 1)
//                        break;
//                }

//                point_x = x;

//                for (y = point_y; y > point_y - walk; y--)
//                {
//                    array[y, x] = " ";
//                }
//                point_y = y;
//                walk = walk + 2; 
//                //RotateArray(array, 2);
//            }


//            for (y = 0; y < r_size; y++)
//            {
//                for (x = 0; x < r_size; x++)
//                {

//                    Console.Write(array[y, x] + " ");
//                }
//                Console.WriteLine();
//            }

//        }

//        public string[,] RotateArray(PatternnaDrawnaDrawnaDraw parameters)
//        {

//            string[,] original = parameters.Array;
//            int rotationChoice = parameters.RotationChoice;

//            int rows = original.GetLength(0);
//            int cols = original.GetLength(1);

//            string[,] rotated = new string[cols, rows];

//            switch (rotationChoice)
//            {
//                case 0: // 0 degrees (no rotation)
//                    rotated = (string[,])original.Clone();
//                    break;
//                case 1: // 90 degrees clockwise
//                    for (int i = 0; i < rows; i++)
//                    {
//                        for (int j = 0; j < cols; j++)
//                        {
//                            rotated[j, rows - 1 - i] = original[i, j];
//                        }
//                    }
//                    break;
//                case 2: // 180 degrees clockwise
//                    for (int i = 0; i < rows; i++)
//                    {
//                        for (int j = 0; j < cols; j++)
//                        {
//                            rotated[rows - 1 - i, cols - 1 - j] = original[i, j];
//                        }
//                    }
//                    break;
//                case 3: // 270 degrees clockwise
//                    for (int i = 0; i < rows; i++)
//                    {
//                        for (int j = 0; j < cols; j++)
//                        {
//                            rotated[cols - 1 - j, i] = original[i, j];
//                        }
//                    }
//                    break;
//            }

//            return rotated;
//        }


//    }
//}

using System;

namespace DrawSpral_Pattern_test1
{
    internal class PatternnaDrawnaDrawnaDraw
    {
        
        public void Draw()
        {
            Random r = new Random();
            int size = r.Next(1, 5);
            int r_size = (4 * size) + 1;
            int mid = (r_size - 1) / 2;
            int x, y;

            string[,] array = new string[r_size, r_size];
            for (y = 0; y < r_size; y++)
            {
                for (x = 0; x < r_size; x++)
                {
                    array[y, x] = "*";
                }
            }

            int point_x = mid + 1;
            int point_y = mid - 1;
            int walk = 2;
            x = mid + 1;
            y = mid - 1;

            while (x <= array.GetUpperBound(1) && y <= array.GetUpperBound(0))
            {
                for (x = point_x; x > point_x - walk; x--)
                {
                    array[y, x] = " ";
                }
                point_x = x;

                for (y = point_y; y < point_y + walk; y++)
                {
                    array[y, x] = " ";
                }
                point_y = y;
                walk = walk + 2;

                for (x = point_x; x < point_x + walk; x++)
                {
                    array[y, x] = " ";
                    if (x >= array.GetUpperBound(1))
                        break;
                }
                if (x >= array.GetUpperBound(1))
                {
                    if (y >= array.GetUpperBound(0) - 1)
                        break;
                }

                point_x = x;

                for (y = point_y; y > point_y - walk; y--)
                {
                    array[y, x] = " ";
                }
                point_y = y;
                walk = walk + 2;
            }

            for (y = 0; y < r_size; y++)
            {
                for (x = 0; x < r_size; x++)
                {
                    Console.Write(array[y, x] + " ");
                }
                Console.WriteLine();
            }
        }

        public string[,] RotateArray(string[,] original, int rotationChoice)
        {
            int rows = original.GetLength(0);
            int cols = original.GetLength(1);

            string[,] rotated = new string[cols, rows];

            switch (rotationChoice)
            {
                case 0: // 0 degrees (no rotation)
                    rotated = (string[,])original.Clone();
                    break;
                case 1: // 90 degrees clockwise
                    for (int i = 0; i < rows; i++)
                    {
                        for (int j = 0; j < cols; j++)
                        {
                            rotated[j, rows - 1 - i] = original[i, j];
                        }
                    }
                    break;
                case 2: // 180 degrees clockwise
                    for (int i = 0; i < rows; i++)
                    {
                        for (int j = 0; j < cols; j++)
                        {
                            rotated[rows - 1 - i, cols - 1 - j] = original[i, j];
                        }
                    }
                    break;
                case 3: // 270 degrees clockwise
                    for (int i = 0; i < rows; i++)
                    {
                        for (int j = 0; j < cols; j++)
                        {
                            rotated[cols - 1 - j, i] = original[i, j];
                        }
                    }
                    break;
            }

            return rotated;
        }
    }
}