In addition, I still have the Sept 1986 issue of Scientific American, where A.K. Dewdney’s Mathematical Recreations article ‘Wallpaper for the Mind’ shows some pretty cool visuals. I wrote a demo around that on my PC (long since gone).
If you’re going to play with
data = sin®
then you’re going to need r, and to get r, you’re going to need square root, because
r = sqrt( dx^2 + dy^2 )
So: FastLED has an integer square root routine, called sqrt16
uint8_t sqrt16( uint16_t );
which is about 3X faster than the generic Arduino library routine on AVR.
Dan often reminds me that if all you’re doing is comparing distances, there’s often no need to do the sqrt step at all. But here I think for circular sine waves, it is needed. Let us know what you put together!
For the Too Bright Hat, I used:
steps++;
uint8_t dummy1 = 127 + fastSinLUT((int16_t)(column/scale+steps));
uint8_t dummy2 = 127 + fastSinLUT((int16_t)(row/scalefastSinLUT((int16_t)(steps/2))/2+column/scalefastCosLUT((int16_t)(steps/3))/2+steps));
uint8_t dummy3 = 127 + fastSinLUT((int16_t)((row/scalefastCosLUT((int16_t)(steps/2)))/4+(column/scalefastSinLUT((int16_t(steps/3)))/4+steps)));
uint16_t result = dummy1 + dummy2 + dummy3; // Between 0…765
And then scaled or companded that down to 0…255. As I’m not after subtlety, I used this plasma pattern for hue and just set brightness and saturation to maximum. I don’t have the timing to hand, but it happily runs 180 LEDs on a Teensy 3.0.
@Jez_Weston : FastLED V2.1 offers fast integer approximations for sines and cosines, in both
int16_t sin16( uint16_t );
and
uint8_t sin8( uint8_t );
styles. Worth a look, IMHO.
Well, a vector has two points, same as a line segment, but with a vector, one is the beginning and the other is the end. With a line segment, there’s no directionality to it.