Merge pull request #9929 from dotCooCoo/feat/scatter-brush-brightness-jitter

Brushes: Scatter Brush Options has Brightness Jitter, a per-copy brightness move
This commit is contained in:
.CooCoo authored and GitHub committed 2026-11-28 08:03:07 -08:00
commit a0890cc87b
14 files changed
+369 -34

No files matched your search

+61 -3
View File
@@ -125,6 +125,10 @@ const HUE_JITTER_SALT: u64 = 0x6875_655f_6a69_7474;
/// jitter's and the hue jitter's amounts stay as they were without it.
const SATURATION_JITTER_SALT: u64 = 0x7361_745f_6a69_7474;
/// Mixed into a stroke's seed for its brightness jitter, so its amounts follow neither the hue
/// jitter's nor the saturation jitter's, and theirs stay as they were without it.
const BRIGHTNESS_JITTER_SALT: u64 = 0x6272_695f_6a69_7474;
/// Recolor each of `copies` (a scatter brush's copies, in order along the path) with `adjust`,
/// given that copy's own amount between −`amount` and `amount`, drawn from `seed` (the stroke's
/// [`crate::track::seed_of`]) mixed with `salt`. `adjust` gives `None` for a color it leaves as it
@@ -149,6 +153,58 @@ pub(crate) fn jitter_saturations(copies: &mut [Node], amount: f64, seed: u64) {
jitter_copies(copies, amount, seed, SATURATION_JITTER_SALT, saturated);
}
/// Move the brightness of each of `copies` by its own amount between −`amount` and `amount`
/// percentage points (see [`jitter_copies`]).
pub(crate) fn jitter_brightnesses(copies: &mut [Node], amount: f64, seed: u64) {
jitter_copies(copies, amount, seed, BRIGHTNESS_JITTER_SALT, brightened);
}
/// `c` with its brightness moved by `points` percentage points, worked out on its own components
/// so its hue and saturation stay: RGB in HSB of its values, Gray by taking that much ink off or
/// adding it, CMYK by changing its K over the brightness its C, M and Y leave (C, M and Y change
/// only to go brighter than they show with no K), Lab by moving its lightness by `points` units
/// with a and b kept. The result stays between black and full brightness. White, black and grays
/// move too. `None` when the brightness stays as it is.
fn brightened(c: &Color, points: f32) -> Option<Color> {
if !points.is_finite() {
return None;
}
let by = points / 100.0;
match *c {
Color::Rgb { r, g, b } => {
let [h, s, v] = vectorcraft_color::rgb_to_hsb([r, g, b]);
let to = (v + by).clamp(0.0, 1.0);
(to != v).then(|| {
let [r, g, b] = vectorcraft_color::hsb_to_rgb([h, s, to]);
Color::rgb(r, g, b)
})
}
Color::Gray { k } => {
let to = (k - by).clamp(0.0, 1.0);
(to != k).then_some(Color::gray(to))
}
Color::Cmyk { c, m, y, k } => {
// `v` is the brightness C, M and Y leave; with its K the color shows `v` × (1 − K).
let [h, s, v] = vectorcraft_color::rgb_to_hsb([1.0 - c, 1.0 - m, 1.0 - y]);
let shown = v * (1.0 - k);
let to = (shown + by).clamp(0.0, 1.0);
if to == shown {
None
} else if to <= v {
// v > 0 here: to < shown would need shown > 0, and to > shown leaves to > 0.
Some(Color::cmyk(c, m, y, (1.0 - to / v).clamp(0.0, 1.0)))
} else {
let [r, g, b] = vectorcraft_color::hsb_to_rgb([h, s, to]);
Some(Color::cmyk(1.0 - r, 1.0 - g, 1.0 - b, 0.0))
}
}
Color::Lab { l, a, b } => {
let to = (l + points).clamp(0.0, 100.0);
(to != l).then_some(Color::lab(to, a, b))
}
}
}
/// The largest a or b a Lab color takes.
const LAB_AB_MAX: f64 = 127.0;
@@ -156,7 +212,8 @@ const LAB_AB_MAX: f64 = 127.0;
/// so its hue and brightness stay: RGB in HSB of its values, CMYK over C, M and Y with K kept, Lab
/// by moving its chroma (the length of a and b) by `points` with its lightness and hue angle kept.
/// The result stays between no saturation and full. `None` for a color without a hue (white,
/// black and grays, which have no saturation to move).
/// black and grays, which have no saturation to move) and for one whose saturation stays as it is
/// (already at the end it would move past), so such a color keeps its swatch link.
fn saturated(c: &Color, points: f32) -> Option<Color> {
if !points.is_finite() || vectorcraft_color::recolor::Neutral::of(c).is_some() {
return None;
@@ -164,7 +221,8 @@ fn saturated(c: &Color, points: f32) -> Option<Color> {
let by = points / 100.0;
let move_by = |v: [f32; 3]| {
let [h, s, b] = vectorcraft_color::rgb_to_hsb(v);
(s > 0.0).then(|| vectorcraft_color::hsb_to_rgb([h, (s + by).clamp(0.0, 1.0), b]))
let to = (s + by).clamp(0.0, 1.0);
(s > 0.0 && to != s).then(|| vectorcraft_color::hsb_to_rgb([h, to, b]))
};
match *c {
Color::Rgb { r, g, b } => move_by([r, g, b]).map(|[r, g, b]| Color::rgb(r, g, b)),
@@ -180,7 +238,7 @@ fn saturated(c: &Color, points: f32) -> Option<Color> {
// already reaches past that does not grow.
let fit = (LAB_AB_MAX / a.abs().max(b.abs())).max(1.0);
let scale = ((chroma + f64::from(points)).max(0.0) / chroma).min(fit);
Some(Color::lab(l, (a * scale) as f32, (b * scale) as f32))
(scale != 1.0).then(|| Color::lab(l, (a * scale) as f32, (b * scale) as f32))
}
}
}
+2
View File
@@ -174,6 +174,7 @@ pub fn defaults() -> &'static [Brush] {
colorization: Colorization::Tints,
hue_jitter: 0.0,
saturation_jitter: 0.0,
brightness_jitter: 0.0,
modes: None,
}),
},
@@ -189,6 +190,7 @@ pub fn defaults() -> &'static [Brush] {
colorization: Colorization::None,
hue_jitter: 0.0,
saturation_jitter: 0.0,
brightness_jitter: 0.0,
modes: None,
}),
},
+30 -4
View File
@@ -332,6 +332,14 @@ pub struct Scatter {
/// they are.
#[serde(skip_serializing_if = "is_zero")]
pub saturation_jitter: f64,
/// Brightness jitter in percent, 0 to 100: each copy moves the brightness of the solid colors
/// it draws, after the colorization and the hue and saturation jitter, by its own amount
/// between −`brightness_jitter` and `brightness_jitter` percentage points, keeping their hue
/// and saturation. White, black and grays move too. The stroke's path and the brush name fix
/// the amounts, so a stroke draws the same colors every time. 0 (brushes saved before there
/// was brightness jitter) leaves the colors as they are.
#[serde(skip_serializing_if = "is_zero")]
pub brightness_jitter: f64,
/// How size, spacing, scatter and rotation vary between their two values: Fixed takes the
/// first, Random any value between them, Pressure the first at the lightest pen pressure and
/// the second at the heaviest, Tilt the first with the pen lying flat and the second upright,
@@ -355,6 +363,7 @@ impl Default for Scatter {
colorization: Colorization::None,
hue_jitter: 0.0,
saturation_jitter: 0.0,
brightness_jitter: 0.0,
modes: None,
}
}
@@ -367,6 +376,8 @@ impl Scatter {
pub const HUE_JITTER_RANGE: (f64, f64) = (0.0, 180.0);
/// The range of [`Scatter::saturation_jitter`] (%).
pub const SATURATION_JITTER_RANGE: (f64, f64) = (0.0, 100.0);
/// The range of [`Scatter::brightness_jitter`] (%).
pub const BRIGHTNESS_JITTER_RANGE: (f64, f64) = (0.0, 100.0);
/// Size, spacing, scatter and rotation, each as its (first, second) values.
pub fn values(&self) -> [(f64, f64); 4] {
@@ -762,6 +773,7 @@ impl Brush {
s.rotation = within_pair(s.rotation, rotation, 0.0);
s.hue_jitter = within(s.hue_jitter, Scatter::HUE_JITTER_RANGE, 0.0);
s.saturation_jitter = within(s.saturation_jitter, Scatter::SATURATION_JITTER_RANGE, 0.0);
s.brightness_jitter = within(s.brightness_jitter, Scatter::BRIGHTNESS_JITTER_RANGE, 0.0);
s.colorization.sanitize();
}
BrushKind::Art(a) => {
@@ -815,6 +827,7 @@ struct ScatterOptions {
colorization: Colorization,
hue_jitter: f64,
saturation_jitter: f64,
brightness_jitter: f64,
}
/// The Art brush fields a stroke can set for itself.
@@ -847,9 +860,18 @@ impl BrushKind {
pub fn stroke_option_keys(&self) -> &'static [&'static str] {
match self {
BrushKind::Calligraphic(_) => &["angle", "roundness", "size", "variation", "modes"],
BrushKind::Scatter(_) => {
&["size", "spacing", "scatter", "rotation", "modes", "rotation_relative_to_path", "colorization", "hue_jitter", "saturation_jitter"]
}
BrushKind::Scatter(_) => &[
"size",
"spacing",
"scatter",
"rotation",
"modes",
"rotation_relative_to_path",
"colorization",
"hue_jitter",
"saturation_jitter",
"brightness_jitter",
],
BrushKind::Art(_) => &["width", "width_mode", "width_max", "flip_along", "flip_across", "overlap", "colorization"],
BrushKind::Pattern(_) => &["scale", "spacing", "fit", "flip_along", "flip_across", "colorization"],
BrushKind::Bristle(_) => &[],
@@ -876,6 +898,7 @@ impl BrushKind {
colorization: s.colorization,
hue_jitter: s.hue_jitter,
saturation_jitter: s.saturation_jitter,
brightness_jitter: s.brightness_jitter,
}),
BrushKind::Art(a) => serde_json::to_value(ArtOptions {
width: a.width,
@@ -908,7 +931,7 @@ impl BrushKind {
let o: ScatterOptions = serde_json::from_value(v)?;
(s.size, s.spacing, s.scatter, s.rotation, s.modes) = (o.size, o.spacing, o.scatter, o.rotation, o.modes);
(s.rotation_relative_to_path, s.colorization) = (o.rotation_relative_to_path, o.colorization);
(s.hue_jitter, s.saturation_jitter) = (o.hue_jitter, o.saturation_jitter);
(s.hue_jitter, s.saturation_jitter, s.brightness_jitter) = (o.hue_jitter, o.saturation_jitter, o.brightness_jitter);
}
BrushKind::Art(a) => {
let o: ArtOptions = serde_json::from_value(v)?;
@@ -1156,6 +1179,9 @@ pub fn stroke_pieces(doc: &Document, brush: &Brush, bp: &BezPath, stroke: &Strok
if s.saturation_jitter > 0.0 {
colorize::jitter_saturations(&mut out, s.saturation_jitter, track::seed_of(bp, &brush.name));
}
if s.brightness_jitter > 0.0 {
colorize::jitter_brightnesses(&mut out, s.brightness_jitter, track::seed_of(bp, &brush.name));
}
}
leave_out_brushed(doc, &mut out, &mut Known::new());
out
+176 -9
View File
@@ -1249,23 +1249,26 @@ fn hue_jitter_turns_type_every_colorization_and_linked_colors() {
}
}
/// A stroke's own hue and saturation jitter replace the brush's, as its other scatter settings do,
/// and are kept within their ranges.
/// A stroke's own hue, saturation and brightness jitter replace the brush's, as its other scatter
/// settings do, and are kept within their ranges.
#[test]
fn a_strokes_own_jitter_replaces_the_brushs() {
let doc = Document::new(1.0, 1.0);
let path = line(0.0, 0.0, 200.0, 0.0);
let pink = Color::rgb(0.8, 0.4, 0.4);
let b = sat_jittered(pink, Colorization::None, 0.0, 0.0);
let own = stroke_pieces(&doc, &b, &path, &with_options(serde_json::json!({"hue_jitter": 30.0, "saturation_jitter": 40.0})));
let brushed = stroke_pieces(&doc, &sat_jittered(pink, Colorization::None, 30.0, 40.0), &path, &stroke(1.0));
let own =
stroke_pieces(&doc, &b, &path, &with_options(serde_json::json!({"hue_jitter": 30.0, "saturation_jitter": 40.0, "brightness_jitter": 20.0})));
let brushed = stroke_pieces(&doc, &bri_jittered(sat_jittered(pink, Colorization::None, 30.0, 40.0), 20.0), &path, &stroke(1.0));
assert_eq!(fill_colors(&own), fill_colors(&brushed));
assert!(fill_colors(&own).iter().any(|c| *c != pink));
let options = serde_json::Map::from_iter([("saturation_jitter".to_string(), serde_json::json!(500.0))]);
assert_eq!(
b.stroke_options_that_differ(&options).unwrap(),
serde_json::Map::from_iter([("saturation_jitter".to_string(), serde_json::json!(100.0))])
);
// The brightness is part of what the stroke's own options give.
let without = stroke_pieces(&doc, &sat_jittered(pink, Colorization::None, 30.0, 40.0), &path, &stroke(1.0));
assert_ne!(fill_colors(&own), fill_colors(&without));
for (key, given, kept) in [("saturation_jitter", 500.0, 100.0), ("brightness_jitter", 500.0, 100.0)] {
let options = serde_json::Map::from_iter([(key.to_string(), serde_json::json!(given))]);
assert_eq!(b.stroke_options_that_differ(&options).unwrap(), serde_json::Map::from_iter([(key.to_string(), serde_json::json!(kept))]));
}
// A stroke that sets 0 on a jittered brush draws the art's own color.
let still =
stroke_pieces(&doc, &sat_jittered(pink, Colorization::None, 0.0, 40.0), &path, &with_options(serde_json::json!({"saturation_jitter": 0.0})));
@@ -1432,6 +1435,170 @@ fn saturation_jitter_moves_type_and_linked_colors() {
}
}
/// `b` (a scatter brush) with `brightness_jitter`.
fn bri_jittered(mut b: Brush, brightness_jitter: f64) -> Brush {
if let BrushKind::Scatter(s) = &mut b.kind {
s.brightness_jitter = brightness_jitter;
}
b
}
#[test]
fn brightness_jitter_moves_each_copy_the_same_every_time() {
let doc = Document::new(1.0, 1.0);
let path = line(0.0, 0.0, 200.0, 0.0);
// A red at 50% saturation and 80% brightness.
let pink = Color::rgb(0.8, 0.4, 0.4);
let b = bri_jittered(sat_jittered(pink, Colorization::None, 0.0, 0.0), 15.0);
let out = stroke_pieces(&doc, &b, &path, &stroke(1.0));
assert_eq!(out.len(), 20);
assert_eq!(stroke_pieces(&doc, &b, &path, &stroke(1.0)), out, "the same stroke draws the same colors");
let colors = fill_colors(&out);
let hsb: Vec<[f32; 3]> = colors.iter().map(rgb_hsb).collect();
// Each copy's brightness is within 15 points of 80%; its hue and saturation stay.
assert!(hsb.iter().all(|[h, s, v]| hue_gap(*h, 0.0) < 1e-3 && near(f64::from(*s), 0.5, 1e-4) && (v - 0.8).abs() <= 0.1501), "{hsb:?}");
assert!(hsb.iter().any(|[_, _, v]| *v > 0.85) && hsb.iter().any(|[_, _, v]| *v < 0.75), "the copies move both ways: {hsb:?}");
let distinct: std::collections::HashSet<String> = colors.iter().map(Color::to_hex).collect();
assert!(distinct.len() > 10, "each copy moves by its own amount: {distinct:?}");
// The copies stay where they were, at their size and angle.
let plain = stroke_pieces(&doc, &sat_jittered(pink, Colorization::None, 0.0, 0.0), &path, &stroke(1.0));
let boxes = |o: &[Node]| o.iter().map(|n| n.geometric_bounds().unwrap()).collect::<Vec<_>>();
assert_eq!(boxes(&out), boxes(&plain));
// Another path draws other amounts.
let other = fill_colors(&stroke_pieces(&doc, &b, &line(0.0, 10.0, 200.0, 10.0), &stroke(1.0)));
assert_ne!(other, colors);
// At 100 the copies reach black or full brightness and go no further.
let full: Vec<f32> =
fill_colors(&stroke_pieces(&doc, &bri_jittered(sat_jittered(pink, Colorization::None, 0.0, 0.0), 100.0), &path, &stroke(1.0)))
.iter()
.map(|c| rgb_hsb(c)[2])
.collect();
assert!(full.iter().all(|v| (0.0..=1.0).contains(v)), "{full:?}");
assert!(full.iter().any(|v| *v < 1e-6) && full.iter().any(|v| *v > 1.0 - 1e-6), "{full:?}");
// Brightness jitter leaves the hue and saturation jitter's amounts as they were.
let red = Color::rgb(1.0, 0.0, 0.0);
let hue_sat = fill_colors(&stroke_pieces(&doc, &sat_jittered(red, Colorization::None, 90.0, 50.0), &path, &stroke(1.0)));
let all = fill_colors(&stroke_pieces(&doc, &bri_jittered(sat_jittered(red, Colorization::None, 90.0, 50.0), 30.0), &path, &stroke(1.0)));
assert_eq!(all.len(), hue_sat.len());
assert_ne!(all, hue_sat);
for (a, h) in all.iter().zip(&hue_sat) {
let ([ha, sa, _], [hh, sh, _]) = (rgb_hsb(a), rgb_hsb(h));
assert!(hue_gap(ha, hh) < 0.01 && (sa - sh).abs() < 1e-4, "{a:?} from {h:?}");
}
}
#[test]
fn brightness_jitter_of_zero_changes_nothing() {
let pink = Color::rgb(0.8, 0.4, 0.4);
let plain = sat_jittered(pink, Colorization::None, 0.0, 0.0);
let out = stroke_pieces(&Document::new(1.0, 1.0), &bri_jittered(plain.clone(), 0.0), &line(0.0, 0.0, 200.0, 0.0), &stroke(1.0));
assert!(!out.is_empty() && fill_colors(&out).iter().all(|c| *c == pink));
// A brush without brightness jitter is saved as before, and one saved before reads as 0.
let v = serde_json::to_value(&plain).unwrap();
assert!(v.get("brightness_jitter").is_none(), "{v}");
let mut old = serde_json::to_value(bri_jittered(plain.clone(), 25.0)).unwrap();
assert_eq!(old.as_object_mut().unwrap().remove("brightness_jitter"), Some(serde_json::json!(25.0)));
let BrushKind::Scatter(s) = Brush::from_json(old).unwrap().kind else { panic!("not a scatter brush") };
assert_eq!(s.brightness_jitter, 0.0, "a brush saved without the key reads as 0");
let mut with = v.clone();
with["brightness_jitter"] = serde_json::json!(25.0);
let BrushKind::Scatter(s) = Brush::from_json(with).unwrap().kind else { panic!("not a scatter brush") };
assert_eq!(s.brightness_jitter, 25.0);
// Values outside 0..100 are clamped.
for (given, kept) in [(250.0, 100.0), (-5.0, 0.0)] {
let mut v = v.clone();
v["brightness_jitter"] = serde_json::json!(given);
let BrushKind::Scatter(s) = Brush::from_json(v).unwrap().kind else { panic!("not a scatter brush") };
assert_eq!(s.brightness_jitter, kept, "{given}");
}
}
#[test]
fn brightness_jitter_moves_after_the_colorization_in_each_model() {
let doc = Document::new(1.0, 1.0);
let path = line(0.0, 0.0, 200.0, 0.0);
let jittered_fills = |art: Color, colorization: Colorization, amount: f64, key: &StrokeLayer| {
fill_colors(&stroke_pieces(&doc, &bri_jittered(sat_jittered(art, colorization, 0.0, 0.0), amount), &path, key))
};
// Tints: black art takes the blue stroke color, whose brightness then moves.
let blue = StrokeLayer::new(Paint::solid(Color::rgb(0.0, 0.0, 1.0)), 1.0);
let hsb: Vec<[f32; 3]> = jittered_fills(Color::BLACK, Colorization::Tints, 30.0, &blue).iter().map(rgb_hsb).collect();
assert!(!hsb.is_empty() && hsb.iter().all(|[h, s, v]| hue_gap(*h, 240.0) < 1e-3 && near(f64::from(*s), 1.0, 1e-4) && *v >= 0.6999), "{hsb:?}");
assert!(hsb.iter().any(|[_, _, v]| *v < 0.97), "{hsb:?}");
// White, black and grays move too, and stay neutral. RGB white gets darker.
let white: Vec<[f32; 3]> = jittered_fills(Color::WHITE, Colorization::None, 30.0, &stroke(1.0)).iter().map(rgb_hsb).collect();
assert!(white.iter().all(|[_, s, v]| *s == 0.0 && *v >= 0.6999) && white.iter().any(|[_, _, v]| *v < 0.95), "{white:?}");
// A gray's ink moves within 20 points of its 40%.
let gray = StrokeLayer::new(Paint::solid(Color::gray(0.4)), 1.0);
let grays = jittered_fills(Color::BLACK, Colorization::Tints, 20.0, &gray);
assert!(grays.iter().all(|c| matches!(*c, Color::Gray { k } if (k - 0.4).abs() <= 0.2001)), "{grays:?}");
assert!(grays.iter().any(|c| *c != Color::gray(0.4)), "{grays:?}");
// Black ink alone stays black ink alone, lighter by its K.
let k_only = jittered_fills(Color::cmyk(0.0, 0.0, 0.0, 1.0), Colorization::None, 30.0, &stroke(1.0));
assert!(k_only.iter().all(|c| matches!(*c, Color::Cmyk { c, m, y, k } if c == 0.0 && m == 0.0 && y == 0.0 && k >= 0.6999)), "{k_only:?}");
assert!(k_only.iter().any(|c| matches!(*c, Color::Cmyk { k, .. } if k < 0.97)), "{k_only:?}");
// A process color with room in its K moves by its K and keeps its C, M and Y.
let cmyk = jittered_fills(Color::cmyk(0.0, 0.6, 0.6, 0.25), Colorization::None, 20.0, &stroke(1.0));
assert!(cmyk.iter().any(|c| *c != Color::cmyk(0.0, 0.6, 0.6, 0.25)), "{cmyk:?}");
for c in &cmyk {
let Color::Cmyk { c, m, y, k } = *c else { panic!("not CMYK: {c:?}") };
assert!(c == 0.0 && m == 0.6 && y == 0.6 && (k - 0.25).abs() <= 0.2001, "{c} {m} {y} {k}");
}
// One brighter than its C, M and Y show with no K loses its K and takes less ink, its hue and
// saturation kept (full magenta and yellow, cyan the brightness).
let deep = jittered_fills(Color::cmyk(0.4, 1.0, 1.0, 0.0), Colorization::None, 30.0, &stroke(1.0));
let mut ways = (false, false);
for c in &deep {
let Color::Cmyk { c, m, y, k } = *c else { panic!("not CMYK: {c:?}") };
assert!(near(f64::from(m), 1.0, 1e-5) && near(f64::from(y), 1.0, 1e-5), "{c} {m} {y} {k}");
if k > 0.0 {
assert!(c == 0.4 && k <= 0.5001, "darker: {c} {k}");
ways.0 = true;
} else {
assert!((0.0999..=0.4).contains(&c), "brighter: {c}");
ways.1 |= c < 0.4;
}
}
assert!(ways.0 && ways.1, "the copies move both ways: {deep:?}");
// A Lab color keeps its a and b; its lightness moves within 20 of its 50.
let lab = jittered_fills(Color::lab(50.0, 40.0, 30.0), Colorization::None, 20.0, &stroke(1.0));
assert!(lab.iter().any(|c| *c != Color::lab(50.0, 40.0, 30.0)), "{lab:?}");
assert!(lab.iter().all(|c| matches!(*c, Color::Lab { l, a, b } if a == 40.0 && b == 30.0 && (l - 50.0).abs() <= 20.001)), "{lab:?}");
}
/// A swatch-linked color already at the end a copy's saturation or brightness moves toward stays as
/// it is and keeps its link; the copies that move it lose the link.
#[test]
fn jitter_at_a_limit_keeps_the_swatch_link() {
let doc = Document::new(1.0, 1.0);
let path = line(0.0, 0.0, 200.0, 0.0);
// Full red (full saturation and brightness), full magenta and yellow ink, and a Lab red whose a
// is at its largest: saturation that grows and brightness that grows leave them as they are.
for (color, saturation_jitter, brightness_jitter) in [
(Color::rgb(1.0, 0.0, 0.0), 50.0, 0.0),
(Color::cmyk(0.0, 1.0, 1.0, 0.0), 50.0, 0.0),
(Color::lab(50.0, 127.0, 0.0), 50.0, 0.0),
(Color::rgb(1.0, 0.0, 0.0), 0.0, 50.0),
(Color::lab(100.0, 20.0, 10.0), 0.0, 50.0),
] {
let linked = Paint::Solid { color, swatch: Some("Spot".into()), tint: 1.0 };
let mut art = rect_art(10.0, 4.0);
art.appearance.set_fill(linked.clone());
let mut s = Scatter { art, saturation_jitter, ..Default::default() };
s.brightness_jitter = brightness_jitter;
let out = stroke_pieces(&doc, &Brush { name: "s".into(), kind: BrushKind::Scatter(s) }, &path, &stroke(1.0));
let (mut kept, mut moved) = (0, 0);
for n in &out {
match n.appearance.fill_paint() {
p if p == linked => kept += 1,
Paint::Solid { color: c, swatch: None, .. } if c != color => moved += 1,
p => panic!("{color:?}: {p:?}"),
}
}
assert!(kept > 0 && moved > 0, "{color:?}: {kept} kept, {moved} moved");
}
}
/// An instance whose fill has an opacity of 0 does not stain its symbol's art, so the art keeps its
/// swatch links.
#[test]
+2 -2
View File
@@ -170,7 +170,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Brush Options…",
[],
None,
"{name, params?: {…fields to change (brush.get shows them; values outside their ranges are clamped). calligraphic: angle −180..180° (counter-clockwise from level), roundness 0..100%, size 0..1296 pt, variation: [angle°, roundness%, size pt], modes: [fixed|random|pressure|tilt|bearing|rotation|stylusWheel for angle, roundness, size] (pressure goes from value − variation at the lightest pen pressure to value + variation at the heaviest; tilt from value − variation with the pen lying flat to value + variation with it upright; bearing and rotation add variation × the pen's bearing (which way it leans, counter-clockwise from leaning right) or its barrel's counter-clockwise rotation over 180°; stylusWheel from value − variation at one end of an airbrush pen's finger wheel to value + variation at the other; the angle turns on past ±180°). scatter: size [a, b] 1..10000%, spacing [a, b] 1..10000%, scatter [a, b] −1000..1000%, rotation [a, b] −180..180° (counter-clockwise), modes: [fixed|random|pressure|tilt|bearing|rotation|stylusWheel for size, spacing, scatter, rotation] (fixed: a; random: between a and b; pressure: a at the lightest pen pressure to b at the heaviest; tilt: a with the pen lying flat to b upright; bearing and rotation: a at −180° to b at 180°; stylusWheel: a at one end of an airbrush pen's finger wheel to b at the other), rotation_relative_to_path, hue_jitter 0..180° (each copy turns the hue of its solid colors, after the colorization, by its own amount up to this far either way, the same on every redraw; colors without a hue stay; 0: off), saturation_jitter 0..100% (each copy moves the saturation of its solid colors, after the colorization and the hue jitter, by its own amount up to this many points either way, keeping their hue and brightness, the same on every redraw; colors without a hue stay; 0: off). art: width 1..1000%, width_mode: null (fixed)|pressure|tilt|bearing|rotation|stylusWheel, width_max 1..1000% (pressure: width at the lightest pen pressure to width_max at the heaviest; tilt: width with the pen lying flat to width_max upright; bearing and rotation: width at −180° to width_max at 180°; stylusWheel: width at one end of the finger wheel to width_max at the other; half way on a stroke drawn without that input), scale: {mode: proportional|stretch|betweenGuides, start, end: 0..1 of the art length}, direction: leftToRight|rightToLeft|topToBottom|bottomToTop, flip_along, flip_across, overlap. pattern: scale 1..10000%, spacing 0..10000%, fit: stretch|addSpace|approximate, flip_along, flip_across, outer_corner and inner_corner: corner tile art (drawn as the corner that joins a side tile on its right to one below it) or null, outer_source and inner_source: what that kind of corner draws without its art: none|autoCentered|autoBetween|autoSliced|autoOverlap (a tile made from the side tile), or null (the other kind of corner's art); side_tile, outer_corner_tile, inner_corner_tile, start_tile, end_tile: a document pattern name, original, or none (side refuses none); corner tiles also take autoCentered|autoBetween|autoSliced|autoOverlap. Each tile also accepts {pattern: name} to select a swatch whose name is a reserved choice. scatter, art and pattern: colorization: {method: none|tints|tintsAndShades|hueShift, key: colour (hueShift: the art colour that becomes the stroke colour; without a key: the solid color the art's fills and strokes use most, black when they use none)}; colorization and the art brush's scale change only the fields given}, newName? (trimmed; blank: the name is kept; a new bristle brush name has at most 31 characters, and a longer name the brush has is kept)} edit a brush definition (strokes using it update) → {name}",
"{name, params?: {…fields to change (brush.get shows them; values outside their ranges are clamped). calligraphic: angle −180..180° (counter-clockwise from level), roundness 0..100%, size 0..1296 pt, variation: [angle°, roundness%, size pt], modes: [fixed|random|pressure|tilt|bearing|rotation|stylusWheel for angle, roundness, size] (pressure goes from value − variation at the lightest pen pressure to value + variation at the heaviest; tilt from value − variation with the pen lying flat to value + variation with it upright; bearing and rotation add variation × the pen's bearing (which way it leans, counter-clockwise from leaning right) or its barrel's counter-clockwise rotation over 180°; stylusWheel from value − variation at one end of an airbrush pen's finger wheel to value + variation at the other; the angle turns on past ±180°). scatter: size [a, b] 1..10000%, spacing [a, b] 1..10000%, scatter [a, b] −1000..1000%, rotation [a, b] −180..180° (counter-clockwise), modes: [fixed|random|pressure|tilt|bearing|rotation|stylusWheel for size, spacing, scatter, rotation] (fixed: a; random: between a and b; pressure: a at the lightest pen pressure to b at the heaviest; tilt: a with the pen lying flat to b upright; bearing and rotation: a at −180° to b at 180°; stylusWheel: a at one end of an airbrush pen's finger wheel to b at the other), rotation_relative_to_path, hue_jitter 0..180° (each copy turns the hue of its solid colors, after the colorization, by its own amount up to this far either way, the same on every redraw; colors without a hue stay; 0: off), saturation_jitter 0..100% (each copy moves the saturation of its solid colors, after the colorization and the hue jitter, by its own amount up to this many points either way, keeping their hue and brightness, the same on every redraw; colors without a hue stay; 0: off), brightness_jitter 0..100% (each copy moves the brightness of its solid colors, after the colorization and the hue and saturation jitter, by its own amount up to this many points either way, keeping their hue and saturation, the same on every redraw; white, black and grays move too; 0: off). art: width 1..1000%, width_mode: null (fixed)|pressure|tilt|bearing|rotation|stylusWheel, width_max 1..1000% (pressure: width at the lightest pen pressure to width_max at the heaviest; tilt: width with the pen lying flat to width_max upright; bearing and rotation: width at −180° to width_max at 180°; stylusWheel: width at one end of the finger wheel to width_max at the other; half way on a stroke drawn without that input), scale: {mode: proportional|stretch|betweenGuides, start, end: 0..1 of the art length}, direction: leftToRight|rightToLeft|topToBottom|bottomToTop, flip_along, flip_across, overlap. pattern: scale 1..10000%, spacing 0..10000%, fit: stretch|addSpace|approximate, flip_along, flip_across, outer_corner and inner_corner: corner tile art (drawn as the corner that joins a side tile on its right to one below it) or null, outer_source and inner_source: what that kind of corner draws without its art: none|autoCentered|autoBetween|autoSliced|autoOverlap (a tile made from the side tile), or null (the other kind of corner's art); side_tile, outer_corner_tile, inner_corner_tile, start_tile, end_tile: a document pattern name, original, or none (side refuses none); corner tiles also take autoCentered|autoBetween|autoSliced|autoOverlap. Each tile also accepts {pattern: name} to select a swatch whose name is a reserved choice. scatter, art and pattern: colorization: {method: none|tints|tintsAndShades|hueShift, key: colour (hueShift: the art colour that becomes the stroke colour; without a key: the solid color the art's fills and strokes use most, black when they use none)}; colorization and the art brush's scale change only the fields given}, newName? (trimmed; blank: the name is kept; a new bristle brush name has at most 31 characters, and a longer name the brush has is kept)} edit a brush definition (strokes using it update) → {name}",
has_doc,
brush_options
),
@@ -179,7 +179,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Options of Selected Object…",
[],
None,
"{ids?|id?, params?: {…the fields brush.options takes that a path can set for itself: calligraphic angle (counter-clockwise from level), roundness, size, variation, modes; scatter size, spacing, scatter, rotation (counter-clockwise), modes, rotation_relative_to_path, colorization, hue_jitter, saturation_jitter; art width, width_mode, width_max, flip_along, flip_across, overlap, colorization; pattern scale, spacing, fit, flip_along, flip_across, colorization (values outside their ranges are clamped; a colorization object changes only the fields it gives; a null item of an array such as size: [40, null] keeps each stroke's own item, else the brush's)}, reset?: bool} set the brush settings of the brushed strokes of the selected paths on those strokes only, leaving the brush and its other strokes as they are (the Brushes panel's Options of Selected Object); params add to each stroke's own settings, a mode params does not set (no modes, or a null item) stays the one each stroke draws with when a changed variation or range would change it, a setting equal to the brush's own value is dropped, and reset: true clears them so the strokes draw the brush again; without params or reset nothing changes; one undo step, none when nothing changes. The brushes' own edits (brush.options) still reach the settings a stroke does not set, applying a brush (brush.apply, stroke.setAdvanced or a brush.freehand extend with another brush) or removing it clears them, and a renamed brush keeps them. Refused with nothing painted with a brush selected, for paths painted with brushes of different types, for a bristle brush, for a field the type does not take and for a value of the wrong kind → {ids: the brushed paths, changed: the paths whose settings changed, options: the first stroke's own settings}",
"{ids?|id?, params?: {…the fields brush.options takes that a path can set for itself: calligraphic angle (counter-clockwise from level), roundness, size, variation, modes; scatter size, spacing, scatter, rotation (counter-clockwise), modes, rotation_relative_to_path, colorization, hue_jitter, saturation_jitter, brightness_jitter; art width, width_mode, width_max, flip_along, flip_across, overlap, colorization; pattern scale, spacing, fit, flip_along, flip_across, colorization (values outside their ranges are clamped; a colorization object changes only the fields it gives; a null item of an array such as size: [40, null] keeps each stroke's own item, else the brush's)}, reset?: bool} set the brush settings of the brushed strokes of the selected paths on those strokes only, leaving the brush and its other strokes as they are (the Brushes panel's Options of Selected Object); params add to each stroke's own settings, a mode params does not set (no modes, or a null item) stays the one each stroke draws with when a changed variation or range would change it, a setting equal to the brush's own value is dropped, and reset: true clears them so the strokes draw the brush again; without params or reset nothing changes; one undo step, none when nothing changes. The brushes' own edits (brush.options) still reach the settings a stroke does not set, applying a brush (brush.apply, stroke.setAdvanced or a brush.freehand extend with another brush) or removing it clears them, and a renamed brush keeps them. Refused with nothing painted with a brush selected, for paths painted with brushes of different types, for a bristle brush, for a field the type does not take and for a value of the wrong kind → {ids: the brushed paths, changed: the paths whose settings changed, options: the first stroke's own settings}",
has_doc,
brush_object_options
),
+3 -2
View File
@@ -33,11 +33,12 @@ pub(super) fn brush_get(s: &mut Session, p: &Value) -> Result<Value> {
let name = name_param(p, "brush.get")?;
let b = brush::find(&s.doc()?.doc, name).ok_or_else(|| EngineError::Other(format!("no brush named `{name}`")))?;
let mut v = serde_json::to_value(&b).unwrap_or_default();
// A scatter brush saves its hue and saturation jitter only when they are not 0; brush.get shows
// them either way.
// A scatter brush saves its hue, saturation and brightness jitter only when they are not 0;
// brush.get shows them either way.
if let (BrushKind::Scatter(sc), Some(o)) = (&b.kind, v.as_object_mut()) {
o.entry("hue_jitter").or_insert(json!(sc.hue_jitter));
o.entry("saturation_jitter").or_insert(json!(sc.saturation_jitter));
o.entry("brightness_jitter").or_insert(json!(sc.brightness_jitter));
}
Ok(v)
}
+38
View File
@@ -1848,6 +1848,44 @@ fn scatter_saturation_jitter_saves_and_exports() {
assert_eq!(piece_fills(&s.doc().unwrap().doc, id), plain);
}
/// Scatter Brush Options' `brightness_jitter`: shown by `brush.get`, set by `brush.options` (a value
/// past 100 clamped), saved with the document, and the moved colors drawn the same after Open and
/// written by SVG export.
#[test]
fn scatter_brightness_jitter_saves_and_exports() {
let mut s = session();
let r = rect(&mut s, 10.0, 200.0, 8.0, 8.0);
s.execute("paint.setFill", &json!({"color": "#cc6666"})).unwrap();
let name = s.execute("brush.new", &json!({"type": "scatter", "name": "Confetti", "ids": [r.0]})).unwrap()["name"].as_str().unwrap().to_string();
let id = line(&mut s);
select(&mut s, &[id]);
s.execute("brush.apply", &json!({ "name": name })).unwrap();
let plain = piece_fills(&s.doc().unwrap().doc, id);
assert!(plain.len() > 10 && plain.iter().all(|c| c == "#cc6666"), "{plain:?}");
let get = |s: &mut Session| s.execute("brush.get", &json!({ "name": name })).unwrap()["brightness_jitter"].clone();
assert_eq!(get(&mut s), json!(0.0), "brush.get shows the option at 0");
s.execute("brush.options", &json!({"name": name, "params": {"brightness_jitter": 250}})).unwrap();
assert_eq!(get(&mut s), json!(100.0), "a value past 100 is clamped");
s.execute("brush.options", &json!({"name": name, "params": {"brightness_jitter": 15}})).unwrap();
assert_eq!(get(&mut s), json!(15.0));
let doc = s.doc().unwrap().doc.clone();
let moved = piece_fills(&doc, id);
assert_eq!(moved.len(), plain.len());
let distinct: std::collections::HashSet<&String> = moved.iter().collect();
assert!(distinct.len() > 5, "{moved:?}");
// Saved and opened again, the stroke draws the same colors.
let back = vectorcraft_format::load(&vectorcraft_format::save(&doc, false)).unwrap();
assert_eq!(piece_fills(&back, id), moved);
// SVG export writes each copy's moved color.
let svg = vectorcraft_svg::export(&doc, &Default::default());
for c in &distinct {
assert!(svg.contains(&format!("fill=\"{c}\"")), "{c} missing from the SVG");
}
// Back to 0, the copies draw the art's own color.
s.execute("brush.options", &json!({"name": name, "params": {"brightness_jitter": 0}})).unwrap();
assert_eq!(piece_fills(&s.doc().unwrap().doc, id), plain);
}
/// The bounds of the brush art `id`'s strokes draw.
fn brushed_bounds(s: &Session, id: NodeId) -> Rect {
let st = s.doc().unwrap();
+17
View File
@@ -10389,6 +10389,7 @@ fn brush_library() -> Vec<vectorcraft_brush::Brush> {
colorization: Colorization::Tints,
hue_jitter: 0.0,
saturation_jitter: 0.0,
brightness_jitter: 0.0,
modes: Some([Variation::Random, Variation::Fixed, Variation::Pressure, Variation::Random]),
}),
},
@@ -10526,6 +10527,21 @@ fn a_scatter_brush_with_saturation_jitter_is_left_out() {
assert_eq!(back.iter().map(|b| b.name.as_str()).collect::<Vec<_>>(), ["Nib", "Ribbon", "Plain ribbon"]);
}
/// Nor its brightness jitter: such a brush is left out and reported too.
#[test]
fn a_scatter_brush_with_brightness_jitter_is_left_out() {
use vectorcraft_brush::BrushKind;
let mut lib = brush_library();
let BrushKind::Scatter(s) = &mut lib[1].kind else { panic!("scatter") };
s.brightness_jitter = 30.0;
let mut doc = Document::new(300.0, 200.0);
vectorcraft_brush::store(&mut doc, &lib);
let out = export_ai_editing(&doc, &opts()).unwrap();
assert!(out.warnings.iter().any(|w| w == writer::BRUSHES), "{:?}", out.warnings);
let back = vectorcraft_brush::library(&read_back(&doc));
assert_eq!(back.iter().map(|b| b.name.as_str()).collect::<Vec<_>>(), ["Nib", "Ribbon", "Plain ribbon"]);
}
/// An Art brush's options, without its art.
#[derive(Debug, PartialEq)]
struct ArtBrushOptions(serde_json::Value);
@@ -10858,6 +10874,7 @@ fn more_brush_settings_are_read_back() {
colorization: Colorization::None,
hue_jitter: 0.0,
saturation_jitter: 0.0,
brightness_jitter: 0.0,
modes: Some([Variation::Tilt, Variation::Bearing, Variation::Fixed, Variation::Rotation]),
};
let lib = vec![
+1 -1
View File
@@ -1132,7 +1132,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
"ui.brushOptions",
"Brush Options…",
"",
"{name?} (default: the selected path's brush, else the current brush) open its Brush Options, what double-clicking a brush in the Brushes panel opens (dialog `brushOptions`): Calligraphic (fields name, angle −180..180, roundness 0..100, size 0..1296 pt, angleMode/roundnessMode/sizeMode: fixed|random|pressure, angleVariation/roundnessVariation/sizeVariation), Bristle (fields name, shape, size, length, density, thickness, opacity, stiffness), Scatter (fields sizeMin/sizeMax/sizeMode, spacingMin/spacingMax/spacingMode, scatterMin/scatterMax/scatterMode, rotationMin/rotationMax/rotationMode with modes fixed|random|pressure, rotationRelativeTo: page|path, hueJitter 0..180°, saturationJitter 0..100%), Art (fields width %, scaleMode: proportional|stretch|betweenGuides, guideStart/guideEnd % of the art length, direction: leftToRight|rightToLeft|topToBottom|bottomToTop, flipAlong, flipAcross) or Pattern (fields scale %, spacing %, fit: stretch|addSpace|approximate, flipAlong, flipAcross); Scatter, Art and Pattern also colorization: none|tints|tintsAndShades|hueShift, keyColor, and tips: true opens Colorization Tips (what each method does, beside a sample of the brush painted with it), as the Tips button beside Method does; OK runs brush.options",
"{name?} (default: the selected path's brush, else the current brush) open its Brush Options, what double-clicking a brush in the Brushes panel opens (dialog `brushOptions`): Calligraphic (fields name, angle −180..180, roundness 0..100, size 0..1296 pt, angleMode/roundnessMode/sizeMode: fixed|random|pressure, angleVariation/roundnessVariation/sizeVariation), Bristle (fields name, shape, size, length, density, thickness, opacity, stiffness), Scatter (fields sizeMin/sizeMax/sizeMode, spacingMin/spacingMax/spacingMode, scatterMin/scatterMax/scatterMode, rotationMin/rotationMax/rotationMode with modes fixed|random|pressure, rotationRelativeTo: page|path, hueJitter 0..180°, saturationJitter 0..100%, brightnessJitter 0..100%), Art (fields width %, scaleMode: proportional|stretch|betweenGuides, guideStart/guideEnd % of the art length, direction: leftToRight|rightToLeft|topToBottom|bottomToTop, flipAlong, flipAcross) or Pattern (fields scale %, spacing %, fit: stretch|addSpace|approximate, flipAlong, flipAcross); Scatter, Art and Pattern also colorization: none|tints|tintsAndShades|hueShift, keyColor, and tips: true opens Colorization Tips (what each method does, beside a sample of the brush painted with it), as the Tips button beside Method does; OK runs brush.options",
),
(
"ui.brushObjectOptions",
@@ -9,7 +9,7 @@
//! eyedropper samples), `tips` (whether Colorization Tips is open).
//! Scatter: per value (`size`, `spacing`, `scatter` %, `rotation` °) `…Min`, `…Max` and `…Mode`
//! (`fixed` | `random` | `pressure` | `tilt` | `bearing` | `rotation`), `rotationRelativeTo` (`page` |
//! `path`), `hueJitter` (°), `saturationJitter` (%).
//! `path`), `hueJitter` (°), `saturationJitter` (%), `brightnessJitter` (%).
//! Art: `width` (%), `widthMode` (`fixed` | `pressure` | `tilt` | `bearing` | `rotation`),
//! `widthMax` (the width at the heaviest pen pressure, upright or at 180°, %), `scaleMode` (`proportional` | `stretch` | `betweenGuides`), `guideStart` and
//! `guideEnd` (% of the art's length), `direction` (`leftToRight` …), `flipAlong`, `flipAcross`,
@@ -204,6 +204,7 @@ pub(super) fn fields(b: &Brush, def: Value, f: &mut Map<String, Value>) {
f.insert("rotationRelativeTo".into(), json!(if s.rotation_relative_to_path { "path" } else { "page" }));
f.insert("hueJitter".into(), json!(s.hue_jitter));
f.insert("saturationJitter".into(), json!(s.saturation_jitter));
f.insert("brightnessJitter".into(), json!(s.brightness_jitter));
}
BrushKind::Art(a) => {
let (mode, start, end) = match a.scale {
@@ -295,6 +296,7 @@ pub(super) fn params(f: &DialogFields) -> Value {
p["modes"] = json!(SCATTER.map(|(key, _)| scatter_mode(f, key).id()));
p["hue_jitter"] = json!(clamped(f, "hueJitter", Scatter::HUE_JITTER_RANGE));
p["saturation_jitter"] = json!(clamped(f, "saturationJitter", Scatter::SATURATION_JITTER_RANGE));
p["brightness_jitter"] = json!(clamped(f, "brightnessJitter", Scatter::BRIGHTNESS_JITTER_RANGE));
p
}
"art" => {
@@ -486,6 +488,8 @@ fn scatter_rows() -> Vec<Param> {
rows.push(clamped_number("hueJitter", tl!("Hue Jitter"), Scatter::HUE_JITTER_RANGE, UnitKind::Degrees));
// Each copy moves its colors' saturation by its own amount up to this many points either way.
rows.push(clamped_number("saturationJitter", tl!("Saturation Jitter"), Scatter::SATURATION_JITTER_RANGE, UnitKind::Percent));
// Each copy moves its colors' brightness by its own amount up to this many points either way.
rows.push(clamped_number("brightnessJitter", tl!("Brightness Jitter"), Scatter::BRIGHTNESS_JITTER_RANGE, UnitKind::Percent));
rows
}
@@ -105,6 +105,7 @@ fn canceled_custom_numbers_and_variation_choices_do_not_reach_the_brush() {
("Bristle Round", "density", "Bristle Density:", "88", 88.0, "/density"),
("Confetti", "hueJitter", "Hue Jitter", "30", 30.0, "/hue_jitter"),
("Confetti", "saturationJitter", "Saturation Jitter", "30", 30.0, "/saturation_jitter"),
("Confetti", "brightnessJitter", "Brightness Jitter", "30", 30.0, "/brightness_jitter"),
] {
let mut app = app();
app.run("brush.options", json!({"name": brush, "params": {}})).unwrap();
@@ -279,7 +280,8 @@ fn dialog_fields_become_brush_options_params() {
vec![
(
vec![json!({"sizeMode": "fixed", "sizeMin": 5000, "spacingMode": "pressure", "scatterMode": "random", "rotationMode": "random",
"rotationMin": -400, "rotationRelativeTo": "path", "colorization": "hueShift", "hueJitter": 400, "saturationJitter": 400})],
"rotationMin": -400, "rotationRelativeTo": "path", "colorization": "hueShift", "hueJitter": 400, "saturationJitter": 400,
"brightnessJitter": 400})],
vec![
("/size", Is(json!([5000.0, 140.0]))),
("/rotation/0", Is(json!(-180.0))),
@@ -287,6 +289,7 @@ fn dialog_fields_become_brush_options_params() {
("/rotation_relative_to_path", Is(json!(true))),
("/hue_jitter", Is(json!(180.0))),
("/saturation_jitter", Is(json!(100.0))),
("/brightness_jitter", Is(json!(100.0))),
("/colorization/method", Is(json!("hueShift"))),
("/colorization/key", Object),
],
@@ -901,8 +904,8 @@ fn options_of_selected_object_set_one_paths_art_brush_settings() {
assert_eq!(own_options(&app, a), json!({"width": 50.0}));
}
/// Options of Selected Object shows a scatter path's hue and saturation jitter, and OK sets them on
/// that path only.
/// Options of Selected Object shows a scatter path's hue, saturation and brightness jitter, and OK
/// sets them on that path only.
#[test]
fn options_of_selected_object_set_one_paths_scatter_jitter() {
let mut app = app();
@@ -910,16 +913,21 @@ fn options_of_selected_object_set_one_paths_scatter_jitter() {
let b = brushed_line(&mut app, 100.0, "Confetti");
select(&mut app, &[a]);
app.run("ui.brushObjectOptions", json!({})).unwrap();
set(&mut app, json!({"hueJitter": 45, "saturationJitter": 30}));
set(&mut app, json!({"hueJitter": 45, "saturationJitter": 30, "brightnessJitter": 20}));
confirm(&mut app).unwrap();
assert_eq!(own_options(&app, a), json!({"hue_jitter": 45.0, "saturation_jitter": 30.0}));
assert_eq!(own_options(&app, a), json!({"hue_jitter": 45.0, "saturation_jitter": 30.0, "brightness_jitter": 20.0}));
assert_eq!(own_options(&app, b), json!({}));
let brush = app.run("brush.get", json!({"name": "Confetti"})).unwrap();
assert_eq!((brush["hue_jitter"].clone(), brush["saturation_jitter"].clone()), (json!(0.0), json!(0.0)), "the brush keeps its own");
assert_eq!(
(brush["hue_jitter"].clone(), brush["saturation_jitter"].clone(), brush["brightness_jitter"].clone()),
(json!(0.0), json!(0.0), json!(0.0)),
"the brush keeps its own"
);
// Opened again, it shows the path's own values.
app.run("ui.brushObjectOptions", json!({})).unwrap();
assert_eq!(fields_of(&app).number("saturationJitter"), Some(30.0));
assert_eq!(fields_of(&app).number("hueJitter"), Some(45.0));
assert_eq!(fields_of(&app).number("brightnessJitter"), Some(20.0));
}
#[test]
@@ -989,10 +997,10 @@ fn options_of_selected_object_show_what_a_path_can_set_for_each_type() {
assert!(keys.iter().any(|k| k == key), "{key} in {keys:?}");
}
assert!(!keys.iter().any(|k| k.ends_with("Tile")), "{keys:?}");
// Scatter: the four values with their modes, the rotation reference and the hue and saturation
// jitter.
// Scatter: the four values with their modes, the rotation reference and the hue, saturation and
// brightness jitter.
let keys = object_keys("scatter");
for key in ["sizeMin", "spacingMin", "scatterMin", "rotationMin", "rotationRelativeTo", "hueJitter", "saturationJitter"] {
for key in ["sizeMin", "spacingMin", "scatterMin", "rotationMin", "rotationRelativeTo", "hueJitter", "saturationJitter", "brightnessJitter"] {
assert!(keys.iter().any(|k| k == key), "{key} in {keys:?}");
}
let p = brushed_line(&mut app, 80.0, "Diamonds");
+1 -1
View File
@@ -1133,7 +1133,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
"ui.brushOptions",
"Brush Options…",
"",
"{name?} (default: the selected path's brush, else the current brush) open its Brush Options, what double-clicking a brush in the Brushes panel opens (dialog `brushOptions`): Calligraphic (fields name, angle −180..180, roundness 0..100, size 0..1296 pt, angleMode/roundnessMode/sizeMode: fixed|random|pressure, angleVariation/roundnessVariation/sizeVariation), Bristle (fields name, shape, size, length, density, thickness, opacity, stiffness), Scatter (fields sizeMin/sizeMax/sizeMode, spacingMin/spacingMax/spacingMode, scatterMin/scatterMax/scatterMode, rotationMin/rotationMax/rotationMode with modes fixed|random|pressure, rotationRelativeTo: page|path, hueJitter 0..180°, saturationJitter 0..100%), Art (fields width %, scaleMode: proportional|stretch|betweenGuides, guideStart/guideEnd % of the art length, direction: leftToRight|rightToLeft|topToBottom|bottomToTop, flipAlong, flipAcross) or Pattern (fields scale %, spacing %, fit: stretch|addSpace|approximate, flipAlong, flipAcross); Scatter, Art and Pattern also colorization: none|tints|tintsAndShades|hueShift, keyColor, and tips: true opens Colorization Tips (what each method does, beside a sample of the brush painted with it), as the Tips button beside Method does; OK runs brush.options",
"{name?} (default: the selected path's brush, else the current brush) open its Brush Options, what double-clicking a brush in the Brushes panel opens (dialog `brushOptions`): Calligraphic (fields name, angle −180..180, roundness 0..100, size 0..1296 pt, angleMode/roundnessMode/sizeMode: fixed|random|pressure, angleVariation/roundnessVariation/sizeVariation), Bristle (fields name, shape, size, length, density, thickness, opacity, stiffness), Scatter (fields sizeMin/sizeMax/sizeMode, spacingMin/spacingMax/spacingMode, scatterMin/scatterMax/scatterMode, rotationMin/rotationMax/rotationMode with modes fixed|random|pressure, rotationRelativeTo: page|path, hueJitter 0..180°, saturationJitter 0..100%, brightnessJitter 0..100%), Art (fields width %, scaleMode: proportional|stretch|betweenGuides, guideStart/guideEnd % of the art length, direction: leftToRight|rightToLeft|topToBottom|bottomToTop, flipAlong, flipAcross) or Pattern (fields scale %, spacing %, fit: stretch|addSpace|approximate, flipAlong, flipAcross); Scatter, Art and Pattern also colorization: none|tints|tintsAndShades|hueShift, keyColor, and tips: true opens Colorization Tips (what each method does, beside a sample of the brush painted with it), as the Tips button beside Method does; OK runs brush.options",
),
(
"ui.brushObjectOptions",
+15 -2
View File
@@ -4769,7 +4769,20 @@ already walks Image Trace. Short agent entry points:
saturation jitter on does not change the hue jitter's amounts. A stroke draws the same colors on every redraw,
after Save and Open, and in export, and the copies keep their places, sizes and rotations. A value outside the
range is clamped. A brush saves `saturation_jitter` only when it is above 0, a brush without the key reads as 0,
and `brush.get` shows it for every scatter brush. `brush.new` and `brush.options` take a bristle brush name of at most 31 characters:
and `brush.get` shows it for every scatter brush. A scatter brush's `brightness_jitter` (0 to 100 percent,
VectorCraft's own range; 0, the default, leaves every copy's colors as they are) moves the brightness of each
copy's solid fills and strokes, its type's characters included, by that copy's own amount between minus and plus
that many percentage points, after the colorization and the hue and saturation jitter. A color keeps its hue and
saturation and moves in its own model: RGB in the HSB of its values, Gray by that much less or more ink, Lab by
moving its lightness by that many units with its a and b kept, and CMYK by changing its K over the brightness its
C, M and Y leave, with C, M and Y changing only when the color goes brighter than they show with no K (they then
lose their K). The brightness stops at black and at full. Unlike the hue and saturation jitter, white, black and
grays move too. Gradients and patterns stay, and a moved color loses its swatch link. The amounts depend only on
the stroke's path and the brush's name, and they are drawn apart from the hue and saturation jitter's, so turning
brightness jitter on does not change their amounts. A stroke draws the same colors on every redraw, after Save and
Open, and in export, and the copies keep their places, sizes and rotations. A value outside the range is clamped.
A brush saves `brightness_jitter` only when it is above 0, a brush without the key reads as 0, and `brush.get`
shows it for every scatter brush. `brush.new` and `brush.options` take a bristle brush name of at most 31 characters:
`brush.new` refuses a longer one, counting the number it adds to a taken name, and `brush.options` refuses a
longer `newName`. `brush.duplicate` does not check the length. A bristle brush that already has a longer name
keeps it, and `brush.options` without a new name, or with a `newName` that only trims the white space around the
@@ -4791,7 +4804,7 @@ already walks Image Trace. Short agent entry points:
keep their settings. The fields a path can set are VectorCraft's own choice: calligraphic `angle` (counter-clockwise from
level), `roundness`, `size`, `variation` and `modes`; scatter `size`, `spacing`, `scatter`, `rotation`
(counter-clockwise), `modes`,
`rotation_relative_to_path`, `colorization`, `hue_jitter` and `saturation_jitter`; art `width`, `width_mode`, `width_max`, `flip_along`, `flip_across`,
`rotation_relative_to_path`, `colorization`, `hue_jitter`, `saturation_jitter` and `brightness_jitter`; art `width`, `width_mode`, `width_max`, `flip_along`, `flip_across`,
`overlap` and `colorization`; pattern `scale`, `spacing`, `fit`, `flip_along`, `flip_across` and `colorization`.
Values outside their ranges are clamped as in `brush.options`, a `colorization` object changes only the fields it
gives, a `null` item of an array (`size: [40, null]`) keeps each path's own item, else the brush's, and a setting
+1
View File
@@ -2205,6 +2205,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
Type in a scatter brush's art takes the brush's colorization as its paths do: Tints, Tints and Shades and Hue Shift recolor the characters' solid fills and strokes in each copy the brush draws, and Brush Options' Key Color list, whose first color is Hue Shift's default key, counts the characters' fills and their strokes wider than 0. The Brushes page says that a scatter, art or pattern brush takes its colors from the current stroke color and the brush's colorization method (<https://web.archive.org/web/20241230205225/https://helpx.adobe.com/illustrator/using/brushes.html>) and does not mention type there; recoloring the characters' paints like the art's fills and strokes is VectorCraft's own rule. The Symbol Stainer mixes the characters' strokes of type toward the stain as it mixes their fills. Evidence: `tests::scatter_colorization_recolors_type`, `tests::art_colors_list_the_most_used_first`, `tests::stain_mixes_type_strokes_too` (vectorcraft-brush).
Scatter Brush Options has Hue Jitter (0° to 180°, 0 by default), VectorCraft's own option: each copy turns the hue of its solid colors, after the colorization, by its own amount up to that far either way. The stroke's path and the brush name fix the amounts, so a stroke draws the same colors every time, and the copies' places, sizes and rotations stay as they are without it. Evidence: `tests::hue_jitter_turns_each_copy_the_same_every_time`, `tests::hue_jitter_of_zero_changes_nothing`, `tests::hue_jitter_turns_after_the_colorization` (vectorcraft-brush), `tests::brushsym::scatter_hue_jitter_saves_and_exports` (vectorcraft-engine).
Scatter Brush Options has Saturation Jitter (0% to 100%, 0 by default), VectorCraft's own option: each copy moves the saturation of its solid colors, after the colorization and the hue jitter, by its own amount up to that many points either way, keeping their hue and brightness. The stroke's path and the brush name fix the amounts, so a stroke draws the same colors every time. Options of Selected Object sets a path's own Hue Jitter and Saturation Jitter. Evidence: `tests::saturation_jitter_moves_each_copy_the_same_every_time`, `tests::saturation_jitter_of_zero_changes_nothing`, `tests::saturation_jitter_moves_after_the_colorization_in_each_model`, `tests::a_strokes_own_jitter_replaces_the_brushs` (vectorcraft-brush), `tests::brushsym::scatter_saturation_jitter_saves_and_exports` (vectorcraft-engine).
Scatter Brush Options has Brightness Jitter (0% to 100%, 0 by default), VectorCraft's own option: each copy moves the brightness of its solid colors, white, black and grays included, after the colorization and the hue and saturation jitter, by its own amount up to that many points either way, keeping their hue and saturation. The stroke's path and the brush name fix the amounts, so a stroke draws the same colors every time. Options of Selected Object sets a path's own Brightness Jitter. Evidence: `tests::brightness_jitter_moves_each_copy_the_same_every_time`, `tests::brightness_jitter_of_zero_changes_nothing`, `tests::brightness_jitter_moves_after_the_colorization_in_each_model` (vectorcraft-brush), `tests::brushsym::scatter_brightness_jitter_saves_and_exports` (vectorcraft-engine).
- **Pen tilt, bearing and rotation (part of #764):** Calligraphic and Scatter Brush Options offer Tilt, Bearing and Rotation beside Fixed, Random and Pressure. The Paintbrush records along each stroke how far the pen leans, which way, and how far its barrel is turned (kept with the path, saved, and joined when a stroke continues a path). A Calligraphic value on Tilt goes from value − variation with the pen lying flat to value + variation upright; on Bearing or Rotation it adds variation × the angle over 180°, so Angle on Bearing with a Variation of 180° turns the nib with the way the pen leans. A Scatter value goes from its first value to its second over the same ranges. A stroke without that input draws the brush's own value. On Linux under X11 and XWayland the app reads the tilt and an Art Pen's barrel rotation from XInput2, on macOS it reads them from AppKit's tablet events, and `path.freehand` points and `pointer_gesture` events carry them on every platform. The [Brushes](https://web.archive.org/web/20241230205225/https://helpx.adobe.com/illustrator/using/brushes.html) page defines the three options and does not say which way each one runs; that mapping is VectorCraft's own rule. Evidence: `tests::tilt_maps_to_roundness_along_the_stroke`, `tests::bearing_and_rotation_turn_the_nib`, `tests::scatter_values_follow_tilt_and_bearing` (vectorcraft-brush), `tests_brushsym::paintbrush_records_the_pens_tilt_on_the_stroke` (vectorcraft-engine), `tablet::tests::a_pens_tilt_and_rotation_go_into_the_feed` and `mac_tablet::tests::a_pens_tilt_and_rotation_go_into_the_feed` (vectorcraft).
Art Brush Options' Width (1% to 1000%) and Pattern Brush Options' Scale (1% to 10000%) each have a slider beside the field, over the same range in whole percents; screen readers name the slider as its row and read the field's value.
Art Brush Options' Width has a Fixed or Pressure menu, from the pen tablet options of the Width pop-up menu on the [Brushes](https://web.archive.org/web/20241230205225/https://helpx.adobe.com/illustrator/using/brushes.html) page (archived copy). With Pressure, the art is Width wide at the lightest pen pressure and the second width at the heaviest, following the pressure the Paintbrush recorded along the stroke, and half way between them on a stroke without recorded pressure (`brush.options` `width_mode` and `width_max`); a stroke inside the art takes the width at the middle of its object. The page does not say how the pressure maps to the width; taking the Scatter brush's minimum and maximum rule and the stroke rule are VectorCraft's own. The menu also offers Tilt, Bearing and Rotation: the art goes from Width with the pen lying flat to the second width upright, and from Width at −180° to the second width at 180° of the pen's bearing or barrel rotation, as Scatter Brush Options' modes do, and half way on a stroke without that input; the page does not say which way each runs, so that mapping is VectorCraft's own. Evidence: `tests::art_brush_width_follows_tilt_bearing_and_rotation` (vectorcraft-brush). The menu also offers Stylus Wheel (next item).