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

Examples: Replace Color::from_* and Color::new with palette::css where possible #787

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
15 changes: 8 additions & 7 deletions examples/scenes/src/mmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::cmp::Ordering;
use rand::seq::SliceRandom;
use rand::Rng;
use vello::kurbo::{Affine, BezPath, CubicBez, Line, ParamCurve, PathSeg, Point, QuadBez, Stroke};
use vello::peniko::color::palette;
use vello::peniko::Color;
use vello::Scene;

Expand Down Expand Up @@ -118,13 +119,13 @@ impl TestScene for MMark {
}

const COLORS: &[Color] = &[
Color::from_rgba8(0x10, 0x10, 0x10, 0xff),
Color::from_rgba8(0x80, 0x80, 0x80, 0xff),
Color::from_rgba8(0xc0, 0xc0, 0xc0, 0xff),
Color::from_rgba8(0x10, 0x10, 0x10, 0xff),
Color::from_rgba8(0x80, 0x80, 0x80, 0xff),
Color::from_rgba8(0xc0, 0xc0, 0xc0, 0xff),
Color::from_rgba8(0xe0, 0x10, 0x40, 0xff),
palette::css::BLACK,
palette::css::GRAY,
palette::css::LIGHT_GRAY,
palette::css::BLACK,
palette::css::GRAY,
palette::css::LIGHT_GRAY,
palette::css::DEEP_PINK,
Comment on lines -121 to +128
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These need to match the motionmark benchmark

];

impl Element {
Expand Down
34 changes: 17 additions & 17 deletions examples/scenes/src/test_scenes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ mod impls {
use PathEl::*;
move |scene, params| {
let colors = [
Color::from_rgba8(140, 181, 236, 255),
Color::from_rgba8(246, 236, 202, 255),
Color::from_rgba8(201, 147, 206, 255),
Color::from_rgba8(150, 195, 160, 255),
palette::css::SKY_BLUE,
palette::css::LIGHT_SALMON,
palette::css::LAVENDER,
palette::css::PALE_GREEN,
Comment on lines -172 to +175
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you come to these colours? Given that this was originally the same set of colours as at line 349, it's surprising that three of the four colour names used are different.

];
let simple_stroke = [MoveTo((0., 0.).into()), LineTo((100., 0.).into())];
let join_stroke = [
Expand Down Expand Up @@ -346,10 +346,10 @@ mod impls {
pub(super) fn tricky_strokes(scene: &mut Scene, params: &mut SceneParams<'_>) {
use PathEl::*;
let colors = [
Color::from_rgba8(140, 181, 236, 255),
Color::from_rgba8(246, 236, 202, 255),
Color::from_rgba8(201, 147, 206, 255),
Color::from_rgba8(150, 195, 160, 255),
palette::css::SKY_BLUE,
palette::css::LIGHT_YELLOW,
palette::css::VIOLET,
palette::css::LIGHT_GREEN,
];

const CELL_SIZE: f64 = 200.;
Expand Down Expand Up @@ -588,14 +588,14 @@ mod impls {
scene.fill(
rule.0,
Affine::translate((0., 10.)) * t * Affine::rotate(0.06),
Color::new([0., 1., 0.7, 0.6]),
palette::css::TURQUOISE.with_alpha(0.6),
None,
&rule.2,
);
scene.fill(
rule.0,
Affine::translate((0., 10.)) * t * Affine::rotate(-0.06),
Color::new([0.9, 0.7, 0.5, 0.6]),
palette::css::ORANGE.with_alpha(0.6),
None,
&rule.2,
);
Expand Down Expand Up @@ -886,7 +886,7 @@ mod impls {
let colors = [
palette::css::RED,
palette::css::YELLOW,
Color::from_rgba8(6, 85, 186, 255),
palette::css::ROYAL_BLUE,
];
let width = 400_f64;
let height = 200_f64;
Expand Down Expand Up @@ -1231,9 +1231,9 @@ mod impls {
.with_stops([palette::css::BLACK, palette::css::WHITE]);
scene.fill(Fill::NonZero, transform, &linear, None, &rect);
const GRADIENTS: &[(f64, f64, Color)] = &[
(150., 0., Color::from_rgba8(255, 240, 64, 255)),
(175., 100., Color::from_rgba8(255, 96, 240, 255)),
(125., 200., Color::from_rgba8(64, 192, 255, 255)),
(150., 0., palette::css::YELLOW),
(175., 100., palette::css::PINK),
(125., 200., palette::css::CYAN),
];
for (x, y, c) in GRADIENTS {
let color2 = c.with_alpha(0.);
Expand Down Expand Up @@ -1279,8 +1279,8 @@ mod impls {
let x = N + 0.5; // Fractional pixel offset reveals the problem on axis-aligned edges.
let mut y = N;

let bg_color = Color::from_rgba8(255, 194, 19, 255);
let fg_color = Color::from_rgba8(12, 165, 255, 255);
let bg_color = palette::css::YELLOW;
let fg_color = palette::css::DODGER_BLUE;

// Two adjacent triangles touching at diagonal edge with opposing winding numbers
scene.fill(
Expand Down Expand Up @@ -1430,7 +1430,7 @@ mod impls {
scene.fill(
Fill::NonZero,
Affine::translate((20.5, 20.5)) * Affine::scale(80.0),
Color::from_rgba8(0x70, 0x80, 0x80, 0xff),
palette::css::SLATE_GRAY,
None,
&path,
);
Expand Down
9 changes: 4 additions & 5 deletions examples/simple/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::num::NonZeroUsize;
use std::sync::Arc;
use vello::kurbo::{Affine, Circle, Ellipse, Line, RoundedRect, Stroke};
use vello::peniko::color::palette;
use vello::peniko::Color;
use vello::util::{RenderContext, RenderSurface};
use vello::{AaConfig, Renderer, RendererOptions, Scene};
use winit::application::ApplicationHandler;
Expand Down Expand Up @@ -211,12 +210,12 @@ fn add_shapes_to_scene(scene: &mut Scene) {
// Draw an outlined rectangle
let stroke = Stroke::new(6.0);
let rect = RoundedRect::new(10.0, 10.0, 240.0, 240.0, 20.0);
let rect_stroke_color = Color::new([0.9804, 0.702, 0.5294, 1.]);
let rect_stroke_color = palette::css::ORANGE;
scene.stroke(&stroke, Affine::IDENTITY, rect_stroke_color, None, &rect);

// Draw a filled circle
let circle = Circle::new((420.0, 200.0), 120.0);
let circle_fill_color = Color::new([0.9529, 0.5451, 0.6588, 1.]);
let circle_fill_color = palette::css::PALE_VIOLET_RED;
scene.fill(
vello::peniko::Fill::NonZero,
Affine::IDENTITY,
Expand All @@ -227,7 +226,7 @@ fn add_shapes_to_scene(scene: &mut Scene) {

// Draw a filled ellipse
let ellipse = Ellipse::new((250.0, 420.0), (100.0, 160.0), -90.0);
let ellipse_fill_color = Color::new([0.7961, 0.651, 0.9686, 1.]);
let ellipse_fill_color = palette::css::PURPLE;
scene.fill(
vello::peniko::Fill::NonZero,
Affine::IDENTITY,
Expand All @@ -238,6 +237,6 @@ fn add_shapes_to_scene(scene: &mut Scene) {

// Draw a straight line
let line = Line::new((260.0, 20.0), (620.0, 100.0));
let line_stroke_color = Color::new([0.5373, 0.7059, 0.9804, 1.]);
let line_stroke_color = palette::css::SKY_BLUE;
scene.stroke(&stroke, Affine::IDENTITY, line_stroke_color, None, &line);
}
9 changes: 4 additions & 5 deletions examples/simple_sdl2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use std::num::NonZeroUsize;

use vello::kurbo::{Affine, Circle, Ellipse, Line, RoundedRect, Stroke};
use vello::peniko::color::palette;
use vello::peniko::Color;
use vello::util::{RenderContext, RenderSurface};
use vello::{AaConfig, Renderer, RendererOptions, Scene};

Expand Down Expand Up @@ -121,12 +120,12 @@ fn add_shapes_to_scene(scene: &mut Scene) {
// Draw an outlined rectangle
let stroke = Stroke::new(6.0);
let rect = RoundedRect::new(10.0, 10.0, 240.0, 240.0, 20.0);
let rect_stroke_color = Color::new([0.9804, 0.702, 0.5294, 1.]);
let rect_stroke_color = palette::css::ORANGE;
scene.stroke(&stroke, Affine::IDENTITY, rect_stroke_color, None, &rect);

// Draw a filled circle
let circle = Circle::new((420.0, 200.0), 120.0);
let circle_fill_color = Color::new([0.9529, 0.5451, 0.6588, 1.]);
let circle_fill_color = palette::css::PALE_VIOLET_RED;
scene.fill(
vello::peniko::Fill::NonZero,
Affine::IDENTITY,
Expand All @@ -137,7 +136,7 @@ fn add_shapes_to_scene(scene: &mut Scene) {

// Draw a filled ellipse
let ellipse = Ellipse::new((250.0, 420.0), (100.0, 160.0), -90.0);
let ellipse_fill_color = Color::new([0.7961, 0.651, 0.9686, 1.]);
let ellipse_fill_color = palette::css::PURPLE;
scene.fill(
vello::peniko::Fill::NonZero,
Affine::IDENTITY,
Expand All @@ -148,6 +147,6 @@ fn add_shapes_to_scene(scene: &mut Scene) {

// Draw a straight line
let line = Line::new((260.0, 20.0), (620.0, 100.0));
let line_stroke_color = Color::new([0.5373, 0.7059, 0.9804, 1.]);
let line_stroke_color = palette::css::SKY_BLUE;
scene.stroke(&stroke, Affine::IDENTITY, line_stroke_color, None, &line);
}
10 changes: 6 additions & 4 deletions examples/with_winit/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use std::collections::VecDeque;
#[cfg(feature = "wgpu-profiler")]
use vello::kurbo::Line;
use vello::kurbo::{Affine, PathEl, Rect, Stroke};
use vello::peniko::{color::palette, Brush, Color, Fill};
#[cfg(feature = "wgpu-profiler")]
use vello::peniko::Color;
use vello::peniko::{color::palette, Brush, Fill};
use vello::{low_level::BumpAllocators, AaConfig, Scene};

#[cfg(all(feature = "wgpu-profiler", not(target_arch = "wasm32")))]
Expand Down Expand Up @@ -135,9 +137,9 @@ impl Snapshot {
let s = Affine::scale_non_uniform(1., -h);
#[allow(clippy::match_overlapping_arm)]
let color = match *sample {
..=16_667 => Color::from_rgba8(100, 143, 255, 255),
..=33_334 => Color::from_rgba8(255, 176, 0, 255),
_ => Color::from_rgba8(220, 38, 127, 255),
..=16_667 => palette::css::ROYAL_BLUE,
..=33_334 => palette::css::ORANGE,
_ => palette::css::PINK,
};
scene.fill(
Fill::NonZero,
Expand Down
4 changes: 2 additions & 2 deletions vello_tests/snapshots/big_colr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions vello_tests/snapshots/fill_types.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions vello_tests/snapshots/stroke_styles.png
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it's just me, but this colour scheme looks worse to me. The previous scheme all had a very similar saturation, whereas now the green looks more saturated than the orange and the blue (plus the new white, which also stands out)

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions vello_tests/snapshots/stroke_styles_non_uniform.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions vello_tests/snapshots/stroke_styles_skew.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions vello_tests/snapshots/tricky_strokes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading