diff --git a/src/lib/decorations/path.typ b/src/lib/decorations/path.typ index 706979bf..9a5a94eb 100644 --- a/src/lib/decorations/path.typ +++ b/src/lib/decorations/path.typ @@ -14,7 +14,11 @@ /// Length of a single segments segment-length: none, - /// Amplitude of a segment in the direction of the segments normal + /// Amplitude of a segment in the direction of the segments normal. + /// The following types are supported: + /// - float + /// - function ratio -> float (the segment ratio is given as argument) + /// - array of floats (the rounded segment ratio is used as index) amplitude: 1, /// Decoration start start: 0%, @@ -59,6 +63,16 @@ factor: 150%, ) +#let resolve-amplitude(amplitude, segment, num-segments) = { + return if type(amplitude) == function { + (amplitude)(segment / (num-segments - 1) * 100%) + } else if type(amplitude) == array { + amplitude.at(int(calc.max(0, calc.round(segment / (num-segments - 1) * (amplitude.len() - 1)))), default: 0) + } else { + amplitude + } +} + #let resolve-style(ctx, segments, style) = { assert(not (style.segments == none and style.segment-length == none), message: "Only one of segments or segment-length must be set, while the other must be auto") @@ -221,10 +235,9 @@ // list of points for the line-strip. let fn(i, a, b, norm) = { let ab = vector.sub(b, a) - let f = .25 - (50% - style.factor) / 50% * .25 let q-dir = vector.scale(ab, f) - let up = vector.scale(norm, style.amplitude / 2) + let up = vector.scale(norm, resolve-amplitude(style.amplitude, i, num-segments) / 2) let down = vector.scale(up, -1) let m1 = vector.add(vector.add(a, q-dir), up) @@ -301,7 +314,8 @@ // let fn(i, a, b, norm) = { let ab = vector.sub(b, a) - let up = vector.scale(norm, style.amplitude / 2) + let amplitude = resolve-amplitude(style.amplitude, i, num-segments) + let up = vector.scale(norm, amplitude / 2) let dist = vector.dist(a, b) let d = vector.norm(ab) @@ -381,7 +395,7 @@ // let fn(i, a, b, norm) = { let ab = vector.sub(b, a) - let up = vector.scale(norm, style.amplitude / 2) + let up = vector.scale(norm, resolve-amplitude(style.amplitude, i, num-segments) / 2) let down = vector.scale( up, -1) diff --git a/tests/decorations/path/ref/1.png b/tests/decorations/path/ref/1.png index 841a84a6..ff761e3f 100644 Binary files a/tests/decorations/path/ref/1.png and b/tests/decorations/path/ref/1.png differ diff --git a/tests/decorations/path/test.typ b/tests/decorations/path/test.typ index 8b6080e4..b4b9e381 100644 --- a/tests/decorations/path/test.typ +++ b/tests/decorations/path/test.typ @@ -9,6 +9,8 @@ zigzag(line((0,0), (4,0))) zigzag(line((0,1), (4,1)), amplitude: .5) + zigzag(line((0,2), (4,2)), amplitude: t => { 1 - .5 * t / 50% }) + zigzag(line((0,3), (4,3)), amplitude: (0, 1, 0, 1, 0)) })) #box(stroke: 2pt + red, canvas(length: 1cm, { @@ -16,6 +18,8 @@ wave(line((0,0), (4,0))) wave(line((0,1), (4,1)), amplitude: .5) + wave(line((0,2), (4,2)), amplitude: t => { 1 - .5 * t / 50% }) + wave(line((0,3), (4,3)), amplitude: (0, 1, 0, 1, 0)) })) #box(stroke: 2pt + red, canvas(length: 1cm, { @@ -23,6 +27,8 @@ coil(line((0,0), (4,0))) coil(line((0,1), (4,1)), amplitude: .5) + coil(line((0,2), (4,2)), amplitude: t => { 1 - .5 * t / 50% }) + coil(line((0,3), (4,3)), amplitude: (0, 1, 0, 1, 0)) })) #box(stroke: 2pt + red, canvas(length: 1cm, {