From facbfc359304eed03f22dafab56897c2bb9f136a Mon Sep 17 00:00:00 2001
From: MarcUs7i <96580944+MarcUs7i@users.noreply.github.com>
Date: Tue, 1 Oct 2024 17:42:35 +0200
Subject: [PATCH] It works, ofc.
---
SimpleDrawings/SimpleDrawings.csproj | 2 +-
SimpleDrawings/TurtlePath.cs | 67 +++++++++++++++++++++++++---
2 files changed, 61 insertions(+), 8 deletions(-)
diff --git a/SimpleDrawings/SimpleDrawings.csproj b/SimpleDrawings/SimpleDrawings.csproj
index 33f0cbe..263925f 100644
--- a/SimpleDrawings/SimpleDrawings.csproj
+++ b/SimpleDrawings/SimpleDrawings.csproj
@@ -9,7 +9,7 @@
-
+
\ No newline at end of file
diff --git a/SimpleDrawings/TurtlePath.cs b/SimpleDrawings/TurtlePath.cs
index f3fa5db..002d2bd 100644
--- a/SimpleDrawings/TurtlePath.cs
+++ b/SimpleDrawings/TurtlePath.cs
@@ -1,4 +1,5 @@
-using LeoTurtle;
+using System.Drawing;
+using LeoTurtle;
namespace SimpleDrawings;
@@ -25,7 +26,19 @@ public static class TurtlePath
const double ShortDistance = 4.24D;
const double LongDistance = 8.49D;
- // TODO
+ turtle.Teleport(5, 20);
+ for (int i = 0; i < 4; i++)
+ {
+ DrawLine(turtle, Distance, 90);
+ }
+ turtle.Turn(45);
+ DrawLine(turtle, LongDistance, -90);
+ for (int i = 0; i < 2; i++)
+ {
+ DrawLine(turtle, ShortDistance, -90);
+ }
+ DrawLine(turtle, LongDistance, 0);
+
}
///
@@ -34,7 +47,9 @@ public static class TurtlePath
/// The instance to use
private static void Shapes(Turtle turtle)
{
- // TODO
+ DrawOctagon(turtle, 5, 5);
+ DrawRhombus(turtle, 20, 5);
+ DrawTriangle(turtle, 35, 5);
}
///
@@ -45,7 +60,12 @@ public static class TurtlePath
/// Initial turtle y position when starting to draw
private static void DrawOctagon(Turtle turtle, int startX, int startY)
{
- // TODO
+ const double Distance = 4.0D;
+ turtle.Teleport(startX, startY);
+ for (int i = 0; i < 8; i++)
+ {
+ DrawLine(turtle, Distance, 45);
+ }
}
///
@@ -56,7 +76,16 @@ public static class TurtlePath
/// Initial turtle y position when starting to draw
private static void DrawRhombus(Turtle turtle, int startX, int startY)
{
- // TODO
+ const double Distance = 8.0D;
+ const double Angle1 = 82;
+ const double Angle2 = (360 - (Angle1 * 2)) / 2;
+
+ turtle.Teleport(startX + Distance / 2, startY - Distance / 2);
+ turtle.Turn(-Angle1 / 2);
+ for (int i = 0; i < 4; i++)
+ {
+ DrawLine(turtle, Distance, i % 2 == 0 ? Angle1 : Angle2);
+ }
}
///
@@ -67,7 +96,11 @@ public static class TurtlePath
/// Initial turtle y position when starting to draw
private static void DrawTriangle(Turtle turtle, int startX, int startY)
{
- // TODO
+ const double Offset = 1.5D;
+ const double ShortSide = 6.0D;
+ const double LongSide = 8.0D;
+ DrawTriangle(turtle, startX, startY, LongSide, ShortSide);
+ DrawTriangle(turtle, startX - Offset, startY - Offset*2, LongSide + Offset*(LongSide/2), ShortSide + Offset*(ShortSide/2));
}
///
@@ -81,7 +114,16 @@ public static class TurtlePath
/// Length of sides a & b
private static void DrawTriangle(Turtle turtle, double startX, double startY, double longSide, double shortSide)
{
- // TODO
+ turtle.Teleport(startX, startY);
+
+ double angle = ConvertToDegrees(Math.Asin(shortSide / longSide)); // Corrected to arcsin
+ DrawLine(turtle, longSide, 180 - angle); // Long side
+ DrawLine(turtle, shortSide, 0);
+
+ turtle.Teleport(startX, startY);
+ turtle.Turn(angle);
+ DrawLine(turtle, shortSide, 0);
+
}
///
@@ -93,4 +135,15 @@ public static class TurtlePath
{
return angleDegrees * Math.PI / 180;
}
+
+ private static double ConvertToDegrees(double angleRadians)
+ {
+ return angleRadians / Math.PI * 180;
+ }
+
+ private static void DrawLine(Turtle turtle, double distance, double rotation)
+ {
+ turtle.MoveForward(distance);
+ turtle.Turn(rotation);
+ }
}