1: class Program
2: {
3: const int startingAsciiCode = 32;
4: const int maxSize = 40;
5: static void Main(string[] args)
6: {
7: while (true)
8: {
9: Console.Clear();
10: Console.WriteLine("Please insert the size: (ctrl + c to exit)");
11: string size = Console.ReadLine();
12: int parsedSize;
13: if (!int.TryParse(size, out parsedSize) || (parsedSize < 2 || parsedSize > 94))
14: {
15: Console.WriteLine("Please introduce a valid integer value between 2 and 94");
16: Console.ReadKey();
17: }
18: else
19: {
20: Console.Clear();
21:
22: // we calculate the diagonal size
23: int diagonal = (parsedSize * 2) - 1;
24: int charsToDraw = 1;
25: // Iterate all the rows
26: for (int row = 1; row <= diagonal; row++)
27: {
28: // Calculate the blank spaces and the total amount of chars to draw
29: int blankSpaces = (int)((diagonal - charsToDraw) / 2);
30: int totalSize = blankSpaces + charsToDraw;
31:
32: // Iterate the columns
33: for (int i = 1; i <= totalSize; i++)
34: {
35: if (i < blankSpaces)
36: {
37: // Draw blank spaces
38: Console.Write(' ');
39: }
40: else
41: {
42: // Draw non blank chars
43: // We use a different char for each concentric rhombus
44: int asciiOffset;
45: if (i <= parsedSize)
46: {
47: asciiOffset = i - blankSpaces;
48: }
49: else
50: {
51: asciiOffset = (totalSize + 1) - i;
52: }
53: Console.Write((Char)(startingAsciiCode + asciiOffset));
54: }
55: }
56: Console.WriteLine();
57: if (row < parsedSize)
58: {
59: charsToDraw = charsToDraw + 2;
60: }
61: else
62: {
63: charsToDraw = charsToDraw - 2;
64: }
65: }
66: Console.WriteLine();
67: Console.WriteLine("Press a key to continue");
68: Console.ReadKey();
69: }
70: }
71: }
72: }