Created
March 20, 2025 18:45
-
-
Save andrewstellman/00c90773fbe85b68f9dba3d4847f1983 to your computer and use it in GitHub Desktop.
Elliptical Pinwheel Animation for C# Console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Console.CursorVisible = false; | |
Console.Clear(); | |
// Get console dimensions | |
int width = Console.WindowWidth; | |
int height = Console.WindowHeight; | |
// Center point of the pinwheel | |
int centerX = width / 2; | |
int centerY = height / 2; | |
// Characters to use for the pinwheel effect | |
char[] pinwheelChars = new char[] { '│', '/', '─', '\\' }; | |
ConsoleColor[] colors = new ConsoleColor[] | |
{ | |
ConsoleColor.Red, ConsoleColor.Yellow, ConsoleColor.Green, | |
ConsoleColor.Cyan, ConsoleColor.Blue, ConsoleColor.Magenta | |
}; | |
int frame = 0; | |
int maxRadiusY = centerY - 1; | |
int maxRadiusX = Math.Min(centerX * 2, width - 2); | |
while (!Console.KeyAvailable) | |
{ | |
Console.Clear(); | |
// Draw the pinwheel | |
for (int radius = 1; radius <= maxRadiusY; radius++) | |
{ | |
for (int angle = 0; angle < 360; angle += 15) | |
{ | |
double radians = angle * Math.PI / 180; | |
// Make x calculations twice as wide | |
int x = centerX + (int)((radius * 2) * Math.Cos(radians)); | |
int y = centerY + (int)(radius * Math.Sin(radians)); | |
// Skip if outside console bounds | |
if (x < 0 || x >= width || y < 0 || y >= height) | |
continue; | |
// Determine character and color based on angle and animation frame | |
int charIndex = (angle / 90 + frame) % pinwheelChars.Length; | |
int colorIndex = (radius + frame) % colors.Length; | |
Console.SetCursorPosition(x, y); | |
Console.ForegroundColor = colors[colorIndex]; | |
Console.Write(pinwheelChars[charIndex]); | |
} | |
} | |
Thread.Sleep(100); | |
frame = (frame + 1) % 4; | |
} | |
// Reset console state | |
Console.ResetColor(); | |
Console.Clear(); | |
Console.CursorVisible = true; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pinwheel.mov