Compare commits

..

No commits in common. "346a4fd72067e10fa83fc5a0ab6d5297a3cfb599" and "1d93c22a73510f933ace9d11eda0886b70ff3e77" have entirely different histories.

8 changed files with 12 additions and 126 deletions

View File

@ -1,114 +0,0 @@
//! Cartesian coordinate system example
//!
//! This example draws a cartesian coordinate system with X and Y axes,
//! labeled axis endpoints, and 4 labeled points (one in each quadrant).
use macroquad::prelude::*;
use turtle_lib::*;
#[turtle_main("Cartesian Axes")]
fn draw(turtle: &mut TurtlePlan) {
const AXIS_LENGTH: f32 = 250.0;
const GRID_STEP: f32 = 50.0;
const FONT_SIZE: i32 = 16;
const SMALL_FONT: i32 = 24;
// Draw coordinate system center and axes
turtle
.reset()
.set_speed(1100)
.pen_up()
.go_to(vec2(0.0, 0.0))
.pen_down();
// Draw X axis (horizontal)
turtle.set_pen_color(macroquad::prelude::BLACK);
turtle.set_pen_width(2.0);
turtle.pen_up().go_to(vec2(-AXIS_LENGTH, 0.0)).pen_down();
turtle.forward(2.0 * AXIS_LENGTH);
// Draw Y axis (vertical)
turtle.pen_up().go_to(vec2(0.0, -AXIS_LENGTH)).pen_down();
turtle.set_heading(90.0);
turtle.forward(2.0 * AXIS_LENGTH);
// Draw axis tick marks (major and minor)
turtle.set_pen_width(1.0);
const MINOR_STEP: f32 = GRID_STEP / 10.0; // 1/10th markers
let mut pos = -AXIS_LENGTH;
while pos <= AXIS_LENGTH {
if (pos - 0.0).abs() > 1.0 {
// Skip origin
// Determine if this is a major or minor tick
let is_major = (pos / GRID_STEP).abs().fract() < 0.01;
let tick_length = if is_major { 10.0 } else { 5.0 };
// X axis tick
turtle
.pen_up()
.set_pen_width(tick_length / 5.0)
.go_to(vec2(pos, -tick_length / 2.0))
.pen_down()
.set_heading(90.0)
.forward(tick_length);
// Y axis tick
turtle
.pen_up()
.go_to(vec2(-tick_length / 2.0, pos))
.set_pen_width(tick_length / 5.0)
.pen_down()
.set_heading(0.0)
.forward(tick_length);
}
pos += MINOR_STEP;
}
// Label axes
turtle
.pen_up()
.go_to(vec2(AXIS_LENGTH + 20.0, 0.0))
.set_heading(0.0)
.write_text("X", FONT_SIZE);
turtle
.pen_up()
.go_to(vec2(0.0, AXIS_LENGTH + 20.0))
.set_heading(0.0)
.write_text("Y", FONT_SIZE);
// Draw and label 4 points (one per quadrant)
let points = vec![
(vec2(120.0, 100.0), "A(2|1)"),
(vec2(-120.0, 100.0), "B(-2|1)"),
(vec2(-120.0, -100.0), "C(-2|-1)"),
(vec2(120.0, -100.0), "D(2|-1)"),
];
for (position, label) in points {
// Draw point as small circle
turtle
.pen_up()
.go_to(position)
.set_pen_color(macroquad::prelude::RED)
.set_pen_width(7.0)
.pen_down()
.forward(1.0); // Just a small mark
// Add label
let label_offset = vec2(label.len() as f32 * 2.5, 0.0);
turtle
.pen_up()
.go_to(position - label_offset)
.set_heading(0.0)
.write_text(label, SMALL_FONT);
}
// Label origin
turtle
.pen_up()
.go_to(vec2(-30.0, -20.0))
.set_heading(0.0)
.write_text("O", FONT_SIZE);
}

View File

@ -35,7 +35,7 @@ async fn main() {
// Draw triangular hole in the middle // Draw triangular hole in the middle
println!("Drawing triangular hole..."); println!("Drawing triangular hole...");
turtle.go_to(vec2(200.0, -120.0)); turtle.go_to(vec2(200.0, 120.0));
turtle.pen_down(); // Start new contour for hole turtle.pen_down(); // Start new contour for hole
for _ in 0..3 { for _ in 0..3 {
@ -48,7 +48,7 @@ async fn main() {
// Draw circular hole (top-left) using circle_left // Draw circular hole (top-left) using circle_left
println!("Drawing circular hole (top-left) with circle_left..."); println!("Drawing circular hole (top-left) with circle_left...");
turtle.go_to(vec2(100.0, -100.0)); turtle.go_to(vec2(100.0, 100.0));
turtle.pen_down(); // Start new contour for hole turtle.pen_down(); // Start new contour for hole
turtle.circle_left(30.0, 360.0, 36); // radius=30, full circle, 36 steps turtle.circle_left(30.0, 360.0, 36); // radius=30, full circle, 36 steps
println!("Closing circle contour with pen_up"); println!("Closing circle contour with pen_up");
@ -56,7 +56,7 @@ async fn main() {
// Draw circular hole (bottom-right) using circle_right // Draw circular hole (bottom-right) using circle_right
println!("Drawing circular hole (bottom-right) with circle_right..."); println!("Drawing circular hole (bottom-right) with circle_right...");
turtle.go_to(vec2(280.0, -280.0)); turtle.go_to(vec2(280.0, 280.0));
turtle.pen_down(); // Start new contour for hole turtle.pen_down(); // Start new contour for hole
turtle.circle_right(40.0, 360.0, 36); // radius=40, full circle, 36 steps turtle.circle_right(40.0, 360.0, 36); // radius=40, full circle, 36 steps
println!("Closing circle contour with pen_up"); println!("Closing circle contour with pen_up");

View File

@ -28,7 +28,7 @@ fn draw_cheese(turtle: &mut TurtlePlan) {
// Draw triangular hole in the middle // Draw triangular hole in the middle
println!("Drawing triangular hole..."); println!("Drawing triangular hole...");
turtle.go_to(vec2(200.0, -120.0)); turtle.go_to(vec2(200.0, 120.0));
turtle.pen_down(); // Start new contour for hole turtle.pen_down(); // Start new contour for hole
for _ in 0..3 { for _ in 0..3 {
@ -41,7 +41,7 @@ fn draw_cheese(turtle: &mut TurtlePlan) {
// Draw circular hole (top-left) using circle_left // Draw circular hole (top-left) using circle_left
println!("Drawing circular hole (top-left) with circle_left..."); println!("Drawing circular hole (top-left) with circle_left...");
turtle.go_to(vec2(100.0, -100.0)); turtle.go_to(vec2(100.0, 100.0));
turtle.pen_down(); // Start new contour for hole turtle.pen_down(); // Start new contour for hole
turtle.circle_left(30.0, 360.0, 36); // radius=30, full circle, 36 steps turtle.circle_left(30.0, 360.0, 36); // radius=30, full circle, 36 steps
println!("Closing circle contour with pen_up"); println!("Closing circle contour with pen_up");
@ -49,7 +49,7 @@ fn draw_cheese(turtle: &mut TurtlePlan) {
// Draw circular hole (bottom-right) using circle_right // Draw circular hole (bottom-right) using circle_right
println!("Drawing circular hole (bottom-right) with circle_right..."); println!("Drawing circular hole (bottom-right) with circle_right...");
turtle.go_to(vec2(280.0, -280.0)); turtle.go_to(vec2(280.0, 280.0));
turtle.pen_down(); // Start new contour for hole turtle.pen_down(); // Start new contour for hole
turtle.circle_right(40.0, 360.0, 36); // radius=40, full circle, 36 steps turtle.circle_right(40.0, 360.0, 36); // radius=40, full circle, 36 steps
println!("Closing circle contour with pen_up"); println!("Closing circle contour with pen_up");

View File

@ -83,6 +83,8 @@ fn run_game_logic(
smiley_tx.send(plan.build()).ok(); smiley_tx.send(plan.build()).ok();
} }
draw_smiley(&smiley_tx, true);
// Setup: Position hangman turtle and draw base (hill) // Setup: Position hangman turtle and draw base (hill)
{ {
let mut plan = create_turtle_plan(); let mut plan = create_turtle_plan();

View File

@ -90,7 +90,7 @@ fn sierpinski_triangle_auto(turtle: &mut TurtlePlan, level: u8) {
let size = TRIANGLE_SIZE; let size = TRIANGLE_SIZE;
turtle.pen_up(); turtle.pen_up();
turtle.go_to((-screen_width() / 2.0 + 20.0, -screen_height() / 2.0 + 20.0)); turtle.go_to((-screen_width() / 2.0 + 20.0, screen_height() / 2.0 - 20.0));
turtle.set_heading(0.0); // 0 = East (pointing right) turtle.set_heading(0.0); // 0 = East (pointing right)
// The drawing itself. // The drawing itself.

View File

@ -615,7 +615,7 @@ impl TurtlePlan {
/// Coordinates are in screen space: /// Coordinates are in screen space:
/// - `(0, 0)` is at the center /// - `(0, 0)` is at the center
/// - Positive x goes right /// - Positive x goes right
/// - Positive y goes up /// - Positive y goes down
/// ///
/// # Examples /// # Examples
/// ///

View File

@ -247,8 +247,7 @@ pub fn execute_command(command: &TurtleCommand, state: &mut Turtle) {
TurtleCommand::Goto(coord) => { TurtleCommand::Goto(coord) => {
let start = state.params.position; let start = state.params.position;
// Flip Y coordinate: turtle graphics uses Y+ = up, but Macroquad uses Y+ = down state.params.position = *coord;
state.params.position = vec2(coord.x, -coord.y);
if state.params.pen_down { if state.params.pen_down {
// Draw line segment with round caps // Draw line segment with round caps

View File

@ -400,8 +400,7 @@ impl TweenController {
}); });
} }
TurtleCommand::Goto(coord) => { TurtleCommand::Goto(coord) => {
// Flip Y coordinate: turtle graphics uses Y+ = up, but Macroquad uses Y+ = down target.position = *coord;
target.position = vec2(coord.x, -coord.y);
} }
TurtleCommand::SetHeading(heading) => { TurtleCommand::SetHeading(heading) => {
target.heading = normalize_angle(*heading); target.heading = normalize_angle(*heading);