Skip to content
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

Arbitrary gradient transforms #28

Open
Herschel opened this issue May 16, 2022 · 3 comments
Open

Arbitrary gradient transforms #28

Herschel opened this issue May 16, 2022 · 3 comments

Comments

@Herschel
Copy link

Herschel commented May 16, 2022

It'd be nice if CanvasGradient could have an arbitrary transform. For example, this would allow for elliptical radial gradients or skewed gradients.

This is possible with the current canvas API in some situations by 1) tracing the path with lineTo etc., 2) calling context.transform(..), and 3) calling context.fill(), which transforms the gradient while not transforming the path. But this feels both roundabout and doesn't play nicely if you want to use Path2D.

Ideally there would be a CanvasGradient.transform method that accepts a DomMatrix similar to CanvasRenderingContext2d.transform. This would be analogous to SVG gradientTransform.

Another possibility would be to allow context.createPattern to accept a CanvasGradient, as CanvasPattern.setTransform already exists.

@Kaiido
Copy link

Kaiido commented May 16, 2022

Yes that would be nice.
Note that for Path2D you can still somehow hack around the situation by creating a new Path2D transformed by the inverse matrix you want to apply: https://jsfiddle.net/1t65ukea/

But I agree the API ought to offer a simpler way to do this.

@Herschel
Copy link
Author

The transform & inverse trick unfortunately doesn't help with applying a gradient style to strokes, because transforming the context transforms the stroke geometry itself, resulting in odd-looking width, joins, etc.: https://jsfiddle.net/mwelsh/7zLac8m3/9/

@mikerreed
Copy link

mikerreed commented May 18, 2022 via email

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

No branches or pull requests

3 participants