Skip to content

Commit

Permalink
Merge pull request #5 from Vincexodus/main
Browse files Browse the repository at this point in the history
`hello_example` for crate
  • Loading branch information
nixon-voxell authored Jun 10, 2024
2 parents 539b2b3 + 7072c19 commit c215227
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
61 changes: 61 additions & 0 deletions examples/hello_world.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use bevy::{math::DVec2, prelude::*};
use bevy_vello_graphics::prelude::*;

fn main() {
App::new()
// Bevy plugins
.add_plugins(DefaultPlugins)
// Custom Plugins
.add_plugins(VelloGraphicsPlugin)
.add_systems(Startup, (setup, render_shapes))
.run();
}

fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
}

fn render_shapes(mut commands: Commands) {
// Line
let line = (
VelloLine::new(DVec2::new(0.0, 100.0), DVec2::new(0.0, -100.0)),
Stroke::new(5.0).with_color(Color::WHITE),
Transform::from_xyz(-300.0, 0.0, 0.0),
);

// Rectangle
let rect = (
VelloRect::new(100.0, 200.0),
Fill::new().with_color(Color::ORANGE),
Stroke::new(5.0).with_color(Color::RED),
Transform::from_xyz(-100.0, 0.0, 0.0),
);

// Circle
let circle = (
VelloCircle::new(50.0),
Fill::new().with_color(Color::YELLOW_GREEN),
Stroke::new(5.0).with_color(Color::DARK_GREEN),
Transform::from_xyz(100.0, 0.0, 0.0),
);

let mut bez_path = kurbo::BezPath::new();
bez_path.move_to((300.0, 100.0));
bez_path.curve_to((200.0, 50.0), (400.0, -50.0), (300.0, -100.0));

// Bézier Path
let bezier_path = (
VelloBezPath::new().with_path(bez_path),
Stroke::new(4.0).with_color(Color::YELLOW),
);

commands.spawn(VelloSceneBundle::default()).insert(line);

commands.spawn(VelloSceneBundle::default()).insert(rect);

commands.spawn(VelloSceneBundle::default()).insert(circle);

commands
.spawn(VelloSceneBundle::default())
.insert(bezier_path);
}
11 changes: 10 additions & 1 deletion src/bezpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bevy_vello::prelude::*;
use super::VelloVector;

/// Vello Bézier path component.
#[derive(Component, Default, Debug, Clone)]
#[derive(Component, Debug, Clone)]
pub struct VelloBezPath {
pub path: kurbo::BezPath,
pub trace: f32,
Expand All @@ -26,6 +26,15 @@ impl VelloBezPath {
}
}

impl Default for VelloBezPath {
fn default() -> Self {
Self {
path: default(),
trace: 1.0,
}
}
}

impl VelloVector for VelloBezPath {
fn shape(&self) -> impl kurbo::Shape {
let pathels = self.path.elements();
Expand Down

0 comments on commit c215227

Please sign in to comment.