How would i go forth with creating a logarithmic gradient that increases as I go farther from a point in javascript. I would also like to normalize the values of this gradient to stay between 0 and 1. As of right now I have the folllowing methods:
generateGradient(x, y) {
let distance = Math.sqrt(Math.pow((x - this.x), 2) + Math.pow((y - this.y), 2));
return distance;
}
This method is straightforward and just uses the distance formula from generic math Next I normalize these values to stay between zero and one:
normalize(x) {
let x_normalized = (x - this.x) / (width - this.x);
return Math.abs(x_normalized);
}
Both these methods work as expected, tested with this for loop:
var light = new lightSource(100, 100);
for (var i = light.x+1; i < width; i++) {
console.log(light.normalize(light.generateGradient(i, 100)));
}
The lightsource class is just a class with x and y variables that are used when instantiating it. The for loop generates values from 0 to 1 based on the distance, but how would I create a logarithmic regression.
I would like the values to increase exponentially as the distance increases