mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-09 20:31:29 +11:00
Mmark example
This commit ports the mmark example from the mmark branch, and also makes the complexity adjustable through up/down arrow keys.
This commit is contained in:
parent
495229bf10
commit
f4a2fc616b
|
@ -16,6 +16,7 @@ vello_svg = { path = "../../integrations/vello_svg" }
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
clap = { workspace = true, features = ["derive"] }
|
clap = { workspace = true, features = ["derive"] }
|
||||||
image = "0.24.5"
|
image = "0.24.5"
|
||||||
|
rand = "0.8.5"
|
||||||
instant = { workspace = true }
|
instant = { workspace = true }
|
||||||
|
|
||||||
# Used for the `download` command
|
# Used for the `download` command
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
pub mod download;
|
pub mod download;
|
||||||
mod images;
|
mod images;
|
||||||
|
mod mmark;
|
||||||
mod simple_text;
|
mod simple_text;
|
||||||
mod svg;
|
mod svg;
|
||||||
mod test_scenes;
|
mod test_scenes;
|
||||||
|
@ -25,6 +26,7 @@ pub struct SceneParams<'a> {
|
||||||
pub images: &'a mut ImageCache,
|
pub images: &'a mut ImageCache,
|
||||||
pub resolution: Option<Vec2>,
|
pub resolution: Option<Vec2>,
|
||||||
pub base_color: Option<vello::peniko::Color>,
|
pub base_color: Option<vello::peniko::Color>,
|
||||||
|
pub complexity: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SceneConfig {
|
pub struct SceneConfig {
|
||||||
|
@ -34,10 +36,20 @@ pub struct SceneConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ExampleScene {
|
pub struct ExampleScene {
|
||||||
pub function: Box<dyn FnMut(&mut SceneBuilder, &mut SceneParams)>,
|
pub function: Box<dyn TestScene>,
|
||||||
pub config: SceneConfig,
|
pub config: SceneConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait TestScene {
|
||||||
|
fn render(&mut self, sb: &mut SceneBuilder, params: &mut SceneParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<F: FnMut(&mut SceneBuilder, &mut SceneParams)> TestScene for F {
|
||||||
|
fn render(&mut self, sb: &mut SceneBuilder, params: &mut SceneParams) {
|
||||||
|
self(sb, params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct SceneSet {
|
pub struct SceneSet {
|
||||||
pub scenes: Vec<ExampleScene>,
|
pub scenes: Vec<ExampleScene>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,16 @@ pub fn test_scenes() -> SceneSet {
|
||||||
},
|
},
|
||||||
function: Box::new(splash_with_tiger()),
|
function: Box::new(splash_with_tiger()),
|
||||||
};
|
};
|
||||||
|
let mmark_scene = ExampleScene {
|
||||||
|
config: SceneConfig {
|
||||||
|
animated: false,
|
||||||
|
name: "mmark".to_owned(),
|
||||||
|
},
|
||||||
|
function: Box::new(crate::mmark::MMark::new(80_000)),
|
||||||
|
};
|
||||||
let scenes = vec![
|
let scenes = vec![
|
||||||
splash_scene,
|
splash_scene,
|
||||||
|
mmark_scene,
|
||||||
scene!(funky_paths),
|
scene!(funky_paths),
|
||||||
scene!(cardioid_and_friends),
|
scene!(cardioid_and_friends),
|
||||||
scene!(animated_text: animated),
|
scene!(animated_text: animated),
|
||||||
|
|
|
@ -113,6 +113,7 @@ fn run(
|
||||||
let mut prior_position: Option<Vec2> = None;
|
let mut prior_position: Option<Vec2> = None;
|
||||||
// We allow looping left and right through the scenes, so use a signed index
|
// We allow looping left and right through the scenes, so use a signed index
|
||||||
let mut scene_ix: i32 = 0;
|
let mut scene_ix: i32 = 0;
|
||||||
|
let mut complexity: usize = 0;
|
||||||
if let Some(set_scene) = args.scene {
|
if let Some(set_scene) = args.scene {
|
||||||
scene_ix = set_scene;
|
scene_ix = set_scene;
|
||||||
}
|
}
|
||||||
|
@ -134,6 +135,8 @@ fn run(
|
||||||
match input.virtual_keycode {
|
match input.virtual_keycode {
|
||||||
Some(VirtualKeyCode::Left) => scene_ix = scene_ix.saturating_sub(1),
|
Some(VirtualKeyCode::Left) => scene_ix = scene_ix.saturating_sub(1),
|
||||||
Some(VirtualKeyCode::Right) => scene_ix = scene_ix.saturating_add(1),
|
Some(VirtualKeyCode::Right) => scene_ix = scene_ix.saturating_add(1),
|
||||||
|
Some(VirtualKeyCode::Up) => complexity += 1,
|
||||||
|
Some(VirtualKeyCode::Down) => complexity = complexity.saturating_sub(1),
|
||||||
Some(key @ VirtualKeyCode::Q) | Some(key @ VirtualKeyCode::E) => {
|
Some(key @ VirtualKeyCode::Q) | Some(key @ VirtualKeyCode::E) => {
|
||||||
if let Some(prior_position) = prior_position {
|
if let Some(prior_position) = prior_position {
|
||||||
let is_clockwise = key == VirtualKeyCode::E;
|
let is_clockwise = key == VirtualKeyCode::E;
|
||||||
|
@ -295,8 +298,9 @@ fn run(
|
||||||
resolution: None,
|
resolution: None,
|
||||||
base_color: None,
|
base_color: None,
|
||||||
interactive: true,
|
interactive: true,
|
||||||
|
complexity,
|
||||||
};
|
};
|
||||||
(example_scene.function)(&mut builder, &mut scene_params);
|
example_scene.function.render(&mut builder, &mut scene_params);
|
||||||
|
|
||||||
// If the user specifies a base color in the CLI we use that. Otherwise we use any
|
// If the user specifies a base color in the CLI we use that. Otherwise we use any
|
||||||
// color specified by the scene. The default is black.
|
// color specified by the scene. The default is black.
|
||||||
|
|
Loading…
Reference in a new issue