diff --git a/87 3-D Plot/csharp/Plot.sln b/87 3-D Plot/csharp/Plot.sln new file mode 100644 index 00000000..1402bc2a --- /dev/null +++ b/87 3-D Plot/csharp/Plot.sln @@ -0,0 +1,34 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26124.0 +MinimumVisualStudioVersion = 15.0.26124.0 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plot", "Plot\Plot.csproj", "{8857AE83-F481-43B0-AA51-D78E1340BD93}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8857AE83-F481-43B0-AA51-D78E1340BD93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8857AE83-F481-43B0-AA51-D78E1340BD93}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8857AE83-F481-43B0-AA51-D78E1340BD93}.Debug|x64.ActiveCfg = Debug|Any CPU + {8857AE83-F481-43B0-AA51-D78E1340BD93}.Debug|x64.Build.0 = Debug|Any CPU + {8857AE83-F481-43B0-AA51-D78E1340BD93}.Debug|x86.ActiveCfg = Debug|Any CPU + {8857AE83-F481-43B0-AA51-D78E1340BD93}.Debug|x86.Build.0 = Debug|Any CPU + {8857AE83-F481-43B0-AA51-D78E1340BD93}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8857AE83-F481-43B0-AA51-D78E1340BD93}.Release|Any CPU.Build.0 = Release|Any CPU + {8857AE83-F481-43B0-AA51-D78E1340BD93}.Release|x64.ActiveCfg = Release|Any CPU + {8857AE83-F481-43B0-AA51-D78E1340BD93}.Release|x64.Build.0 = Release|Any CPU + {8857AE83-F481-43B0-AA51-D78E1340BD93}.Release|x86.ActiveCfg = Release|Any CPU + {8857AE83-F481-43B0-AA51-D78E1340BD93}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/87 3-D Plot/csharp/Plot/Function.cs b/87 3-D Plot/csharp/Plot/Function.cs new file mode 100644 index 00000000..3a459d4e --- /dev/null +++ b/87 3-D Plot/csharp/Plot/Function.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; + +namespace Plot +{ + internal static class Function + { + internal static IEnumerable> GetRows() + { + for (var x = -30f; x <= 30f; x += 1.5f) + { + yield return GetValues(x); + } + } + + private static IEnumerable GetValues(float x) + { + var zPrevious = 0; + var yLimit = 5 * (int)(Math.Sqrt(900 - x * x) / 5); + + for (var y = yLimit; y >= -yLimit; y -= 5) + { + var z = GetValue(x, y); + + if (z > zPrevious) + { + zPrevious = z; + yield return z; + } + } + } + + private static int GetValue(float x, float y) + { + var r = (float)Math.Sqrt(x * x + y * y); + return (int)(25 + 30 * Math.Exp(-r * r / 100) - 0.7f * y); + } + } +} diff --git a/87 3-D Plot/csharp/Plot/Plot.csproj b/87 3-D Plot/csharp/Plot/Plot.csproj new file mode 100644 index 00000000..20827042 --- /dev/null +++ b/87 3-D Plot/csharp/Plot/Plot.csproj @@ -0,0 +1,8 @@ + + + + Exe + net5.0 + + + diff --git a/87 3-D Plot/csharp/Plot/Program.cs b/87 3-D Plot/csharp/Plot/Program.cs new file mode 100644 index 00000000..132c41ef --- /dev/null +++ b/87 3-D Plot/csharp/Plot/Program.cs @@ -0,0 +1,38 @@ +using System; + +namespace Plot +{ + class Program + { + static void Main(string[] args) + { + PrintTitle(); + + foreach (var row in Function.GetRows()) + { + foreach (var z in row) + { + Plot(z); + } + Console.WriteLine(); + } + } + + private static void PrintTitle() + { + Console.WriteLine(" 3D Plot"); + Console.WriteLine(" Creative Computing Morristown, New Jersey"); + Console.WriteLine(); + Console.WriteLine(); + Console.WriteLine(); + Console.WriteLine(); + } + + private static void Plot(int z) + { + var x = Console.GetCursorPosition().Top; + Console.SetCursorPosition(z, x); + Console.Write("*"); + } + } +}