hash is 0..0xff, x is 0.12 fixed point returns *.12 fixed-point value
| 72 | // hash is 0..0xff, x is 0.12 fixed point |
| 73 | // returns *.12 fixed-point value |
| 74 | static fl::i32 grad(fl::u8 hash, fl::i32 x) { |
| 75 | fl::u8 h = hash & 15; |
| 76 | fl::i32 grad = 1 + (h&7); // Gradient value 1.0, 2.0, ..., 8.0 |
| 77 | if ((h&8) != 0) { |
| 78 | grad = -grad; // Set a random sign for the gradient |
| 79 | } |
| 80 | return grad * x; // Multiply the gradient with the distance (integer * 0.12 = *.12) |
| 81 | } |
| 82 | |
| 83 | static fl::i32 grad(fl::u8 hash, fl::i32 x, fl::i32 y) { |
| 84 | fl::u8 h = hash & 7; // Convert low 3 bits of hash code |