E534 feat(2d): custom arrow heads for Lines (Curves) (#380) by strau0106 · Pull Request #389 · motion-canvas/motion-canvas · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@strau0106
Copy link

Hi Everybody,

This PR allows custom arrow heads for lines via signals, as requested in #380.

Best,

Strau

if (this.endArrow() instanceof Node) {
const endArrow = this.endArrow() as Node;
endArrow.position(endPoint);
context.translate(endPoint.x, endPoint.y);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to find a way to scale the arrows down when there's not enough space on the line.
Otherwise animating the start/end parameters will be cumbersome.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you elaborate on that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try running the following example:

import {makeScene2D} from '@motion-canvas/2d';
import {Line} from '@motion-canvas/2d/lib/components';
import {all, waitFor} from '@motion-canvas/core/lib/flow';
import {createRef} from '@motion-canvas/core/lib/utils';

export default makeScene2D(function* (view) {
  const line = createRef<Line>();

  view.add(
    <Line
      ref={line}
      points={[
        [-400, 0],
        [400, 0],
      ]}
      lineWidth={8}
      stroke={'white'}
      startArrow
      endArrow
      arrowSize={100}
    />,
  );

  yield* all(
    line().start(1, 3),
    line().end(0, 3),
  );

  yield* waitFor(5);
});
Description Image
I exaggerated the size to better illustrate the effect. image
Notice that when the line passes through the point of zero length the arrows get scaled down image
Without that, it results in this ugly effect: image

This is done automatically so that you don't need to animate arrowSize each time this happens.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do this by scaling or "cutting off" the node, if it overlaps?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really sorry, I didn't notice your comment.
I think scaling down the node would be better because it would work even if the arrow exceeds the actual line (for example a circle whose center is placed at the end of the line).
You should be able to use Node.cacheBBox() to get the size of the node so that you know when to start scaling it down.

@ksassnowski
Copy link
Contributor

@strau0106 Are you still interested in finishing this PR? If not, I'd be happy to take it over from here.

@strau0106
Copy link
Author
strau0106 commented Mar 30, 2023 via email

@ksassnowski
Copy link
Contributor

No pressure! I just wanted to make sure the work you've done so far doesn't go to waste.

Regarding the merge conflicts: we recently extracted a Curve base class that Line now extends from (#594). So these changes should also go into the Curve class instead of Line. You should be able just cut/paste them from Line to Curve, though.

@strau0106
Copy link
Author
strau0106 commented Mar 30, 2023 via email

@strau0106 strau0106 closed this Mar 30, 2023
@strau0106 strau0106 force-pushed the feat2d-custom-arrow-heads branch from 2fcf225 to 1626811 Compare March 30, 2023 12:34
@strau0106 strau0106 reopened this Mar 30, 2023
@strau0106 strau0106 changed the title feat(2d): custom arrow heads for Lines (#380) feat(2d): custom arrow heads for Lines (Curves) (#380) Mar 30, 2023
@strau0106
Copy link
Author

@ksassnowski If this can wait for the next two weeks, I'll finish this PR. If not I am happy to leave it to you

*
* @remarks
* If `true`, a default arrow will be drawn. This can be used with the {@link arrowSize} signal to change the size of the arrow.
* If set to a {@link Node}, the node will be used as the arrow. This can be used to edraw a custom arrow. If a custom arrow is used, the {@link arrowSize} signal will be ignored.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* If set to a {@link Node}, the node will be used as the arrow. This can be used to edraw a custom arrow. If a custom arrow is used, the {@link arrowSize} signal will be ignored.
* If set to a {@link Node}, the node will be used as the arrow. This can be used to draw a custom arrow. If a custom arrow is used, the {@link arrowSize} signal will be ignored.

*
* @remarks
* If `true`, a default arrow will be drawn. This can be used with the {@link arrowSize} signal to change the size of the arrow.
* If set to a {@link Node}, the node will be used as the arrow. This can be used to edraw a custom arrow. If a custom arrow is used, the {@link arrowSize} signal will be ignored.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* If set to a {@link Node}, the node A016 will be used as the arrow. This can be used to edraw a custom arrow. If a custom arrow is used, the {@link arrowSize} signal will be ignored.
* If set to a {@link Node}, the node will be used as the arrow. This can be used to draw a custom arrow. If a custom arrow is used, the {@link arrowSize} signal will be ignored.

@ksassnowski
Copy link
Contributor

@strau0106 Fine with me. Take your time 👍

@ksassnowski
Copy link
Contributor

@strau0106 Any updates on this? My offer to take over still stands if you're too busy to continue working on this PR at the moment 👍

@strau0106
Copy link
Author
strau0106 commented Apr 28, 2023 via email

@ksassnowski
Copy link
Contributor

Then I'll take it from here. Nothing to be sorry about. Thanks for your work so far!

@ksassnowski
Copy link
Contributor

Closing this in favor of #629

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

0