Jump to content

Colorize complex shape


Laura
 Share

Recommended Posts

Hello!

I am developing an application with Angular and PIXI JS which generates bitmap fonts using bezier curves. The curves represent the outlines of my letter and supposing I am drawing the letter O as seen in the image I attached (it is not a stylish drawing, but you get the point), I would like to fill in with colour the interior of my drawing - the letter itself.

I have not found away to do it. I have tried to create a texture from my graphics and then a sprite from the texture, then adding a tint to the sprite, as follows:

const bezierTexture = renderer.generateTexture(this._splineGraphics); // convert shape to texture
const sprite = new PIXI.Sprite(bezierTexture);
this._stage.addChild(sprite);
sprite.texture = PIXI.Texture.WHITE;
sprite.tint = 0xFF0000;
sprite.width = this._width;
sprite.height = this._height;

However, this is tinting my entire canvas.

Thank you,

Laura

test (1).png

Link to comment
Share on other sites

Hello and Welcome to the forums!

> I would like to fill in with colour the interior of my drawing - the letter itself.

There's no such operation in canvas2d nor in webgl.

Yes, its possible to do that but this is not a basic operation. You have to learn many things like context2d getImageData putImageData and "breadth-first search" and how colors are encoded to do that.

However, there are many other ways to achieve what you want if you slightly change the input. Color-replace filters exist in pixi-filters, but they wont notice which is inner and which is outer. 

If you dont know what BFS is and how to do it on pixels - you have to change your input in photoshop - you have to do that operation in any of editors so you wont have to do it in JS side. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...