Hi,
Imagine I have a square with a diagonal line from the bottom left to the top right corner. Given any point (x,y), I want to be able to determine how far along that line the point is. This is because I want to create a colour gradient from one colour to another, from bottom left to top right of a square.
This image displays my working
here;
Given the arbitrary point (90,50), I believe I should calculate where the hypotenuse of the formed triangle begins along the square's hypotenuse. The point is directly diagonal, so it maps to position z along the square's hypotenuse.
Therefore I should be able to do the following to generate an RGB value:
$r = self::map(hypot($y, $y) + (hypot($x, $y) / 2), 0, hypot($imgW, $imgH), 0, 255);
$c = ImageColorAllocate($base_image, 0, $r, $r);
by mapping from 0 to the hypotenuse length, to 0-255.
Could anyone please help me to figure out why the output is this
here[
^]?
There are two issues; the gradient is completely wrong, and there are some black pixels in the bottom right which have seemingly chosen not to participate in this code.
What I have tried:
----------------------------------------------------