Hello guys! I hope you are safe
I’m trying to hide a part of a shape I did using alpha mask but I have no idea how to achieve it.
My current result looks like that:
I want the black shape to act like an alpha mask and hide the white part behind it. I tried different solutions but didn’t manage to solve it
Here is my code:
// Responsive Canvas
function windowResized() {
var w = windowWidth / 1.5;
var h = w * 1.43;
if (windowHeight < h) {
h = windowHeight - (windowHeight / 10);
w = h / 1.43;
}
var cnv = createCanvas(w, h);
cnv.style('display', 'block');
}
var arColors = ['magenta', '#23fafa', '#456783']; // library of colors
let amt, startColor, newColor; // variables for color fading
function setup() {
windowResized();
rectMode(CENTER);
startColor = color(random(arColors)); // set start color
newColor = color(random(arColors)); // set new color
amt = 0;
}
function draw() {
var roundedCorner = width/30;
var centerH = height / 2;
var centerW = width / 2;
var marginWidth = width / 27;
background(0,0); // bacground transparent
// sign fill
fill(lerpColor(startColor, newColor, smoothstep(0.3,0.7,amt)));
amt += 0.01;
if(amt >= 1){
amt = 0.0;
startColor = newColor;
newColor = color(random(arColors));
}
// sign base
rect(centerW, centerH, width, height, roundedCorner);
noStroke();
// white path
var thickness = (height / 6.4) - marginWidth ;
var strokePosition = marginWidth + thickness/2;
strokeWeight(thickness);
strokeCap(ROUND);
strokeJoin(ROUND);
stroke(255);
noFill();
beginShape();
var n = 2.495;
var dist = 1.495;
vertex(width - strokePosition , strokePosition);
vertex(strokePosition, strokePosition);
vertex(strokePosition, strokePosition);
vertex(strokePosition , strokePosition * n);
vertex(strokePosition , strokePosition * n);
vertex(width - strokePosition , strokePosition * n);
vertex(width - strokePosition , strokePosition * n);
var n = n + dist;
vertex(width - strokePosition , strokePosition * n);
vertex(width - strokePosition , strokePosition * n);
vertex(strokePosition , strokePosition * n);
vertex(strokePosition , strokePosition * n);
n = n + dist;
vertex(strokePosition , strokePosition * n);
vertex(strokePosition , strokePosition * n);
vertex(width - strokePosition , strokePosition * n);
vertex(width - strokePosition , strokePosition * n);
n = n + dist;
vertex(width - strokePosition , strokePosition * n);
vertex(width - strokePosition , strokePosition * n);
vertex(strokePosition , strokePosition * n);
vertex(strokePosition , strokePosition * n);
n = n + dist;
vertex(strokePosition , strokePosition * n);
vertex(strokePosition , strokePosition * n);
vertex(width - strokePosition , strokePosition * n);
vertex(width - strokePosition , strokePosition * n);
n = n + dist;
vertex(width - strokePosition , strokePosition * n);
vertex(width - strokePosition , strokePosition * n);
vertex(strokePosition , strokePosition * n);
endShape();
noStroke();
// mask
fill(0);
noStroke();
beginShape();
vertex(marginWidth / 2 , (height - marginWidth) / 1.155);
vertex(marginWidth + width/12.75 , (height - marginWidth) / 1.155);
vertex(marginWidth + width/12.75 , (height - marginWidth) / 1.155);
vertex(marginWidth, strokePosition * n);
vertex(marginWidth, strokePosition * n);
vertex(marginWidth + width/12.75 , height - marginWidth);
vertex(marginWidth + width/12.75 , height - marginWidth);
vertex(marginWidth / 2 , height - marginWidth);
vertex(marginWidth / 2 , height - marginWidth);
vertex(marginWidth / 2 , (height - marginWidth) / 1.155);
endShape();
}
function smoothstep(edge0, edge1, m) {
m = constrain((m - edge0) / (edge1 - edge0), 0.0, 1.0);
return m * m * (3 - 2 * m);
}