Created
October 6, 2019 17:40
-
-
Save peterthorsteinson/0c9e7c3e3a733444727e8be9f9275d97 to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Threading; | |
namespace PlotCircle | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int radius = 50; | |
for (int i=0; i<120; i++) | |
{ | |
double theta =2*Math.PI*(i/120.0); // 0.0 -> 2*Math.PI | |
double cos = Math.Cos(theta); // -1.0 -> +1.0 | |
double sin = Math.Sin(theta); // -1.0 -> +1.0 | |
int x = (int)(radius * (1 + cos)); // 0 -> 100 | |
int y = (int)(radius/2.0 * (1 + sin)); // 0 -> 50 (divide by 2 because character box is not square | |
PlotPoint(x, y, '*'); | |
Thread.Sleep(50); // delay 1/20 second to see the sequence in plotting output | |
} | |
Console.ReadKey(true); | |
} | |
protected static void PlotPoint(int x, int y, char c) | |
{ | |
try | |
{ | |
Console.SetCursorPosition(x, y); | |
Console.Write(c); | |
} | |
catch (ArgumentOutOfRangeException e) | |
{ | |
Console.WriteLine(e.Message); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment