Skip to content

Commit 9de67ae

Browse files
committed
Add a test scene for Clip::Mix
See #1198 This is a runnable version of the code in that PR
1 parent 0cb4afd commit 9de67ae

File tree

1 file changed

+104
-1
lines changed

1 file changed

+104
-1
lines changed

examples/scenes/src/test_scenes.rs

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export_scenes!(
7171
brush_transform(brush_transform: animated),
7272
blend_grid(blend_grid),
7373
deep_blend(deep_blend),
74+
clipped_blend(clipped_blend),
7475
many_clips(many_clips),
7576
conflation_artifacts(conflation_artifacts),
7677
labyrinth(labyrinth),
@@ -100,7 +101,8 @@ mod impls {
100101
use rand::Rng;
101102
use rand::{SeedableRng, rngs::StdRng};
102103
use vello::kurbo::{
103-
Affine, BezPath, Cap, Circle, Ellipse, Join, PathEl, Point, Rect, Shape, Stroke, Vec2,
104+
Affine, BezPath, Cap, Circle, Ellipse, Join, PathEl, Point, Rect, Shape, Stroke, Triangle,
105+
Vec2,
104106
};
105107
use vello::peniko::color::{AlphaColor, Lch, palette};
106108
use vello::peniko::*;
@@ -1111,6 +1113,107 @@ mod impls {
11111113
}
11121114
}
11131115

1116+
pub(super) fn clipped_blend(scene: &mut Scene, params: &mut SceneParams<'_>) {
1117+
params.resolution = Some(Vec2::new(1000., 1200.));
1118+
let transform = Affine::translate((10., 100.));
1119+
params.text.add_run(
1120+
&mut *scene,
1121+
None,
1122+
32.,
1123+
Color::WHITE,
1124+
transform.then_translate((10., -30.).into()),
1125+
None,
1126+
&Style::Fill(Fill::EvenOdd),
1127+
"No Clip",
1128+
);
1129+
1130+
scene.fill(
1131+
Fill::EvenOdd,
1132+
transform,
1133+
palette::css::BLUE,
1134+
None,
1135+
&Rect::from_origin_size((0., 0.), (400., 400.)),
1136+
);
1137+
scene.push_layer(
1138+
Mix::Multiply,
1139+
1.0,
1140+
transform,
1141+
&Triangle::from_coords((200., 0.), (0., 400.), (400., 400.)),
1142+
);
1143+
scene.fill(
1144+
Fill::EvenOdd,
1145+
transform,
1146+
palette::css::AQUAMARINE,
1147+
None,
1148+
&Rect::from_origin_size((0., 0.), (400., 400.)),
1149+
);
1150+
scene.pop_layer();
1151+
1152+
let transform = Affine::translate((0., 600.));
1153+
params.text.add_run(
1154+
&mut *scene,
1155+
None,
1156+
32.,
1157+
Color::WHITE,
1158+
transform.then_translate((10., -30.).into()),
1159+
None,
1160+
&Style::Fill(Fill::EvenOdd),
1161+
"Mix::Normal",
1162+
);
1163+
1164+
scene.fill(
1165+
Fill::EvenOdd,
1166+
transform,
1167+
palette::css::BLUE,
1168+
None,
1169+
&Rect::from_origin_size((0., 0.), (400., 400.)),
1170+
);
1171+
let layer_shape = Triangle::from_coords((200., 0.), (0., 400.), (400., 400.));
1172+
scene.push_layer(Mix::Normal, 1.0, transform, &layer_shape);
1173+
scene.push_layer(Mix::Multiply, 1.0, transform, &layer_shape);
1174+
scene.fill(
1175+
Fill::EvenOdd,
1176+
transform,
1177+
palette::css::AQUAMARINE,
1178+
None,
1179+
&Rect::from_origin_size((0., 0.), (400., 400.)),
1180+
);
1181+
scene.pop_layer();
1182+
scene.pop_layer();
1183+
1184+
let transform = Affine::translate((500., 600.));
1185+
params.text.add_run(
1186+
&mut *scene,
1187+
None,
1188+
32.,
1189+
Color::WHITE,
1190+
transform.then_translate((10., -30.).into()),
1191+
None,
1192+
&Style::Fill(Fill::EvenOdd),
1193+
"Mix::Clip",
1194+
);
1195+
1196+
scene.fill(
1197+
Fill::EvenOdd,
1198+
transform,
1199+
palette::css::BLUE,
1200+
None,
1201+
&Rect::from_origin_size((0., 0.), (400., 400.)),
1202+
);
1203+
let layer_shape = Triangle::from_coords((200., 0.), (0., 400.), (400., 400.));
1204+
scene.push_layer(Mix::Clip, 1.0, transform, &layer_shape);
1205+
scene.push_layer(Mix::Multiply, 1.0, transform, &layer_shape);
1206+
scene.fill(
1207+
Fill::EvenOdd,
1208+
transform,
1209+
palette::css::AQUAMARINE,
1210+
None,
1211+
&Rect::from_origin_size((0., 0.), (400., 400.)),
1212+
);
1213+
scene.pop_layer();
1214+
scene.pop_layer();
1215+
}
1216+
11141217
pub(super) fn many_clips(scene: &mut Scene, params: &mut SceneParams<'_>) {
11151218
params.resolution = Some(Vec2::new(1000., 1000.));
11161219
let mut rng = StdRng::seed_from_u64(42);

0 commit comments

Comments
 (0)