mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-30 14:42:03 -08:00
Removed spaces from top-level directory names.
Spaces tend to cause annoyances in a Unix-style shell environment. This change fixes that.
This commit is contained in:
39
87_3-D_Plot/csharp/Plot/Function.cs
Normal file
39
87_3-D_Plot/csharp/Plot/Function.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Plot
|
||||
{
|
||||
internal static class Function
|
||||
{
|
||||
internal static IEnumerable<IEnumerable<int>> GetRows()
|
||||
{
|
||||
for (var x = -30f; x <= 30f; x += 1.5f)
|
||||
{
|
||||
yield return GetValues(x);
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<int> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
8
87_3-D_Plot/csharp/Plot/Plot.csproj
Normal file
8
87_3-D_Plot/csharp/Plot/Plot.csproj
Normal file
@@ -0,0 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
38
87_3-D_Plot/csharp/Plot/Program.cs
Normal file
38
87_3-D_Plot/csharp/Plot/Program.cs
Normal file
@@ -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("*");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user