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

consider adding char shape type (i.e. emoji) #82

Closed
catdad opened this issue Nov 22, 2019 · 2 comments
Closed

consider adding char shape type (i.e. emoji) #82

catdad opened this issue Nov 22, 2019 · 2 comments
Labels
feature request A neat new idea for this project help wanted Issue could use a contributor

Comments

@catdad
Copy link
Owner

catdad commented Nov 22, 2019

Example code:

function text(context, x, y, scaleX, scaleY, rotation, char) {
  context.setTransform(scaleX, 0, 0, scaleY, x, y);
  context.rotate(rotation);
  context.textAlign = 'center';
  context.font = 'normal normal 16px auto';
  context.fillText(char, 0, 0);
  context.setTransform(1,0,0,1,0,0);
}
...
text(context, fetti.x, fetti.y, Math.abs(x2 - x1) * 0.2, Math.abs(y2 - y1) * 0.2, Math.PI / 10 * fetti.wobble, fetti.shape.char);
...
confetti({
  shapes: [{ type: 'char', char: '💩' }]
});

I am guessing we'd need an additional font family argument.

This code has very poor performance. Any acceptable solution will need to solve that.

@catdad
Copy link
Owner Author

catdad commented Oct 2, 2023

Interesting... canvas has a createPattern() helper, which allows creating a pattern from an image. Then, the pattern has a setTransform(matrix) which allows manipulating that image directly instead of the entire canvas context. This, of course, means we need to rasterize the text ahead of time, but it's certainly better than that sprite branch. And this should be fast?

@catdad
Copy link
Owner Author

catdad commented Oct 5, 2023

This was shipped in version 1.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A neat new idea for this project help wanted Issue could use a contributor
Projects
None yet
Development

No branches or pull requests

1 participant