mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-10 04:31:30 +11:00
Add a test scene that animates the base color
The test scenes can now supply their own optional base (background) color. In the with_winit example, we also allow the user to provide a base color as a CLI option. The precedence is as follows: 1. Use the color from the CLI options, if any. 2. Otherwise use the scene provided base color, if any. 3. Otherwise default to black.
This commit is contained in:
parent
3bbf108df5
commit
d72ad14059
|
@ -96,6 +96,7 @@ async fn render(mut scenes: SceneSet, index: usize, args: &Args) -> Result<()> {
|
|||
time: args.time.unwrap_or(0.),
|
||||
text: &mut text,
|
||||
resolution: None,
|
||||
base_color: None,
|
||||
};
|
||||
(example_scene.function)(&mut builder, &mut scene_params);
|
||||
builder.finish();
|
||||
|
@ -130,6 +131,7 @@ async fn render(mut scenes: SceneSet, index: usize, args: &Args) -> Result<()> {
|
|||
base_color: args
|
||||
.args
|
||||
.get_base_color()?
|
||||
.or(scene_params.base_color)
|
||||
.unwrap_or(vello::peniko::Color::BLACK),
|
||||
width,
|
||||
height,
|
||||
|
|
|
@ -19,6 +19,7 @@ pub struct SceneParams<'a> {
|
|||
pub time: f64,
|
||||
pub text: &'a mut SimpleText,
|
||||
pub resolution: Option<Vec2>,
|
||||
pub base_color: Option<vello::peniko::Color>,
|
||||
}
|
||||
|
||||
pub struct SceneConfig {
|
||||
|
|
|
@ -32,6 +32,7 @@ pub fn test_scenes() -> SceneSet {
|
|||
scene!(blend_grid),
|
||||
scene!(conflation_artifacts),
|
||||
scene!(labyrinth),
|
||||
scene!(base_color_test: animated),
|
||||
];
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
scenes.push(ExampleScene {
|
||||
|
@ -582,6 +583,21 @@ fn labyrinth(sb: &mut SceneBuilder, _: &mut SceneParams) {
|
|||
)
|
||||
}
|
||||
|
||||
fn base_color_test(sb: &mut SceneBuilder, params: &mut SceneParams) {
|
||||
// Cycle through the hue value every 5 seconds (t % 5) * 360/5
|
||||
let color = Color::hlc((params.time % 5.0) * 72.0, 80.0, 80.0);
|
||||
params.base_color = Some(color);
|
||||
|
||||
// Blend a white square over it.
|
||||
sb.fill(
|
||||
Fill::NonZero,
|
||||
Affine::IDENTITY,
|
||||
Color::rgba8(255, 255, 255, 128),
|
||||
None,
|
||||
&Rect::new(50.0, 50.0, 500.0, 500.0),
|
||||
);
|
||||
}
|
||||
|
||||
fn around_center(xform: Affine, center: Point) -> Affine {
|
||||
Affine::translate(center.to_vec2()) * xform * Affine::translate(-center.to_vec2())
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ async fn run(
|
|||
event_loop: EventLoop<UserEvent>,
|
||||
window: Window,
|
||||
args: Args,
|
||||
base_color: Color,
|
||||
base_color_arg: Option<Color>,
|
||||
mut scenes: SceneSet,
|
||||
) {
|
||||
use winit::{event::*, event_loop::ControlFlow};
|
||||
|
@ -163,12 +163,6 @@ async fn run(
|
|||
let height = surface.config.height;
|
||||
let device_handle = &render_cx.devices[surface.dev_id];
|
||||
|
||||
let render_params = vello::RenderParams {
|
||||
base_color,
|
||||
width,
|
||||
height,
|
||||
};
|
||||
|
||||
// Allow looping forever
|
||||
scene_ix = scene_ix.rem_euclid(scenes.scenes.len() as i32);
|
||||
let example_scene = &mut scenes.scenes[scene_ix as usize];
|
||||
|
@ -182,9 +176,20 @@ async fn run(
|
|||
time: start.elapsed().as_secs_f64(),
|
||||
text: &mut simple_text,
|
||||
resolution: None,
|
||||
base_color: None,
|
||||
};
|
||||
(example_scene.function)(&mut builder, &mut scene_params);
|
||||
builder.finish();
|
||||
|
||||
// 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.
|
||||
let render_params = vello::RenderParams {
|
||||
base_color: base_color_arg
|
||||
.or(scene_params.base_color)
|
||||
.unwrap_or(Color::BLACK),
|
||||
width,
|
||||
height,
|
||||
};
|
||||
let mut builder = SceneBuilder::for_scene(&mut scene);
|
||||
let mut transform = transform;
|
||||
if let Some(resolution) = scene_params.resolution {
|
||||
|
@ -257,7 +262,7 @@ fn main() -> Result<()> {
|
|||
env_logger::init();
|
||||
let args = Args::parse();
|
||||
let scenes = args.args.select_scene_set(|| Args::command())?;
|
||||
let base_color = args.args.get_base_color()?.unwrap_or(Color::BLACK);
|
||||
let base_color = args.args.get_base_color()?;
|
||||
if let Some(scenes) = scenes {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue