MCPcopy Create free account
hub / github.com/FastLED/FastLED / grad

Function grad

src/simplex.cpp.hpp:74–81  ·  view source on GitHub ↗

hash is 0..0xff, x is 0.12 fixed point returns *.12 fixed-point value

Source from the content-addressed store, hash-verified

72// hash is 0..0xff, x is 0.12 fixed point
73// returns *.12 fixed-point value
74static 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
83static 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

Callers 1

snoise16Function · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected