113 lines
2.9 KiB
C#
113 lines
2.9 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.IO;
|
|||
|
|
|||
|
using SBRL.Utilities;
|
|||
|
using SBRL.SimpleTurtle;
|
|||
|
|
|||
|
namespace SBRL.Algorithms.LSystem
|
|||
|
{
|
|||
|
class MainClass
|
|||
|
{
|
|||
|
public static void Main(string[] args)
|
|||
|
{
|
|||
|
string inputFilename = string.Empty;
|
|||
|
string outputDirectory = string.Empty;
|
|||
|
int startingGeneration = 0;
|
|||
|
int generations = 5;
|
|||
|
int stepCount = 25;
|
|||
|
|
|||
|
for (int i = 0; i < args.Length; i++)
|
|||
|
{
|
|||
|
switch (args[i].ToLower())
|
|||
|
{
|
|||
|
case "--help":
|
|||
|
Console.WriteLine(EmbeddedFiles.ReadAllText("SimpleTurtle.Help.txt"));
|
|||
|
return;
|
|||
|
|
|||
|
case "--input-file":
|
|||
|
case "-i":
|
|||
|
inputFilename = args[++i];
|
|||
|
break;
|
|||
|
case "--output-dir":
|
|||
|
case "-o":
|
|||
|
outputDirectory = args[++i];
|
|||
|
break;
|
|||
|
case "--skip-gen":
|
|||
|
case "-s":
|
|||
|
startingGeneration = int.Parse(args[++i]);
|
|||
|
break;
|
|||
|
case "--count":
|
|||
|
case "-c":
|
|||
|
generations = int.Parse(args[++i]);
|
|||
|
break;
|
|||
|
case "--step-dist":
|
|||
|
case "-d":
|
|||
|
stepCount = int.Parse(args[++i]);
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
StreamReader source;
|
|||
|
if (inputFilename == string.Empty)
|
|||
|
source = new StreamReader(Console.OpenStandardInput());
|
|||
|
else
|
|||
|
source = new StreamReader(inputFilename);
|
|||
|
|
|||
|
if (outputDirectory == string.Empty) {
|
|||
|
if (inputFilename == string.Empty)
|
|||
|
outputDirectory = "./l-system";
|
|||
|
else
|
|||
|
outputDirectory = inputFilename.Substring(0, inputFilename.LastIndexOf("."));
|
|||
|
}
|
|||
|
|
|||
|
// Normalise & create the output directory
|
|||
|
outputDirectory = outputDirectory.TrimEnd('/') + "/";
|
|||
|
if(!Directory.Exists(outputDirectory))
|
|||
|
Directory.CreateDirectory(outputDirectory);
|
|||
|
|
|||
|
LSystemEngine lsystem = LSystemEngine.FromStream(source);
|
|||
|
foreach (KeyValuePair<string, string> kvp in lsystem.Definitions)
|
|||
|
{
|
|||
|
Console.WriteLine("Setting {0} to {1}.", kvp.Key, kvp.Value);
|
|||
|
}
|
|||
|
Turtle turtle = new Turtle();
|
|||
|
|
|||
|
Timer gentimer = Timer.GetStarted(), stagetimer = Timer.GetStarted();
|
|||
|
for (int i = startingGeneration; i < generations; i++)
|
|||
|
{
|
|||
|
stagetimer.Reset(); gentimer.Reset();
|
|||
|
|
|||
|
Console.Write($"Generation {i}: ");
|
|||
|
turtle.ApplyDefinitions(lsystem.Definitions);
|
|||
|
turtle.MovementStep = stepCount;
|
|||
|
turtle.Commands(lsystem.CurrentGeneration);
|
|||
|
turtle.Draw($"{outputDirectory}lsystem_generation_{i}.png");
|
|||
|
|
|||
|
Console.Write("{0:0.000000}s draw", stagetimer.GetElapsedSeconds());
|
|||
|
stagetimer.Reset();
|
|||
|
|
|||
|
// ----------
|
|||
|
|
|||
|
lsystem.Simulate();
|
|||
|
|
|||
|
Console.Write(", {0:0.000000}s simulation", stagetimer.GetElapsedSeconds());
|
|||
|
stagetimer.Reset();
|
|||
|
|
|||
|
// ----------
|
|||
|
|
|||
|
File.WriteAllText($"{outputDirectory}lsystem_generation_{i}.txt", lsystem.CurrentGeneration);
|
|||
|
|
|||
|
Console.WriteLine(
|
|||
|
", {0:0.000000}s textoutput - {1:0.000000}s total",
|
|||
|
stagetimer.GetElapsedSeconds(),
|
|||
|
gentimer.GetElapsedSeconds()
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
//Turtle turtle = new Turtle();
|
|||
|
//turtle.Commands(Console.ReadLine());
|
|||
|
//turtle.Draw("turtleImage.png");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|