updated examples for simpler interface

This commit is contained in:
Dietrich 2022-12-21 11:08:04 +01:00 committed by Franz Dietrich
parent 8686c81c00
commit 85f32250b1
3 changed files with 55 additions and 27 deletions

View File

@ -23,32 +23,22 @@ fn setup(mut commands: Commands) {
let mut turtle = get_a_turtle(); let mut turtle = get_a_turtle();
turtle.set_speed(1); turtle.set_speed(1);
for _x in 0..3 { for _x in 0..3 {
koch(4, &mut turtle); koch(3, &mut turtle);
let mut left = turtle.create_plan(); turtle.right(120);
left.right(120);
turtle.extend_plan(left);
} }
commands.spawn((turtle, Egon {})); commands.spawn((turtle, Egon {}));
} }
fn koch(depth: u32, turtle: &mut AnimatedTurtle) { fn koch(depth: u32, turtle: &mut AnimatedTurtle) {
if depth == 0 { if depth == 0 {
let mut forward = turtle.create_plan(); turtle.forward(10);
forward.forward(10);
turtle.extend_plan(forward)
} else { } else {
koch(depth - 1, turtle); koch(depth - 1, turtle);
let mut left = turtle.create_plan(); turtle.left(60);
left.left(60);
turtle.extend_plan(left);
koch(depth - 1, turtle); koch(depth - 1, turtle);
let mut right = turtle.create_plan(); turtle.right(120);
right.right(120);
turtle.extend_plan(right);
koch(depth - 1, turtle); koch(depth - 1, turtle);
let mut left = turtle.create_plan(); turtle.left(60);
left.left(60);
turtle.extend_plan(left);
koch(depth - 1, turtle); koch(depth - 1, turtle);
} }
} }

36
examples/stern.rs Normal file
View File

@ -0,0 +1,36 @@
use bevy::prelude::*;
use bevy_inspector_egui::Inspectable;
use turtle_lib::builders::{CurvedMovement, DirectionalMovement};
use turtle_lib::turtle_bundle::AnimatedTurtle;
use turtle_lib::{get_a_turtle, TurtlePlugin};
use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
#[derive(Component, Inspectable)]
struct Egon {}
fn main() {
App::new()
.add_plugin(TurtlePlugin)
.add_startup_system(setup)
//.add_system(plan)
.add_plugin(LogDiagnosticsPlugin::default())
.add_plugin(FrameTimeDiagnosticsPlugin::default())
.run();
}
fn setup(mut commands: Commands) {
let mut turtle = get_a_turtle();
turtle.set_speed(500);
stern(&mut turtle);
commands.spawn((turtle, Egon {}));
}
fn stern(turtle: &mut AnimatedTurtle) {
for _ in 0..5 {
turtle.forward(200);
turtle.circle(10, 72);
turtle.circle_right(5, 360);
turtle.circle(10, 72);
}
}

View File

@ -1,6 +1,6 @@
use bevy::prelude::*; use bevy::prelude::*;
use bevy_inspector_egui::Inspectable; use bevy_inspector_egui::Inspectable;
use turtle_lib::builders::Turnable; use turtle_lib::builders::{CurvedMovement, DirectionalMovement, Turnable};
use turtle_lib::{get_a_turtle, TurtlePlugin}; use turtle_lib::{get_a_turtle, TurtlePlugin};
use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}; use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
@ -20,17 +20,19 @@ fn main() {
fn setup(mut commands: Commands) { fn setup(mut commands: Commands) {
let mut turtle = get_a_turtle(); let mut turtle = get_a_turtle();
let mut p = turtle.create_plan(); turtle.set_speed(1000);
turtle.circle(50, 90);
turtle.circle_right(50, 180);
turtle.circle(50, 90);
for x in 0..1999 { for x in 0..1999 {
p.forward(x.into()); turtle.forward(x);
p.right(45.into()); turtle.right(45);
p.forward(30.into()); turtle.forward(30);
p.left((90 + x).into()); turtle.left(90 + x);
p.forward(30.into()); turtle.forward(30);
p.right(45.into()); turtle.right(45);
p.forward(x.into()); turtle.forward(x);
p.left(91.into()); turtle.left(91);
} }
turtle.apply_plan(p);
commands.spawn((turtle, Egon {})); commands.spawn((turtle, Egon {}));
} }