Initial macroquad version for compiletime reasons

```rust
// Movement
plan.forward(100);
plan.backward(50);

// Rotation
plan.left(90);    // degrees
plan.right(45);

// Circular arcs
plan.circle_left(50.0, 180.0, 36);   // radius, angle (degrees), segments
plan.circle_right(50.0, 180.0, 36);  // draws arc to the right

// Pen control
plan.pen_up();
plan.pen_down();

// Appearance
plan.set_color(RED);
plan.set_pen_width(5.0);
plan.hide();
plan.show();

// Turtle shape
plan.shape(ShapeType::Triangle);
plan.shape(ShapeType::Turtle);    // Default classic turtle shape
plan.shape(ShapeType::Circle);
plan.shape(ShapeType::Square);
plan.shape(ShapeType::Arrow);

// Custom shape
let custom = TurtleShape::new(
    vec![vec2(10.0, 0.0), vec2(-5.0, 5.0), vec2(-5.0, -5.0)],
    true  // filled
);
plan.set_shape(custom);

// Chaining
plan.forward(100).right(90).forward(50);
```
This commit is contained in:
2025-10-09 09:12:16 +02:00
parent 9ab58e39e7
commit 25753b47ce
25 changed files with 2941 additions and 2 deletions
@@ -0,0 +1,41 @@
//! Test circle_left and circle_right commands
use macroquad::prelude::*;
use turtle_lib_macroquad::*;
#[macroquad::main("Circle Test")]
async fn main() {
// Create a turtle plan
let mut plan = create_turtle();
plan.shape(ShapeType::Turtle);
// Draw some circles
plan.set_color(RED);
plan.set_pen_width(0.5);
plan.left(90.0);
plan.circle_left(100.0, 540.0, 72); // partial circle to the left
plan.forward(150.0);
plan.set_color(BLUE);
plan.circle_right(50.0, 270.0, 72); // partial circle to the right
plan.forward(150.0);
plan.set_color(GREEN);
plan.circle_left(50.0, 180.0, 36); // Half circle to the left
// Create turtle app with animation (speed = 100 pixels/sec)
let mut app = TurtleApp::new().with_commands(plan.build(), 100.0);
// Main loop
loop {
clear_background(WHITE);
// Update and render
app.update();
app.render();
next_frame().await
}
}
@@ -0,0 +1,30 @@
//! Test circle_left and circle_right commands
use macroquad::prelude::*;
use turtle_lib_macroquad::*;
#[macroquad::main("Circle Test")]
async fn main() {
// Create a turtle plan
let mut plan = create_turtle();
plan.right(45.0);
plan.forward(100.0);
plan.right(45.0);
plan.forward(100.0);
//plan.circle_left(100.0, 90.0, 72); // Full circle to the left
// Create turtle app with animation (speed = 100 pixels/sec)
let mut app = TurtleApp::new().with_commands(plan.build(), 10.0);
// Main loop
loop {
clear_background(WHITE);
// Update and render
app.update();
app.render();
next_frame().await
}
}
+49
View File
@@ -0,0 +1,49 @@
//! Koch snowflake fractal example
use macroquad::prelude::*;
use turtle_lib_macroquad::*;
fn koch(depth: u32, plan: &mut TurtlePlan, distance: f32) {
if depth == 0 {
plan.forward(distance);
} else {
let new_distance = distance / 3.0;
koch(depth - 1, plan, new_distance);
plan.left(60.0);
koch(depth - 1, plan, new_distance);
plan.right(120.0);
koch(depth - 1, plan, new_distance);
plan.left(60.0);
koch(depth - 1, plan, new_distance);
}
}
#[macroquad::main("Koch Snowflake")]
async fn main() {
let mut plan = create_turtle();
// Position turtle
plan.set_speed(10);
plan.pen_up();
plan.backward(150.0);
plan.pen_down();
// Draw Koch snowflake (triangle of Koch curves)
for _ in 0..3 {
koch(4, &mut plan, 300.0);
plan.right(120.0);
}
plan.hide(); // Hide turtle when done
// Create app with animation
let mut app = TurtleApp::new().with_commands(plan.build(), 1000.0);
loop {
clear_background(WHITE);
app.update();
app.render();
next_frame().await
}
}
+74
View File
@@ -0,0 +1,74 @@
//! Nikolaus example - draws a house-like figure
use macroquad::prelude::*;
use turtle_lib_macroquad::*;
fn nikolausquadrat(plan: &mut TurtlePlan, groesse: f32) {
plan.forward(groesse);
plan.left(90.0);
plan.forward(groesse);
plan.left(90.0);
plan.forward(groesse);
plan.left(90.0);
plan.forward(groesse);
plan.left(90.0);
}
fn nikolausdiag(plan: &mut TurtlePlan, groesse: f32) {
let quadrat = groesse * groesse;
let diag = (quadrat + quadrat).sqrt();
plan.left(45.0);
plan.forward(diag);
plan.left(45.0);
nikolausdach2(plan, groesse);
plan.left(45.0);
plan.forward(diag);
plan.left(45.0);
}
fn nikolausdach2(plan: &mut TurtlePlan, groesse: f32) {
let quadrat = groesse * groesse;
let diag = (quadrat + quadrat).sqrt();
plan.left(45.0);
plan.forward(diag / 2.0);
plan.left(90.0);
plan.forward(diag / 2.0);
plan.left(45.0);
}
fn nikolaus(plan: &mut TurtlePlan, groesse: f32) {
nikolausquadrat(plan, groesse);
nikolausdiag(plan, groesse);
}
#[macroquad::main("Nikolaus")]
async fn main() {
// Create a turtle plan
let mut plan = create_turtle();
plan.shape(ShapeType::Turtle);
// Position the turtle (pen up, move, pen down)
plan.pen_up();
plan.backward(80.0);
plan.left(90.0);
plan.forward(50.0);
plan.right(90.0);
plan.pen_down();
nikolaus(&mut plan, 100.0);
// Create turtle app with animation (speed = 100 pixels/sec)
let mut app = TurtleApp::new().with_commands(plan.build(), 100.0);
// Main loop
loop {
clear_background(WHITE);
// Update and render
app.update();
app.render();
next_frame().await
}
}
+47
View File
@@ -0,0 +1,47 @@
//! Example demonstrating different turtle shapes
use macroquad::prelude::*;
use turtle_lib_macroquad::*;
#[macroquad::main("Turtle Shapes")]
async fn main() {
// Create a turtle plan that demonstrates different shapes
let mut plan = create_turtle();
// Start with triangle (default)
plan.forward(100.0);
plan.right(90.0);
// Change to turtle shape
plan.shape(ShapeType::Turtle);
plan.forward(100.0);
plan.right(90.0);
// Change to circle
plan.shape(ShapeType::Circle);
plan.forward(100.0);
plan.right(90.0);
// Change to square
plan.shape(ShapeType::Square);
plan.forward(100.0);
plan.right(90.0);
// Change to arrow
plan.shape(ShapeType::Arrow);
plan.forward(100.0);
// Create turtle app with animation (speed = 100 pixels/sec for slower animation)
let mut app = TurtleApp::new().with_commands(plan.build(), 700.0);
// Main loop
loop {
clear_background(WHITE);
// Update and render
app.update();
app.render();
next_frame().await
}
}
+30
View File
@@ -0,0 +1,30 @@
//! Simple square example demonstrating basic turtle graphics
use macroquad::prelude::*;
use turtle_lib_macroquad::*;
#[macroquad::main("Turtle Square")]
async fn main() {
// Create a turtle plan
let mut plan = create_turtle();
plan.shape(ShapeType::Turtle);
// Draw a square
for _ in 0..4 {
plan.forward(100.0).right(90.0);
}
// Create turtle app with animation (speed = 100 pixels/sec)
let mut app = TurtleApp::new().with_commands(plan.build(), 100.0);
// Main loop
loop {
clear_background(WHITE);
// Update and render
app.update();
app.render();
next_frame().await
}
}
+34
View File
@@ -0,0 +1,34 @@
//! Simple square example demonstrating basic turtle graphics
use macroquad::prelude::*;
use turtle_lib_macroquad::*;
#[macroquad::main("Turtle Square")]
async fn main() {
// Create a turtle plan
let mut plan = create_turtle();
plan.shape(ShapeType::Turtle);
plan.set_speed(800);
// Draw a square
for _ in 0..5 {
plan.forward(200.0);
plan.circle_left(10.0, 72.0, 1000);
plan.circle_right(5.0, 360.0, 1000);
plan.circle_left(10.0, 72.0, 1000);
}
// Create turtle app with animation (speed = 100 pixels/sec)
let mut app = TurtleApp::new().with_commands(plan.build(), 100.0);
// Main loop
loop {
clear_background(WHITE);
// Update and render
app.update();
app.render();
next_frame().await
}
}
+41
View File
@@ -0,0 +1,41 @@
//! Simple square example demonstrating basic turtle graphics
use macroquad::prelude::*;
use turtle_lib_macroquad::*;
#[macroquad::main("Turtle Square")]
async fn main() {
// Create a turtle plan
let mut t = create_turtle();
t.circle_left(90.0, 180.0, 36);
t.circle_left(90.0, 180.0, 36);
t.circle_left(45.0, 180.0, 26);
t.circle_right(45.0, 180.0, 26);
t.pen_up();
t.right(90.0);
t.forward(37.0);
t.left(90.0);
t.pen_down();
t.circle_right(8.0, 360.0, 12);
t.pen_up();
t.right(90.0);
t.forward(90.0);
t.left(90.0);
t.pen_down();
t.circle_right(8.0, 360.0, 12);
// Create turtle app with animation (speed = 100 pixels/sec)
let mut app = TurtleApp::new().with_commands(t.build(), 100.0);
// Main loop
loop {
clear_background(WHITE);
// Update and render
app.update();
app.render();
next_frame().await
}
}