Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hello_example for crate #5

Merged
merged 4 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, Clone)]
nixon-voxell marked this conversation as resolved.
Show resolved Hide resolved
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