Created
October 26, 2011 10:21
-
-
Save Htbaa/1315970 to your computer and use it in GitHub Desktop.
Drawing a sinus with Console.WriteLine
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
static void PrimitieveSinus() | |
{ | |
var positions = from x in Enumerable.Range(0,79) | |
select new { x, y = (int)(Math.Sin(x) * 2) }; | |
positions = positions.OrderBy(p => p.y).ThenBy(p => p.x); | |
var y_pos = positions.GroupBy(p => p.y).Select(p => p.Key); | |
foreach (int y in y_pos) | |
{ | |
var x_pos = positions.Where(p => p.y == y).Select(p => p.x); | |
foreach (int x in x_pos) | |
{ | |
Console.SetCursorPosition(x, Console.CursorTop); | |
Console.Write("*"); | |
} | |
Console.SetCursorPosition(0, Console.CursorTop + 1); | |
} | |
Console.SetCursorPosition(0, Console.CursorTop + 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment