-
-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
decoration: Allow dynamic amplitudes #756
Conversation
3031c13
to
0c5a842
Compare
f34eda7
to
a9cb203
Compare
src/lib/decorations/path.typ
Outdated
@@ -59,6 +63,16 @@ | |||
factor: 150%, | |||
) | |||
|
|||
#let resolve-amplitude(amplitude, segment, num-segments) = { | |||
return if type(amplitude) == function { | |||
(amplitude)(segment / (num-segments - 1) * 100%) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now needs to be reverted back to (amplitude)(segment / num-segments * 100%)
, since segment
now ranges from 0.25
to num-segments + 0.75
😅
You can see what I mean with the test case
wave(line((0,3), (4,3)), amplitude: t => { calc.sin(t/100%*calc.pi) })
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I am playing around with it. With the .25 addition, you won't get 0%
/100%
in the callback, which is a bit unexpected, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the segment
variable is no longer an index, but rather the coordinate along the curve 0 <= t <= num-segments
4ef8457
to
bdfc993
Compare
src/lib/decorations/path.typ
Outdated
return if type(amplitude) == function { | ||
(amplitude)(segment / num-segments * 100%) | ||
} else if type(amplitude) == array { | ||
amplitude.at(calc.rem(int(segment), amplitude.len()), default: 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered amplitude.at(calc.rem(int(2*segment), amplitude.len()), default: 0)
? That gives the user control over individual peaks and troughs. With int(segment)
, you can only control them in full-wavelength pairs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just had one possible suggestion:
Have you considered
amplitude.at(calc.rem(int(2*segment), amplitude.len()), default: 0)
? That gives the user control over individual peaks and troughs. Withint(segment)
, you can only control them in full-wavelength pairs.
Will look into that. |
bdfc993
to
2233dc0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect:)
I think length
amplitudes should also be allowed, but I'm happy to make that a separate PR. It's just a matter of adding util.resolve-number(ctx, amplitude)
and adding some tests.
Allows passing a function of the form
ratio -> float
or an array of floats asamplitude:
to path decorations.Adds a
square
square-wave decoration.