Documentation
¶
Index ¶
- Constants
- func Abs8(i int8) int8
- func Cos16(theta uint16) int16
- func Cos8(theta uint8) uint8
- func NScale8x3(r, g, b *uint8, scale uint8)
- func NScale8x3Video(r, g, b *uint8, scale uint8)
- func QAdd8(i, j uint8) uint8
- func QMul8(i, j uint8) uint8
- func QSub8(i, j uint8) uint8
- func Random16() uint16
- func Random16AddEntropy(entropy uint16)
- func Random16GetSeed() uint16
- func Random16Limit(lim uint16) uint16
- func Random16Range(min, lim uint16) uint16
- func Random16SetSeed(seed uint16)
- func Random8() uint8
- func Random8Limit(lim uint8) uint8
- func Random8Range(min, lim uint8) uint8
- func Scale16(i, scale uint16) uint16
- func Scale16By8(i uint16, scale uint8) uint16
- func Scale8(i uint8, scale uint8) uint8
- func Scale8Video(i, scale uint8) uint8
- func Sin16(theta uint16) int16
- func Sin8(theta uint8) uint8
- func Sqrt16(x uint16) uint8
Constants ¶
const PI16 uint16 = 32768
PI16 is the value of π in 16 bit math.
const PI8 uint8 = 127
PI8 is the value of π in 8 bit math.
Variables ¶
This section is empty.
Functions ¶
func Cos16 ¶
Cos16 is a fast 16-bit approximation of cos(x). This approximation never varies more than 0.69% from the floating point value.
Accepts theta input angle from 0-65535. Returns sin of theta, value between -32767 to 32767.
func Cos8 ¶
Cos8 is a fast 8-bit approximation of cos(x). This approximation never varies more than 2% from the floating point value.
Accepts theta input angle from 0-255 Returns sin of theta, value between 0 and 255
func NScale8x3 ¶
NScale8x3 scales three one byte values by a fourth one, which is treated as the numerator of a fraction whose demominator is 256. In other words, it computes r,g,b * (scale / 256).
func NScale8x3Video ¶
NScale8x3Video scale three one byte values by a fourth one, which is treated as the numerator of a fraction whose demominator is 256. In other words, it computes r,g,b * (scale / 256), ensuring that non-zero values passed in remain non zero, no matter how low the scale argument.
func QAdd8 ¶
QAdd8 adds one byte to another, saturating at 0xFF. Accepts: * i - first byte to add * j - second byte to add Returns the sum of i & j, capped at 0xFF
func QMul8 ¶
QMul8 performs saturating 8x8 bit multiplication, with 8 bit result. Returns the product of i * j, capping at 0xFF
func QSub8 ¶
QSub8 subtracts one byte from another, saturating at 0x00. Returns i - j with a floor of 0
func Random16AddEntropy ¶
func Random16AddEntropy(entropy uint16)
Random16AddEntropy adds entropy into the random number generator.
func Random16GetSeed ¶
func Random16GetSeed() uint16
Random16GetSeed gets the current seed value for the random number generator.
func Random16Limit ¶
Random16Limit generates an 16-bit random number between 0 and lim. Accepts lim the upper bound for the result
func Random16Range ¶
Random16Range generates an 16-bit random number in the given range. Accept min the lower bound for the random number Return lim the upper bound for the random number
func Random16SetSeed ¶
func Random16SetSeed(seed uint16)
Random16SetSeed sets the 16-bit seed used for the random number generator.
func Random8Limit ¶
Random8Limit generates an 8-bit random number between 0 and lim. Accept lim the upper bound for the result
func Random8Range ¶
Random8Range generates an 8-bit random number in the given range. Accepts min the lower bound for the random number Accepts lim the upper bound for the random number
func Scale16 ¶
Scale16 scales a 16-bit unsigned value by a 16-bit value, considered as numerator of a fraction whose denominator is 65536. In other words, it computes i * (scale / 65536).
func Scale16By8 ¶
Scale16By8 scales a 16-bit unsigned value by an 8-bit value, considered as numerator of a fraction whose denominator is 256. In other words, it computes i * (scale / 256).
func Scale8 ¶
Scale8 scales one byte by a second one, which is treated as the numerator of a fraction whose denominator is 256. In other words, it computes i * (scale / 256)
func Scale8Video ¶
Scale8Video is the "video" version of Scale8. Guarantees the output will be only be zero if one or both of the inputs are zero. If both inputs are non-zero, the output is guaranteed to be non-zero. This makes for better 'video'/LED dimming, at the cost of several additional cycles.
func Sin16 ¶
Sin16 is a fast 16-bit approximation of sin(x). This approximation never varies more than 0.69% from the floating point value.
This is a Golang translation of the FastLED lib8tion sin16_C() function. https://raw.githubusercontent.com/FastLED/FastLED/dcbf3993/lib8tion/trig8.h
Accepts theta input angle from 0-65535. Returns sin of theta, value between -32767 to 32767.
func Sin8 ¶
Sin8 is a fast 8-bit approximation of sin(x). This approximation never varies more than 2% from the floating point value.
This is a Golang translation of the FastLED lib8tion sin8_C() function. https://raw.githubusercontent.com/FastLED/FastLED/dcbf3993/lib8tion/trig8.h
Accepts theta input angle from 0-255. Returns sin of theta, value between 0 and 255
func Sqrt16 ¶
Sqrt16 finds the square root for 16-bit integers. This function is significantly slower, ~20X, on Intel/AMD CPUs. It should be much faster on a microcontroller though.
Note: Sqrt is implemented in assembly on some systems. Others have assembly stubs that jump to func sqrt below. On systems where Sqrt is a single instruction, the compiler may turn a direct call into a direct use of that instruction instead. src: https://golang.org/src/math/sqrt.go
Types ¶
This section is empty.