Skip to content

Instantly share code, notes, and snippets.

@Htbaa
Created October 26, 2011 10:21
Show Gist options
  • Save Htbaa/1315970 to your computer and use it in GitHub Desktop.
Save Htbaa/1315970 to your computer and use it in GitHub Desktop.
Drawing a sinus with Console.WriteLine
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