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

Can EraserBrush add hardness function? #50

Open
evenlan1990 opened this issue Dec 30, 2024 · 5 comments
Open

Can EraserBrush add hardness function? #50

evenlan1990 opened this issue Dec 30, 2024 · 5 comments

Comments

@evenlan1990
Copy link

No description provided.

@ShaMan123
Copy link
Owner

What is hardness?

@evenlan1990
Copy link
Author

@ShaMan123 Thanks for reply;
hardness is a key parameter used to control the brush edge effect. When drawing circular brush strokes, hardness determines the intensity of the color transition from the center to the edge of the brush, influencing whether the brush edge is soft or sharp.
• Values of hardness: Typically, hardness is a number ranging from 0 to 1:
• hardness = 1: The brush edge is completely hard (sharp) with almost no transition zone, similar to a solid circle brush.
• hardness = 0: The brush edge is completely soft, with the center fully opaque and the edge gradually transitioning to fully transparent.
• Intermediate values (e.g., hardness = 0.5): The color transition zone between the center and edge is wider, creating a semi-soft edge.

You can see from this picture that setting the hardness has different effects. I found a code, but I don't know how to combine it with the brush, code:
drawBrushPoint(drawingConfig: DrawingCircularConfig) {
const { ctx, x, y, radius, hardness } = drawingConfig;
const {
innerColor = REPAIR_POINT_INNER_COLOR,
outerColor = REPAIR_POINT_OUTER_COLOR,
} = drawingConfig;
ctx.beginPath();
const gradient = ctx.createRadialGradient(
x,
y,
GRADIENT_INNER_RADIUS,
x,
y,
radius
);
gradient.addColorStop(GRADIENT_BEGIN_OFFSET, innerColor);
gradient.addColorStop(hardness, innerColor);
gradient.addColorStop(GRADIENT_END_OFFSET, outerColor);
ctx.fillStyle = gradient;
ctx.arc(x, y, radius, ZERO_DEGREES, ONE_TURN_DEGREES);
ctx.fill();
}
image

@ShaMan123
Copy link
Owner

You can acheive this by subclassing the underlying PencilBrush methods.
I know of an integration with perfect-freehand but I am not sure this is what you want.
The erasing logic is built on top of the drawing logic and isn't coupled tightly or even at all.

@ShaMan123
Copy link
Owner

I did add an opacity level to erasing but it is global. You can try to manipulate that for your needs perhaps.

@evenlan1990
Copy link
Author

Yes, opacity is global. I will try to find a way to support gradient.

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

2 participants