HTLLeonding.Utility.Turtle 1.1.2

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package HTLLeonding.Utility.Turtle --version 1.1.2                
NuGet\Install-Package HTLLeonding.Utility.Turtle -Version 1.1.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HTLLeonding.Utility.Turtle" Version="1.1.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HTLLeonding.Utility.Turtle --version 1.1.2                
#r "nuget: HTLLeonding.Utility.Turtle, 1.1.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install HTLLeonding.Utility.Turtle as a Cake Addin
#addin nuget:?package=HTLLeonding.Utility.Turtle&version=1.1.2

// Install HTLLeonding.Utility.Turtle as a Cake Tool
#tool nuget:?package=HTLLeonding.Utility.Turtle&version=1.1.2                

LeoTurtle

Allows students to control a turtle, which can primarily only move forward and turn. This turtle leaves track in the sand, and by looking at this track they can draw simple shapes.

Screenshot

Turtle

The Turtle has the following capabilities:

  • Can move forward a certain distance in meters
    • While moving forward, a line is drawn
  • Can turn in degrees euler
    • Positive values turn right
    • Negative values turn left
  • Can teleport itself to a specific position
    • No line is drawn when teleporting
  • Knows how many meters it has traveled
  • Will stay within the boundaries of the 'beach'

Smart Turtle

The SmartTurtle went to HTL Leonding and thus became the smarter cousin of Turtle with the following additional capabilities:

  • Knows where it is and can report its current position
  • Can look at a certain point on the beach
    • ⇒ turns to face that point automatically

Sample Usage

using LeoTurtle;

const int Length = 100;
const int Width = 80;
const string Basic = "1";
const string Smart = "2";

Console.Write($"Run Basic ({Basic}) or Smart ({Smart}) demo? ");
var choice = Console.ReadLine();
switch (choice)
{
    case Basic:
    {
        Beach.Prepare<Turtle>(WalkPath, Length, Width);
        break;
    }
    case Smart:
    {
        Beach.Prepare<SmartTurtle>(WalkSmartPath, Length, Width);
        break;
    }
    default:
    {
        Console.WriteLine("Unknown option");
        break;
    }
}

return;

static void WalkPath(Turtle turtle)
{
    turtle.Teleport(10, 5);
    turtle.MoveForward(30);
    turtle.Turn(180);
    turtle.MoveForward(15);
    turtle.Turn(-90);
    turtle.MoveForward(15);
    turtle.Turn(-90);
    turtle.MoveForward(15);
    turtle.Turn(180);
    turtle.MoveForward(30);
    
    turtle.Teleport(30, 35);
    turtle.Turn(90);
    turtle.MoveForward(15);
    turtle.Turn(180);
    turtle.MoveForward(15/2D);
    turtle.Turn(-90);
    turtle.MoveForward(30);
    
    turtle.Teleport(50, 35, false);
    turtle.MoveForward(30);
    turtle.Turn(-90);
    turtle.MoveForward(15);
}

static void WalkSmartPath(SmartTurtle turtle)
{
    const double Distance = 23.41;
    var center = new Point(Length / 2D, Width / 2D);
    var starPoint1 = GetPointByOffset(center, 0, 30);
    var starPoint2 = GetPointByOffset(center, 8, 8);
    var starPoint3 = GetPointByOffset(center, 30, 0);
    var starPoint4 = GetPointByOffset(center, 8, -8);
    var starPoint5 = GetPointByOffset(center, 0, -30);
    var starPoint6 = GetPointByOffset(center, -8, -8);
    var starPoint7 = GetPointByOffset(center, -30, 0);
    var starPoint8 = GetPointByOffset(center, -8, 8);
    
    turtle.Teleport(starPoint1.X, starPoint1.Y, resetRotation: true);
    turtle.LookAt(starPoint2.X, starPoint2.Y);
    turtle.MoveForward(Distance);
    turtle.LookAt(starPoint3.X, starPoint3.Y);
    turtle.MoveForward(Distance);
    turtle.LookAt(starPoint4.X, starPoint4.Y);
    turtle.MoveForward(Distance);
    turtle.LookAt(starPoint5.X, starPoint5.Y);
    turtle.MoveForward(Distance);
    turtle.LookAt(starPoint6.X, starPoint6.Y);
    turtle.MoveForward(Distance);
    turtle.LookAt(starPoint7.X, starPoint7.Y);
    turtle.MoveForward(Distance);
    turtle.LookAt(starPoint8.X, starPoint8.Y);
    turtle.MoveForward(Distance);
    turtle.LookAt(starPoint1.X, starPoint1.Y);
    turtle.MoveForward(Distance);
    
    Console.WriteLine($"Turtle has moved: {turtle.TravelDistanceMeters:F1} meters");

    static Point GetPointByOffset(Point origin, double xOffset, double yOffset) 
        => new(origin.X + xOffset, origin.Y + yOffset);
}

readonly record struct Point(double X, double Y);

I recommend providing the Beach.Prepare<T> call for the students and only letting them work within a method similar to WalkPath (from which they may call other methods, of course).

License

  • The source code is licensed under the MIT License.
  • The turtle images are licensed under CC BY-SA 3.0 and CC BY-SA 4.0.

See LICENSE for more information.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.4 126 9/26/2024
1.1.3 82 9/26/2024
1.1.2 88 9/26/2024
1.1.1 84 9/26/2024
1.1.0 123 9/5/2024
1.0.1 119 8/22/2024
1.0.0 109 8/22/2024