Merge pull request #9916 from dotCooCoo/feat/scatter-brush-saturation-jitter

Brushes: Scatter Brush Options has Saturation Jitter, a per-copy saturation move
This commit is contained in:
.CooCoo authored and GitHub committed 2026-11-28 08:02:10 -08:00
commit 072bce3489
14 files changed
+391 -32

No files matched your search

+70 -16
View File
@@ -121,14 +121,67 @@ pub fn colorize(n: &mut Node, mode: Colorization, stroke: &Paint) {
/// and a copy's size, spacing, scatter and rotation stay as they were without hue jitter.
const HUE_JITTER_SALT: u64 = 0x6875_655f_6a69_7474;
/// Turn the hue of each of `copies` (a scatter brush's copies, in order along the path) by its
/// own amount between −`amount` and `amount` degrees, drawn from `seed` (the stroke's
/// [`crate::track::seed_of`]).
pub(crate) fn jitter_hues(copies: &mut [Node], amount: f64, seed: u64) {
let mut rng = crate::track::Rng::new(seed ^ HUE_JITTER_SALT);
/// Mixed into a stroke's seed for its saturation jitter, so its amounts do not follow the hue
/// jitter's and the hue jitter's amounts stay as they were without it.
const SATURATION_JITTER_SALT: u64 = 0x7361_745f_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
/// is.
fn jitter_copies(copies: &mut [Node], amount: f64, seed: u64, salt: u64, adjust: fn(&Color, f32) -> Option<Color>) {
let mut rng = crate::track::Rng::new(seed ^ salt);
for n in copies {
let turn = rng.range(-amount, amount) as f32;
turn_hues(n, turn);
let by = rng.range(-amount, amount) as f32;
recolor_solids(n, &|c| adjust(c, by));
}
}
/// Turn the hue of each of `copies` by its own amount between −`amount` and `amount` degrees (see
/// [`jitter_copies`]).
pub(crate) fn jitter_hues(copies: &mut [Node], amount: f64, seed: u64) {
jitter_copies(copies, amount, seed, HUE_JITTER_SALT, turned);
}
/// Move the saturation of each of `copies` by its own amount between −`amount` and `amount`
/// percentage points (see [`jitter_copies`]).
pub(crate) fn jitter_saturations(copies: &mut [Node], amount: f64, seed: u64) {
jitter_copies(copies, amount, seed, SATURATION_JITTER_SALT, saturated);
}
/// The largest a or b a Lab color takes.
const LAB_AB_MAX: f64 = 127.0;
/// `c` with its saturation moved by `points` percentage points, worked out on its own components
/// 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).
fn saturated(c: &Color, points: f32) -> Option<Color> {
if !points.is_finite() || vectorcraft_color::recolor::Neutral::of(c).is_some() {
return None;
}
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]))
};
match *c {
Color::Rgb { r, g, b } => move_by([r, g, b]).map(|[r, g, b]| Color::rgb(r, g, b)),
Color::Cmyk { c, m, y, k } => move_by([1.0 - c, 1.0 - m, 1.0 - y]).map(|[r, g, b]| Color::cmyk(1.0 - r, 1.0 - g, 1.0 - b, k)),
Color::Gray { .. } => None,
Color::Lab { l, a, b } => {
let (a, b) = (f64::from(a), f64::from(b));
let chroma = a.hypot(b);
if chroma <= 0.0 {
return None;
}
// A longer chroma is cut back along the same hue angle until a and b fit; one that
// 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))
}
}
}
@@ -156,32 +209,33 @@ fn turned(c: &Color, degrees: f32) -> Option<Color> {
}
}
fn turn_paint(p: &mut Paint, degrees: f32) {
/// Replace a solid paint's color with what `adjust` gives for it, dropping its swatch link.
fn recolor_paint(p: &mut Paint, adjust: &dyn Fn(&Color) -> Option<Color>) {
if let Paint::Solid { color, .. } = p
&& let Some(c) = turned(color, degrees)
&& let Some(c) = adjust(color)
{
*p = Paint::solid(c);
}
}
/// Turn the hue of the solid fills and strokes under `n`, its type's characters included. A
/// Recolor the solid fills and strokes under `n` with `adjust`, its type's characters included. A
/// mask's colors are its values, so they stay.
fn turn_hues(n: &mut Node, degrees: f32) {
fn recolor_solids(n: &mut Node, adjust: &dyn Fn(&Color) -> Option<Color>) {
for it in &mut n.appearance.items {
match it {
AppearanceItem::Fill(f) => turn_paint(&mut f.paint, degrees),
AppearanceItem::Stroke(s) => turn_paint(&mut s.paint, degrees),
AppearanceItem::Fill(f) => recolor_paint(&mut f.paint, adjust),
AppearanceItem::Stroke(s) => recolor_paint(&mut s.paint, adjust),
}
}
if let NodeKind::Text(t) = &mut n.kind {
for r in &mut t.runs {
turn_paint(&mut r.style.fill, degrees);
turn_paint(&mut r.style.stroke, degrees);
recolor_paint(&mut r.style.fill, adjust);
recolor_paint(&mut r.style.stroke, adjust);
}
}
if let Some(ch) = n.children_mut() {
for c in ch.iter_mut() {
turn_hues(Arc::make_mut(c), degrees);
recolor_solids(Arc::make_mut(c), adjust);
}
}
}
+2
View File
@@ -173,6 +173,7 @@ pub fn defaults() -> &'static [Brush] {
rotation_relative_to_path: false,
colorization: Colorization::Tints,
hue_jitter: 0.0,
saturation_jitter: 0.0,
modes: None,
}),
},
@@ -187,6 +188,7 @@ pub fn defaults() -> &'static [Brush] {
rotation_relative_to_path: true,
colorization: Colorization::None,
hue_jitter: 0.0,
saturation_jitter: 0.0,
modes: None,
}),
},
+27 -5
View File
@@ -324,6 +324,14 @@ pub struct Scatter {
/// 0 (brushes saved before there was hue jitter) leaves the colors as they are.
#[serde(skip_serializing_if = "is_zero")]
pub hue_jitter: f64,
/// Saturation jitter in percent, 0 to 100: each copy moves the saturation of the solid colors it
/// draws, after the colorization and the hue jitter, by its own amount between
/// −`saturation_jitter` and `saturation_jitter` percentage points, 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. 0 (brushes saved before there was saturation jitter) leaves the colors as
/// they are.
#[serde(skip_serializing_if = "is_zero")]
pub saturation_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,
@@ -346,6 +354,7 @@ impl Default for Scatter {
rotation_relative_to_path: false,
colorization: Colorization::None,
hue_jitter: 0.0,
saturation_jitter: 0.0,
modes: None,
}
}
@@ -356,6 +365,8 @@ impl Scatter {
pub const RANGES: [(f64, f64); 4] = [(1.0, 10000.0), (1.0, 10000.0), (-1000.0, 1000.0), (-180.0, 180.0)];
/// The range of [`Scatter::hue_jitter`] (°).
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);
/// Size, spacing, scatter and rotation, each as its (first, second) values.
pub fn values(&self) -> [(f64, f64); 4] {
@@ -750,6 +761,7 @@ impl Brush {
s.scatter = within_pair(s.scatter, scatter, 0.0);
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.colorization.sanitize();
}
BrushKind::Art(a) => {
@@ -801,6 +813,8 @@ struct ScatterOptions {
modes: Option<[Variation; 4]>,
rotation_relative_to_path: bool,
colorization: Colorization,
hue_jitter: f64,
saturation_jitter: f64,
}
/// The Art brush fields a stroke can set for itself.
@@ -833,7 +847,9 @@ 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"],
BrushKind::Scatter(_) => {
&["size", "spacing", "scatter", "rotation", "modes", "rotation_relative_to_path", "colorization", "hue_jitter", "saturation_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(_) => &[],
@@ -858,6 +874,8 @@ impl BrushKind {
modes: s.modes,
rotation_relative_to_path: s.rotation_relative_to_path,
colorization: s.colorization,
hue_jitter: s.hue_jitter,
saturation_jitter: s.saturation_jitter,
}),
BrushKind::Art(a) => serde_json::to_value(ArtOptions {
width: a.width,
@@ -890,6 +908,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);
}
BrushKind::Art(a) => {
let o: ArtOptions = serde_json::from_value(v)?;
@@ -1130,10 +1149,13 @@ pub fn stroke_pieces(doc: &Document, brush: &Brush, bp: &BezPath, stroke: &Strok
colorize(n, colorization, &stroke.paint);
}
// One piece per copy, in the order the copies run along the path.
if let BrushKind::Scatter(s) = &brush.kind
&& s.hue_jitter > 0.0
{
colorize::jitter_hues(&mut out, s.hue_jitter, track::seed_of(bp, &brush.name));
if let BrushKind::Scatter(s) = &brush.kind {
if s.hue_jitter > 0.0 {
colorize::jitter_hues(&mut out, s.hue_jitter, track::seed_of(bp, &brush.name));
}
if s.saturation_jitter > 0.0 {
colorize::jitter_saturations(&mut out, s.saturation_jitter, track::seed_of(bp, &brush.name));
}
}
leave_out_brushed(doc, &mut out, &mut Known::new());
out
+183
View File
@@ -1249,6 +1249,189 @@ 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.
#[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));
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))])
);
// 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})));
assert!(!still.is_empty() && fill_colors(&still).iter().all(|c| *c == pink));
}
/// A scatter brush of rectangles filled `fill`, with `colorization`, `hue_jitter` and
/// `saturation_jitter`.
fn sat_jittered(fill: Color, colorization: Colorization, hue_jitter: f64, saturation_jitter: f64) -> Brush {
let mut b = jittered(fill, colorization, hue_jitter);
if let BrushKind::Scatter(s) = &mut b.kind {
s.saturation_jitter = saturation_jitter;
}
b
}
/// The HSB of an RGB color's own values.
fn rgb_hsb(c: &Color) -> [f32; 3] {
let Color::Rgb { r, g, b } = *c else { panic!("not RGB: {c:?}") };
vectorcraft_color::rgb_to_hsb([r, g, b])
}
#[test]
fn saturation_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 = sat_jittered(pink, Colorization::None, 0.0, 40.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 saturation is within 40 points of 50%; its hue and brightness stay.
assert!(hsb.iter().all(|[h, s, v]| hue_gap(*h, 0.0) < 1e-3 && (s - 0.5).abs() <= 0.4001 && near(f64::from(*v), 0.8, 1e-4)), "{hsb:?}");
assert!(hsb.iter().any(|[_, s, _]| *s > 0.55) && hsb.iter().any(|[_, s, _]| *s < 0.45), "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 gray or full saturation and go no further.
let full: Vec<f32> = fill_colors(&stroke_pieces(&doc, &sat_jittered(pink, Colorization::None, 0.0, 100.0), &path, &stroke(1.0)))
.iter()
.map(|c| rgb_hsb(c)[1])
.collect();
assert!(full.iter().all(|s| (0.0..=1.0).contains(s)), "{full:?}");
assert!(full.iter().any(|s| *s < 1e-6) && full.iter().any(|s| *s > 1.0 - 1e-6), "{full:?}");
// Saturation jitter leaves the hue jitter's amounts as they were.
let red = Color::rgb(1.0, 0.0, 0.0);
let hue_only = fill_colors(&stroke_pieces(&doc, &sat_jittered(red, Colorization::None, 90.0, 0.0), &path, &stroke(1.0)));
let both = fill_colors(&stroke_pieces(&doc, &sat_jittered(red, Colorization::None, 90.0, 50.0), &path, &stroke(1.0)));
assert_eq!(both.len(), hue_only.len());
assert_ne!(both, hue_only);
for (b, h) in both.iter().zip(&hue_only) {
assert!(hue_gap(rgb_hsb(b)[0], rgb_hsb(h)[0]) < 0.01, "{b:?} from {h:?}");
}
}
#[test]
fn saturation_jitter_of_zero_changes_nothing() {
let pink = Color::rgb(0.8, 0.4, 0.4);
let out = stroke_pieces(&Document::new(1.0, 1.0), &sat_jittered(pink, Colorization::None, 0.0, 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 saturation jitter is saved as before, and one saved before reads as 0.
let v = serde_json::to_value(sat_jittered(pink, Colorization::None, 0.0, 0.0)).unwrap();
assert!(v.get("saturation_jitter").is_none(), "{v}");
let mut old = serde_json::to_value(sat_jittered(pink, Colorization::None, 0.0, 25.0)).unwrap();
assert_eq!(old.as_object_mut().unwrap().remove("saturation_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.saturation_jitter, 0.0, "a brush saved without the key reads as 0");
let mut with = v.clone();
with["saturation_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.saturation_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["saturation_jitter"] = serde_json::json!(given);
let BrushKind::Scatter(s) = Brush::from_json(v).unwrap().kind else { panic!("not a scatter brush") };
assert_eq!(s.saturation_jitter, kept, "{given}");
}
}
#[test]
fn saturation_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);
// Tints: black art takes the blue stroke color, whose saturation then moves.
let blue = StrokeLayer::new(Paint::solid(Color::rgb(0.0, 0.0, 1.0)), 1.0);
let hsb: Vec<[f32; 3]> =
fill_colors(&stroke_pieces(&doc, &sat_jittered(Color::BLACK, Colorization::Tints, 0.0, 30.0), &path, &blue)).iter().map(rgb_hsb).collect();
assert!(!hsb.is_empty() && hsb.iter().all(|[h, s, _]| hue_gap(*h, 240.0) < 1e-3 && *s >= 0.6999), "{hsb:?}");
assert!(hsb.iter().any(|[_, s, _]| *s < 0.97), "{hsb:?}");
// Black, white and grays have no saturation to move, in every model.
for key in
[Color::rgb(0.5, 0.5, 0.5), Color::cmyk(0.0, 0.0, 0.0, 1.0), Color::cmyk(0.0, 0.0, 0.0, 0.5), Color::gray(0.4), Color::lab(60.0, 0.0, 0.0)]
{
let key = StrokeLayer::new(Paint::solid(key), 1.0);
let moved = stroke_pieces(&doc, &sat_jittered(Color::BLACK, Colorization::Tints, 0.0, 100.0), &path, &key);
let still = stroke_pieces(&doc, &sat_jittered(Color::BLACK, Colorization::Tints, 0.0, 0.0), &path, &key);
assert_eq!(fill_colors(&moved), fill_colors(&still), "{key:?}");
}
// A process color stays a process color with its K kept, moved over its C, M and Y.
let cmyk = fill_colors(&stroke_pieces(&doc, &sat_jittered(Color::cmyk(0.0, 0.6, 0.6, 0.25), Colorization::None, 0.0, 30.0), &path, &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:?}") };
// No cyan, as before, and magenta equal to yellow: the hue stays; the ink is within 30 points.
assert!(k == 0.25 && near(f64::from(c), 0.0, 1e-5) && near(f64::from(m), f64::from(y), 1e-5), "{c} {m} {y} {k}");
assert!((m - 0.6).abs() <= 0.3001, "{m}");
}
// A Lab color keeps its lightness and hue angle; its chroma moves within 20 of its 50.
let lab = fill_colors(&stroke_pieces(&doc, &sat_jittered(Color::lab(50.0, 40.0, 30.0), Colorization::None, 0.0, 20.0), &path, &stroke(1.0)));
assert!(lab.iter().any(|c| *c != Color::lab(50.0, 40.0, 30.0)), "{lab:?}");
for c in &lab {
let Color::Lab { l, a, b } = *c else { panic!("not Lab: {c:?}") };
let chroma = f64::from(a.hypot(b));
assert!(l == 50.0 && (chroma - 50.0).abs() <= 20.001 && near(f64::from(b.atan2(a)), 30f64.atan2(40.0), 1e-4), "{c:?}");
}
// A chroma that grows stops where a and b reach their largest.
let vivid = fill_colors(&stroke_pieces(&doc, &sat_jittered(Color::lab(50.0, 120.0, 0.0), Colorization::None, 0.0, 100.0), &path, &stroke(1.0)));
assert!(vivid.iter().all(|c| matches!(*c, Color::Lab { a, b, .. } if (0.0..=127.0001).contains(&a) && b.abs() < 1e-4)), "{vivid:?}");
assert!(vivid.iter().any(|c| matches!(*c, Color::Lab { a, .. } if a > 126.999)), "{vivid:?}");
}
/// Saturation jitter moves type's characters and a color linked to a swatch (which loses the
/// link); a pattern paint stays.
#[test]
fn saturation_jitter_moves_type_and_linked_colors() {
let doc = Document::new(1.0, 1.0);
let path = line(0.0, 0.0, 200.0, 0.0);
let red = Paint::solid(Color::rgb(1.0, 0.0, 0.0));
let typed = |saturation_jitter| Brush {
name: "s".into(),
kind: BrushKind::Scatter(Scatter { art: type_art(red.clone(), red.clone()), saturation_jitter, ..Default::default() }),
};
let still = run_paints(&stroke_pieces(&doc, &typed(0.0), &path, &stroke(1.0)));
let moved = run_paints(&stroke_pieces(&doc, &typed(60.0), &path, &stroke(1.0)));
assert!(!still.is_empty() && still.iter().all(|p| *p == (red.clone(), red.clone())), "{still:?}");
assert_eq!(moved.len(), still.len());
assert!(moved.iter().any(|p| *p != (red.clone(), red.clone())), "the characters move: {moved:?}");
assert!(moved.iter().all(|(f, s)| f == s), "a copy's character fill and stroke move by the same amount: {moved:?}");
let linked = Paint::Solid { color: Color::rgb(0.8, 0.4, 0.4), swatch: Some("Rose".into()), tint: 1.0 };
let pattern = Paint::Pattern { pattern: "Dots".into(), xf: Affine::IDENTITY };
let mut art = rect_art(10.0, 4.0);
art.appearance.set_fill(linked.clone());
art.appearance.set_stroke(pattern.clone());
let b = |saturation_jitter| Brush {
name: "s".into(),
kind: BrushKind::Scatter(Scatter { art: art.clone(), saturation_jitter, ..Default::default() }),
};
let moved = stroke_pieces(&doc, &b(50.0), &path, &stroke(1.0));
assert!(!moved.is_empty());
assert!(moved.iter().any(|n| n.appearance.fill_paint().color() != Some(Color::rgb(0.8, 0.4, 0.4))), "the linked color moves");
for n in &moved {
assert!(matches!(n.appearance.fill_paint(), Paint::Solid { swatch: None, .. }), "{:?}", n.appearance.fill_paint());
assert_eq!(n.appearance.stroke().map(|s| &s.paint), Some(&pattern));
}
}
/// 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). 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). 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; 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; 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 -1
View File
@@ -33,9 +33,11 @@ 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 jitter only when it is not 0; brush.get shows it either way.
// A scatter brush saves its hue and saturation 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));
}
Ok(v)
}
+38
View File
@@ -1810,6 +1810,44 @@ fn scatter_hue_jitter_saves_and_exports() {
assert_eq!(piece_fills(&s.doc().unwrap().doc, id), plain);
}
/// Scatter Brush Options' `saturation_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_saturation_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()["saturation_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": {"saturation_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": {"saturation_jitter": 40}})).unwrap();
assert_eq!(get(&mut s), json!(40.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": {"saturation_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
@@ -10388,6 +10388,7 @@ fn brush_library() -> Vec<vectorcraft_brush::Brush> {
rotation_relative_to_path: true,
colorization: Colorization::Tints,
hue_jitter: 0.0,
saturation_jitter: 0.0,
modes: Some([Variation::Random, Variation::Fixed, Variation::Pressure, Variation::Random]),
}),
},
@@ -10510,6 +10511,21 @@ fn a_scatter_brush_with_hue_jitter_is_left_out() {
assert_eq!(back.iter().map(|b| b.name.as_str()).collect::<Vec<_>>(), ["Nib", "Ribbon", "Plain ribbon"]);
}
/// Nor its saturation jitter: such a brush is left out and reported too.
#[test]
fn a_scatter_brush_with_saturation_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.saturation_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);
@@ -10841,6 +10857,7 @@ fn more_brush_settings_are_read_back() {
rotation_relative_to_path: false,
colorization: Colorization::None,
hue_jitter: 0.0,
saturation_jitter: 0.0,
modes: Some([Variation::Tilt, Variation::Bearing, Variation::Fixed, Variation::Rotation]),
};
let lib = vec![
+1 -1
View File
@@ -1126,7 +1126,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°), 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%), 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` (°).
//! `path`), `hueJitter` (°), `saturationJitter` (%).
//! 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`,
@@ -203,6 +203,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));
}
BrushKind::Art(a) => {
let (mode, start, end) = match a.scale {
@@ -293,6 +294,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
}
"art" => {
@@ -482,6 +484,8 @@ fn scatter_rows() -> Vec<Param> {
rows.push(Param::new("rotationRelativeTo", tl!("Rotation relative to"), ParamKind::radio(relative, Some("page".into()))));
// Each copy turns its colors' hue by its own amount up to this many degrees either way.
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));
rows
}
@@ -104,6 +104,7 @@ fn canceled_custom_numbers_and_variation_choices_do_not_reach_the_brush() {
("6 pt. Flat", "angle", "Angle:", "30", 30.0, "/angle"),
("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"),
] {
let mut app = app();
app.run("brush.options", json!({"name": brush, "params": {}})).unwrap();
@@ -278,13 +279,14 @@ 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})],
"rotationMin": -400, "rotationRelativeTo": "path", "colorization": "hueShift", "hueJitter": 400, "saturationJitter": 400})],
vec![
("/size", Is(json!([5000.0, 140.0]))),
("/rotation/0", Is(json!(-180.0))),
("/modes", Is(json!(["fixed", "pressure", "random", "random"]))),
("/rotation_relative_to_path", Is(json!(true))),
("/hue_jitter", Is(json!(180.0))),
("/saturation_jitter", Is(json!(100.0))),
("/colorization/method", Is(json!("hueShift"))),
("/colorization/key", Object),
],
@@ -899,6 +901,27 @@ 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.
#[test]
fn options_of_selected_object_set_one_paths_scatter_jitter() {
let mut app = app();
let a = brushed_line(&mut app, 50.0, "Confetti");
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}));
confirm(&mut app).unwrap();
assert_eq!(own_options(&app, a), json!({"hue_jitter": 45.0, "saturation_jitter": 30.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");
// 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));
}
#[test]
fn options_of_selected_object_change_only_the_values_edited_on_each_path() {
let mut app = app();
@@ -966,9 +989,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 jitter.
// Scatter: the four values with their modes, the rotation reference and the hue and saturation
// jitter.
let keys = object_keys("scatter");
for key in ["sizeMin", "spacingMin", "scatterMin", "rotationMin", "rotationRelativeTo", "hueJitter"] {
for key in ["sizeMin", "spacingMin", "scatterMin", "rotationMin", "rotationRelativeTo", "hueJitter", "saturationJitter"] {
assert!(keys.iter().any(|k| k == key), "{key} in {keys:?}");
}
let p = brushed_line(&mut app, 80.0, "Diamonds");
+1 -1
View File
@@ -1127,7 +1127,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°), 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%), 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",
+14 -2
View File
@@ -4715,7 +4715,19 @@ already walks Image Trace. Short agent entry points:
and the brush's name, so a stroke draws the same colors on every redraw, after Save and Open, and in export. Hue
jitter does not change where the copies go or their size and rotation. A value outside the range is clamped, as
the brush's other values are. A brush saves `hue_jitter` only when it is above 0, and a brush without the key
reads as 0; `brush.get` shows it for every scatter brush. `brush.new` and `brush.options` take a bristle brush name of at most 31 characters:
reads as 0; `brush.get` shows it for every scatter brush. A scatter brush's `saturation_jitter` (0 to 100
percent, VectorCraft's own range; 0, the default, leaves every copy's colors as they are) moves the saturation 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 jitter. A color keeps its hue and brightness
and moves in its own model: RGB in the HSB of its values, CMYK over its C, M and Y with its K kept, and Lab by
moving its chroma (the length of a and b) by that many units with its lightness and hue angle kept, with a and b
kept within 127. The saturation stops at none, which gives a gray, and at full. Colors without a hue (as for
`hue_jitter`) stay as they are, 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 jitter's, so turning
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:
`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
@@ -4737,7 +4749,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` and `colorization`; art `width`, `width_mode`, `width_max`, `flip_along`, `flip_across`,
`rotation_relative_to_path`, `colorization`, `hue_jitter` and `saturation_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
@@ -2199,6 +2199,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
Scale Proportionately art is scaled across by the stroke weight and the Width, as Stretch to Fit Stroke Length and Stretch Between Guides art is, on top of the scale the path length gives it, so a 3 pt stroke draws the art three times as wide as a 1 pt stroke. The [Brushes](https://web.archive.org/web/20241230205225/https://helpx.adobe.com/illustrator/using/brushes.html) page says Scale Proportionately keeps the art's proportions and does not say how the stroke weight applies; that rule is VectorCraft's own. Evidence: `tests::art_brush_proportional_grows_with_weight` (vectorcraft-brush).
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).
- **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).