'P5.js: how to programatically calculate BURN blendMode between 2 colors?

I am doing some blendMode(BURN) to paint some shapes. And other shapes I need to painted directly in the resulting color of the previous shapes, so I need to generate the blended resulting color my self.

I am looking for something like:

let blendedColor = blendColorsBurn(color1, color2);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source