Merge branch 'master' into bnb

This commit is contained in:
Thomas Kolb 2022-07-06 20:00:47 +02:00
commit 3b7e04fa3c
21 changed files with 756 additions and 116 deletions

2
.gitignore vendored
View file

@ -6,3 +6,5 @@
data/etc/* data/etc/*
!data/etc/.* !data/etc/.*
animation_test/build/

View file

@ -3,12 +3,14 @@ cmake_minimum_required(VERSION 3.5)
set(SOURCES set(SOURCES
src/Fader.cpp src/Fader.cpp
src/Animation/ImageScrollerAnimation.cpp src/Animation/RgbwPsychedelicAnimation.cpp
src/fasttrigon.cpp
src/main.cpp src/main.cpp
src/Animation/Animation.h src/Animation/Animation.h
src/Fader.h src/Fader.h
src/Animation/ImageScrollerAnimation.h src/Animation/RgbwPsychedelicAnimation.h
src/fasttrigon.h
) )
add_executable(animation_test ${SOURCES}) add_executable(animation_test ${SOURCES})

View file

@ -0,0 +1,92 @@
#include <algorithm>
//#include <iostream>
#include "Animation/RgbwPsychedelicAnimation.h"
RgbwPsychedelicAnimation::RgbwPsychedelicAnimation(Fader *fader,
const rgbw_val_array &move_speeds,
const rgbw_val_array &tilt_speeds,
int32_t tilt_maxperiods,
uint32_t move_speed_divider,
uint32_t tilt_speed_divider,
uint16_t brightness_scale)
: Animation(fader),
m_move_speeds(move_speeds),
m_tilt_speeds(move_speeds),
m_moveSpeedDivider(move_speed_divider),
m_tiltSpeedDivider(tilt_speed_divider),
m_brightnessScale(brightness_scale),
m_tilt_maxperiods(tilt_maxperiods),
m_move_phi{800,600,400,200},
m_tilt_phi{200,400,600,800},
m_moveOverflowInterval(fasttrigon::LUT_SIZE * move_speed_divider),
m_tiltOverflowInterval(fasttrigon::LUT_SIZE * tilt_speed_divider)
{
reset();
}
void RgbwPsychedelicAnimation::loop(uint64_t frame)
{
std::size_t nled = m_fader->modules_per_strip();
std::size_t nstrip = m_fader->strips();
if(!m_stopping) {
for(unsigned i = 0; i < m_move_speeds.size(); i++) {
m_move_phi[i] += m_move_speeds[i];
if(m_move_phi[i] > m_moveOverflowInterval) {
m_move_phi[i] -= m_moveOverflowInterval;
}
}
rgbw_val_array tilt_nperiods;
for(unsigned i = 0; i < m_tilt_speeds.size(); i++) {
m_tilt_phi[i] += m_tilt_speeds[i];
if(m_tilt_phi[i] > m_tiltOverflowInterval) {
m_tilt_phi[i] -= m_tiltOverflowInterval;
}
tilt_nperiods[i] = m_tilt_maxperiods * fasttrigon::fastsin(m_tilt_phi[i] / m_tiltSpeedDivider);
}
for(std::size_t led = 0; led < nled; led++) {
for(std::size_t strip = 0; strip < nstrip; strip++) {
int32_t x = fasttrigon::LUT_SIZE * led / nled;
int32_t y = fasttrigon::LUT_SIZE * strip / nstrip;
rgbw_val_array rgbw {
(fasttrigon::SCALE + fasttrigon::fastsin(m_move_phi[0] / m_moveSpeedDivider + ((x * tilt_nperiods[0]) >> fasttrigon::UNIT_SHIFT) + y)),
(fasttrigon::SCALE + fasttrigon::fastsin(m_move_phi[1] / m_moveSpeedDivider + ((x * tilt_nperiods[1]) >> fasttrigon::UNIT_SHIFT) + y)),
(fasttrigon::SCALE + fasttrigon::fastsin(m_move_phi[2] / m_moveSpeedDivider + ((x * tilt_nperiods[2]) >> fasttrigon::UNIT_SHIFT) + y)),
(fasttrigon::SCALE + fasttrigon::fastsin(m_move_phi[3] / m_moveSpeedDivider + ((x * tilt_nperiods[3]) >> fasttrigon::UNIT_SHIFT) + y))
};
Fader::Color color{
static_cast<int16_t>((FASTTRIGON_8BIT(rgbw[0] * rgbw[0] >> fasttrigon::UNIT_SHIFT) * m_brightnessScale) >> fasttrigon::PRECISION_BITS),
static_cast<int16_t>((FASTTRIGON_8BIT(rgbw[1] * rgbw[1] >> fasttrigon::UNIT_SHIFT) * m_brightnessScale) >> fasttrigon::PRECISION_BITS),
static_cast<int16_t>((FASTTRIGON_8BIT(rgbw[2] * rgbw[2] >> fasttrigon::UNIT_SHIFT) * m_brightnessScale) >> fasttrigon::PRECISION_BITS),
static_cast<int16_t>((FASTTRIGON_8BIT(rgbw[3] * rgbw[3] >> fasttrigon::UNIT_SHIFT) * m_brightnessScale) >> (fasttrigon::PRECISION_BITS + 2))}; // white is too bright otherwise
//std::cerr << rgbw[0] << " " << rgbw[1] << " " << rgbw[2] << " " << rgbw[3] << std::endl;
//std::cerr << color.r << " " << color.g << " " << color.b << " " << color.w << std::endl;
m_fader->set_color(strip, led, color);
}
}
} else {
m_fader->fade_color(Fader::Color{0, 0, 0, 0});
}
m_fader->update();
m_running = !m_stopping || m_fader->something_changed();
}
void RgbwPsychedelicAnimation::reset(void)
{
m_stopping = false;
m_running = true;
}

View file

@ -0,0 +1,46 @@
#pragma once
#include <array>
#include "Animation.h"
#include "fasttrigon.h"
class RgbwPsychedelicAnimation : public Animation
{
public:
typedef std::array<int32_t, 4> rgbw_val_array;
RgbwPsychedelicAnimation(Fader *fader,
const rgbw_val_array &move_speeds = {2273, 2281, 2287, 2293},
const rgbw_val_array &tilt_speeds = {2297, 2309, 2311, 2333},
int32_t tilt_maxperiods = 3,
uint32_t move_speed_divider = 1024,
uint32_t tilt_speed_divider = 8192,
uint16_t brightness_scale = fasttrigon::SCALE/4); // max: fasttrigon::SCALE
void loop(uint64_t frame) override;
void stop(void) override
{
m_stopping = true;
}
void reset(void) override;
private:
bool m_stopping;
rgbw_val_array m_move_speeds;
rgbw_val_array m_tilt_speeds;
uint32_t m_moveSpeedDivider;
uint32_t m_tiltSpeedDivider;
uint16_t m_brightnessScale;
int32_t m_tilt_maxperiods;
rgbw_val_array m_move_phi;
rgbw_val_array m_tilt_phi;
int32_t m_moveOverflowInterval;
int32_t m_tiltOverflowInterval;
};

View file

@ -104,7 +104,7 @@ void Fader::update(void)
target_addr.sin_family = AF_INET; target_addr.sin_family = AF_INET;
target_addr.sin_port = htons(2703); target_addr.sin_port = htons(2703);
target_addr.sin_addr.s_addr = inet_addr("10.42.7.145"); target_addr.sin_addr.s_addr = inet_addr("192.168.2.145");
int ret = sendto(m_fd, packet.data(), packet.size(), 0, reinterpret_cast<const sockaddr*>(&target_addr), sizeof(target_addr)); int ret = sendto(m_fd, packet.data(), packet.size(), 0, reinterpret_cast<const sockaddr*>(&target_addr), sizeof(target_addr));
if(ret == -1) { if(ret == -1) {

View file

@ -0,0 +1,213 @@
#include <array>
#include "fasttrigon.h"
namespace fasttrigon {
static const std::array<int16_t, LUT_SIZE> LUT {
0, 3, 6, 9, 12, 15, 18, 21, 25, 28, 31, 34, 37, 40, 43, 47, 50, 53, 56,
59, 62, 65, 68, 72, 75, 78, 81, 84, 87, 90, 94, 97, 100, 103, 106,
109, 112, 115, 118, 122, 125, 128, 131, 134, 137, 140, 143, 147,
150, 153, 156, 159, 162, 165, 168, 171, 174, 177, 181, 184, 187,
190, 193, 196, 199, 202, 205, 208, 211, 214, 218, 221, 224, 227,
230, 233, 236, 239, 242, 245, 248, 251, 254, 257, 260, 263, 266,
269, 272, 275, 278, 281, 284, 287, 290, 293, 296, 299, 302, 305,
308, 311, 314, 317, 320, 323, 326, 329, 332, 335, 338, 341, 344,
347, 350, 353, 356, 359, 362, 365, 368, 371, 374, 376, 379, 382,
385, 388, 391, 394, 397, 400, 403, 405, 408, 411, 414, 417, 420,
423, 426, 428, 431, 434, 437, 440, 443, 445, 448, 451, 454, 457,
459, 462, 465, 468, 471, 473, 476, 479, 482, 485, 487, 490, 493,
496, 498, 501, 504, 506, 509, 512, 515, 517, 520, 523, 525, 528,
531, 533, 536, 539, 541, 544, 547, 549, 552, 555, 557, 560, 563,
565, 568, 570, 573, 576, 578, 581, 583, 586, 589, 591, 594, 596,
599, 601, 604, 606, 609, 611, 614, 616, 619, 621, 624, 626, 629,
631, 634, 636, 639, 641, 644, 646, 648, 651, 653, 656, 658, 661,
663, 665, 668, 670, 672, 675, 677, 679, 682, 684, 687, 689, 691,
693, 696, 698, 700, 703, 705, 707, 709, 712, 714, 716, 718, 721,
723, 725, 727, 729, 732, 734, 736, 738, 740, 743, 745, 747, 749,
751, 753, 755, 757, 760, 762, 764, 766, 768, 770, 772, 774, 776,
778, 780, 782, 784, 786, 788, 790, 792, 794, 796, 798, 800, 802,
804, 806, 808, 810, 812, 814, 816, 817, 819, 821, 823, 825, 827,
829, 830, 832, 834, 836, 838, 839, 841, 843, 845, 847, 848, 850,
852, 854, 855, 857, 859, 860, 862, 864, 865, 867, 869, 870, 872,
874, 875, 877, 879, 880, 882, 883, 885, 886, 888, 890, 891, 893,
894, 896, 897, 899, 900, 902, 903, 905, 906, 908, 909, 910, 912,
913, 915, 916, 917, 919, 920, 922, 923, 924, 926, 927, 928, 930,
931, 932, 933, 935, 936, 937, 939, 940, 941, 942, 943, 945, 946,
947, 948, 949, 951, 952, 953, 954, 955, 956, 957, 958, 959, 961,
962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974,
975, 976, 977, 978, 978, 979, 980, 981, 982, 983, 984, 985, 985,
986, 987, 988, 989, 990, 990, 991, 992, 993, 993, 994, 995, 996,
996, 997, 998, 998, 999, 1000, 1000, 1001, 1002, 1002, 1003, 1003,
1004, 1005, 1005, 1006, 1006, 1007, 1007, 1008, 1008, 1009, 1010,
1010, 1010, 1011, 1011, 1012, 1012, 1013, 1013, 1014, 1014, 1014,
1015, 1015, 1016, 1016, 1016, 1017, 1017, 1017, 1018, 1018, 1018,
1018, 1019, 1019, 1019, 1019, 1020, 1020, 1020, 1020, 1021, 1021,
1021, 1021, 1021, 1021, 1022, 1022, 1022, 1022, 1022, 1022, 1022,
1022, 1022, 1022, 1022, 1022, 1022, 1022, 1023, 1022, 1022, 1022,
1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022,
1021, 1021, 1021, 1021, 1021, 1021, 1020, 1020, 1020, 1020, 1019,
1019, 1019, 1019, 1018, 1018, 1018, 1018, 1017, 1017, 1017, 1016,
1016, 1016, 1015, 1015, 1014, 1014, 1014, 1013, 1013, 1012, 1012,
1011, 1011, 1010, 1010, 1010, 1009, 1008, 1008, 1007, 1007, 1006,
1006, 1005, 1005, 1004, 1003, 1003, 1002, 1002, 1001, 1000, 1000,
999, 998, 998, 997, 996, 996, 995, 994, 993, 993, 992, 991, 990,
990, 989, 988, 987, 986, 985, 985, 984, 983, 982, 981, 980, 979,
978, 978, 977, 976, 975, 974, 973, 972, 971, 970, 969, 968, 967,
966, 965, 964, 963, 962, 961, 959, 958, 957, 956, 955, 954, 953,
952, 951, 949, 948, 947, 946, 945, 943, 942, 941, 940, 939, 937,
936, 935, 933, 932, 931, 930, 928, 927, 926, 924, 923, 922, 920,
919, 917, 916, 915, 913, 912, 910, 909, 908, 906, 905, 903, 902,
900, 899, 897, 896, 894, 893, 891, 890, 888, 886, 885, 883, 882,
880, 879, 877, 875, 874, 872, 870, 869, 867, 865, 864, 862, 860,
859, 857, 855, 854, 852, 850, 848, 847, 845, 843, 841, 839, 838,
836, 834, 832, 830, 829, 827, 825, 823, 821, 819, 817, 816, 814,
812, 810, 808, 806, 804, 802, 800, 798, 796, 794, 792, 790, 788,
786, 784, 782, 780, 778, 776, 774, 772, 770, 768, 766, 764, 762,
760, 757, 755, 753, 751, 749, 747, 745, 743, 740, 738, 736, 734,
732, 729, 727, 725, 723, 721, 718, 716, 714, 712, 709, 707, 705,
703, 700, 698, 696, 693, 691, 689, 687, 684, 682, 679, 677, 675,
672, 670, 668, 665, 663, 661, 658, 656, 653, 651, 648, 646, 644,
641, 639, 636, 634, 631, 629, 626, 624, 621, 619, 616, 614, 611,
609, 606, 604, 601, 599, 596, 594, 591, 589, 586, 583, 581, 578,
576, 573, 570, 568, 565, 563, 560, 557, 555, 552, 549, 547, 544,
541, 539, 536, 533, 531, 528, 525, 523, 520, 517, 515, 512, 509,
506, 504, 501, 498, 496, 493, 490, 487, 485, 482, 479, 476, 473,
471, 468, 465, 462, 459, 457, 454, 451, 448, 445, 443, 440, 437,
434, 431, 428, 426, 423, 420, 417, 414, 411, 408, 405, 403, 400,
397, 394, 391, 388, 385, 382, 379, 376, 374, 371, 368, 365, 362,
359, 356, 353, 350, 347, 344, 341, 338, 335, 332, 329, 326, 323,
320, 317, 314, 311, 308, 305, 302, 299, 296, 293, 290, 287, 284,
281, 278, 275, 272, 269, 266, 263, 260, 257, 254, 251, 248, 245,
242, 239, 236, 233, 230, 227, 224, 221, 218, 214, 211, 208, 205,
202, 199, 196, 193, 190, 187, 184, 181, 177, 174, 171, 168, 165,
162, 159, 156, 153, 150, 147, 143, 140, 137, 134, 131, 128, 125,
122, 118, 115, 112, 109, 106, 103, 100, 97, 94, 90, 87, 84, 81, 78,
75, 72, 68, 65, 62, 59, 56, 53, 50, 47, 43, 40, 37, 34, 31, 28, 25,
21, 18, 15, 12, 9, 6, 3, 0, -3, -6, -9, -12, -15, -18, -21, -25,
-28, -31, -34, -37, -40, -43, -47, -50, -53, -56, -59, -62, -65,
-68, -72, -75, -78, -81, -84, -87, -90, -94, -97, -100, -103, -106,
-109, -112, -115, -118, -122, -125, -128, -131, -134, -137, -140,
-143, -147, -150, -153, -156, -159, -162, -165, -168, -171, -174,
-177, -181, -184, -187, -190, -193, -196, -199, -202, -205, -208,
-211, -214, -218, -221, -224, -227, -230, -233, -236, -239, -242,
-245, -248, -251, -254, -257, -260, -263, -266, -269, -272, -275,
-278, -281, -284, -287, -290, -293, -296, -299, -302, -305, -308,
-311, -314, -317, -320, -323, -326, -329, -332, -335, -338, -341,
-344, -347, -350, -353, -356, -359, -362, -365, -368, -371, -374,
-376, -379, -382, -385, -388, -391, -394, -397, -400, -403, -405,
-408, -411, -414, -417, -420, -423, -426, -428, -431, -434, -437,
-440, -443, -445, -448, -451, -454, -457, -459, -462, -465, -468,
-471, -473, -476, -479, -482, -485, -487, -490, -493, -496, -498,
-501, -504, -506, -509, -512, -515, -517, -520, -523, -525, -528,
-531, -533, -536, -539, -541, -544, -547, -549, -552, -555, -557,
-560, -563, -565, -568, -570, -573, -576, -578, -581, -583, -586,
-589, -591, -594, -596, -599, -601, -604, -606, -609, -611, -614,
-616, -619, -621, -624, -626, -629, -631, -634, -636, -639, -641,
-644, -646, -648, -651, -653, -656, -658, -661, -663, -665, -668,
-670, -672, -675, -677, -679, -682, -684, -687, -689, -691, -693,
-696, -698, -700, -703, -705, -707, -709, -712, -714, -716, -718,
-721, -723, -725, -727, -729, -732, -734, -736, -738, -740, -743,
-745, -747, -749, -751, -753, -755, -757, -760, -762, -764, -766,
-768, -770, -772, -774, -776, -778, -780, -782, -784, -786, -788,
-790, -792, -794, -796, -798, -800, -802, -804, -806, -808, -810,
-812, -814, -816, -817, -819, -821, -823, -825, -827, -829, -830,
-832, -834, -836, -838, -839, -841, -843, -845, -847, -848, -850,
-852, -854, -855, -857, -859, -860, -862, -864, -865, -867, -869,
-870, -872, -874, -875, -877, -879, -880, -882, -883, -885, -886,
-888, -890, -891, -893, -894, -896, -897, -899, -900, -902, -903,
-905, -906, -908, -909, -910, -912, -913, -915, -916, -917, -919,
-920, -922, -923, -924, -926, -927, -928, -930, -931, -932, -933,
-935, -936, -937, -939, -940, -941, -942, -943, -945, -946, -947,
-948, -949, -951, -952, -953, -954, -955, -956, -957, -958, -959,
-961, -962, -963, -964, -965, -966, -967, -968, -969, -970, -971,
-972, -973, -974, -975, -976, -977, -978, -978, -979, -980, -981,
-982, -983, -984, -985, -985, -986, -987, -988, -989, -990, -990,
-991, -992, -993, -993, -994, -995, -996, -996, -997, -998, -998,
-999, -1000, -1000, -1001, -1002, -1002, -1003, -1003, -1004,
-1005, -1005, -1006, -1006, -1007, -1007, -1008, -1008, -1009,
-1010, -1010, -1010, -1011, -1011, -1012, -1012, -1013, -1013,
-1014, -1014, -1014, -1015, -1015, -1016, -1016, -1016, -1017,
-1017, -1017, -1018, -1018, -1018, -1018, -1019, -1019, -1019,
-1019, -1020, -1020, -1020, -1020, -1021, -1021, -1021, -1021,
-1021, -1021, -1022, -1022, -1022, -1022, -1022, -1022, -1022,
-1022, -1022, -1022, -1022, -1022, -1022, -1022, -1023, -1022,
-1022, -1022, -1022, -1022, -1022, -1022, -1022, -1022, -1022,
-1022, -1022, -1022, -1022, -1021, -1021, -1021, -1021, -1021,
-1021, -1020, -1020, -1020, -1020, -1019, -1019, -1019, -1019,
-1018, -1018, -1018, -1018, -1017, -1017, -1017, -1016, -1016,
-1016, -1015, -1015, -1014, -1014, -1014, -1013, -1013, -1012,
-1012, -1011, -1011, -1010, -1010, -1010, -1009, -1008, -1008,
-1007, -1007, -1006, -1006, -1005, -1005, -1004, -1003, -1003,
-1002, -1002, -1001, -1000, -1000, -999, -998, -998, -997, -996,
-996, -995, -994, -993, -993, -992, -991, -990, -990, -989, -988,
-987, -986, -985, -985, -984, -983, -982, -981, -980, -979, -978,
-978, -977, -976, -975, -974, -973, -972, -971, -970, -969, -968,
-967, -966, -965, -964, -963, -962, -961, -959, -958, -957, -956,
-955, -954, -953, -952, -951, -949, -948, -947, -946, -945, -943,
-942, -941, -940, -939, -937, -936, -935, -933, -932, -931, -930,
-928, -927, -926, -924, -923, -922, -920, -919, -917, -916, -915,
-913, -912, -910, -909, -908, -906, -905, -903, -902, -900, -899,
-897, -896, -894, -893, -891, -890, -888, -886, -885, -883, -882,
-880, -879, -877, -875, -874, -872, -870, -869, -867, -865, -864,
-862, -860, -859, -857, -855, -854, -852, -850, -848, -847, -845,
-843, -841, -839, -838, -836, -834, -832, -830, -829, -827, -825,
-823, -821, -819, -817, -816, -814, -812, -810, -808, -806, -804,
-802, -800, -798, -796, -794, -792, -790, -788, -786, -784, -782,
-780, -778, -776, -774, -772, -770, -768, -766, -764, -762, -760,
-757, -755, -753, -751, -749, -747, -745, -743, -740, -738, -736,
-734, -732, -729, -727, -725, -723, -721, -718, -716, -714, -712,
-709, -707, -705, -703, -700, -698, -696, -693, -691, -689, -687,
-684, -682, -679, -677, -675, -672, -670, -668, -665, -663, -661,
-658, -656, -653, -651, -648, -646, -644, -641, -639, -636, -634,
-631, -629, -626, -624, -621, -619, -616, -614, -611, -609, -606,
-604, -601, -599, -596, -594, -591, -589, -586, -583, -581, -578,
-576, -573, -570, -568, -565, -563, -560, -557, -555, -552, -549,
-547, -544, -541, -539, -536, -533, -531, -528, -525, -523, -520,
-517, -515, -512, -509, -506, -504, -501, -498, -496, -493, -490,
-487, -485, -482, -479, -476, -473, -471, -468, -465, -462, -459,
-457, -454, -451, -448, -445, -443, -440, -437, -434, -431, -428,
-426, -423, -420, -417, -414, -411, -408, -405, -403, -400, -397,
-394, -391, -388, -385, -382, -379, -376, -374, -371, -368, -365,
-362, -359, -356, -353, -350, -347, -344, -341, -338, -335, -332,
-329, -326, -323, -320, -317, -314, -311, -308, -305, -302, -299,
-296, -293, -290, -287, -284, -281, -278, -275, -272, -269, -266,
-263, -260, -257, -254, -251, -248, -245, -242, -239, -236, -233,
-230, -227, -224, -221, -218, -214, -211, -208, -205, -202, -199,
-196, -193, -190, -187, -184, -181, -177, -174, -171, -168, -165,
-162, -159, -156, -153, -150, -147, -143, -140, -137, -134, -131,
-128, -125, -122, -118, -115, -112, -109, -106, -103, -100, -97,
-94, -90, -87, -84, -81, -78, -75, -72, -68, -65, -62, -59, -56,
-53, -50, -47, -43, -40, -37, -34, -31, -28, -25, -21, -18, -15,
-12, -9, -6, -3
};
int32_t fastsin(int32_t arg)
{
bool neg = arg < 0;
uint32_t idx;
if(neg) {
idx = (-arg) % LUT_SIZE;
return -LUT[idx];
} else {
idx = arg % LUT_SIZE;
return LUT[idx];
}
}
int32_t fastcos(int32_t arg)
{
return fastsin(arg + LUT_SIZE/4);
}
int32_t fasttan(int32_t arg)
{
int32_t denom = fastcos(arg);
if(denom == 0) {
return 0x7FFFFFFF;
}
int32_t numer = fastsin(arg);
return numer * 127 / denom;
}
}

View file

@ -0,0 +1,39 @@
/*!
* \file
*
* This file contains function prototypes for very fast lookup-table based
* trigonometric functions.
*
* The functions take an argument that is dependent on the lookup-table size
* (LUT_SIZE). LUT_SIZE corresponds to 2π. Values outside the range
* [0..LUT_SIZE] are supported and interpreted normally, so just replace 2π
* with LUT_SIZE and you're done.
*/
#pragma once
#include <cstdint>
#define FASTTRIGON_8BIT(x) (x >> (fasttrigon::PRECISION_BITS - 8))
namespace fasttrigon {
static const uint32_t LUT_SIZE = 2048;
static const uint32_t PRECISION_BITS = 11;
static const int32_t SCALE = 1023;
static const uint32_t UNIT_SHIFT = PRECISION_BITS-1;
/*!
* \returns 127 * sin(2π * arg / LUT_SIZE)
*/
int32_t fastsin(int32_t arg);
/*!
* \returns 127 * cos(2π * arg / LUT_SIZE)
*/
int32_t fastcos(int32_t arg);
/*!
* \returns 127 * tan(2π * arg / LUT_SIZE)
*/
int32_t fasttan(int32_t arg);
}

View file

@ -3,35 +3,13 @@
#include <unistd.h> #include <unistd.h>
#include "Fader.h" #include "Fader.h"
#include "Animation/ImageScrollerAnimation.h" #include "Animation/RgbwPsychedelicAnimation.h"
int main(void) int main(void)
{ {
Fader fader(8, 16); Fader fader(8, 16);
ImageScrollerAnimation::Image img(12, 3); Animation *animation = new RgbwPsychedelicAnimation(&fader);
img.pixel( 0 + 1, 0).r = 48;
img.pixel( 0 + 2, 1).r = 48;
img.pixel( 0 + 0, 2).r = 48;
img.pixel( 0 + 1, 2).r = 48;
img.pixel( 0 + 2, 2).r = 48;
img.pixel( 3 + 1, 0).g = 48;
img.pixel( 3 + 2, 1).g = 48;
img.pixel( 3 + 0, 2).g = 48;
img.pixel( 3 + 1, 2).g = 48;
img.pixel( 3 + 2, 2).g = 48;
img.pixel( 6 + 1, 0).b = 48;
img.pixel( 6 + 2, 1).b = 48;
img.pixel( 6 + 0, 2).b = 48;
img.pixel( 6 + 1, 2).b = 48;
img.pixel( 6 + 2, 2).b = 48;
img.pixel( 9 + 1, 0).w = 48;
img.pixel( 9 + 2, 1).w = 48;
img.pixel( 9 + 0, 2).w = 48;
img.pixel( 9 + 1, 2).w = 48;
img.pixel( 9 + 2, 2).w = 48;
Animation *animation = new ImageScrollerAnimation(&fader, &img);
for(uint64_t frame = 0; !animation->finished(); frame++) { for(uint64_t frame = 0; !animation->finished(); frame++) {
animation->loop(frame); animation->loop(frame);
@ -40,11 +18,11 @@ int main(void)
fader.update(); fader.update();
} }
if(frame == 3000) { if(frame == 60 * 90000) {
animation->stop(); animation->stop();
} }
usleep(100000); usleep(16667);
}; };
delete animation; delete animation;

View file

@ -8,6 +8,7 @@
#include "ImageScrollerAnimation.h" #include "ImageScrollerAnimation.h"
#include "MatrixCodeAnimation.h" #include "MatrixCodeAnimation.h"
#include "RgbwSinusAnimation.h" #include "RgbwSinusAnimation.h"
#include "RgbwPsychedelicAnimation.h"
#include "SnowfallAnimation.h" #include "SnowfallAnimation.h"
#include "StellarAnimation.h" #include "StellarAnimation.h"
#include "ChristmasGlitterAnimation.h" #include "ChristmasGlitterAnimation.h"

View file

@ -20,7 +20,8 @@ class AnimationController
FIREWORK = 5, FIREWORK = 5,
STELLAR = 6, STELLAR = 6,
RGBW_SINUS = 7, RGBW_SINUS = 7,
CHRISTMAS_GLITTER = 8, RGBW_PSYCHEDELIC = 8,
CHRISTMAS_GLITTER = 9,
NUM_DEFAULT_ANIMATIONS NUM_DEFAULT_ANIMATIONS
}; };
@ -40,6 +41,7 @@ class AnimationController
"Fireworks", "Fireworks",
"Twinkling Sky", "Twinkling Sky",
"RGBW Sinus", "RGBW Sinus",
"RGBW Psychedelic",
"Christmas Glitter" "Christmas Glitter"
}; };

View file

@ -0,0 +1,46 @@
#pragma once
#include <array>
#include "Animation.h"
#include "fasttrigon.h"
class RgbwPsychedelicAnimation : public Animation
{
public:
typedef std::array<int32_t, 4> rgbw_val_array;
RgbwPsychedelicAnimation(Fader *fader,
const rgbw_val_array &move_speeds = {2273, 2281, 2287, 2293},
const rgbw_val_array &tilt_speeds = {2297, 2309, 2311, 2333},
int32_t tilt_maxperiods = 3,
uint32_t move_speed_divider = 1024,
uint32_t tilt_speed_divider = 8192,
uint16_t brightness_scale = fasttrigon::SCALE/4); // max: fasttrigon::SCALE
void loop(uint64_t frame) override;
void stop(void) override
{
m_stopping = true;
}
void reset(void) override;
private:
bool m_stopping;
rgbw_val_array m_move_speeds;
rgbw_val_array m_tilt_speeds;
uint32_t m_moveSpeedDivider;
uint32_t m_tiltSpeedDivider;
uint16_t m_brightnessScale;
int32_t m_tilt_maxperiods;
rgbw_val_array m_move_phi;
rgbw_val_array m_tilt_phi;
int32_t m_moveOverflowInterval;
int32_t m_tiltOverflowInterval;
};

View file

@ -13,7 +13,7 @@ class RgbwSinusAnimation : public Animation
RgbwSinusAnimation(Fader *fader, RgbwSinusAnimation(Fader *fader,
const rgbw_val_array &speeds = {2273, 2281, 2287, 2293}, const rgbw_val_array &speeds = {2273, 2281, 2287, 2293},
uint32_t speed_divider = 1024, uint32_t speed_divider = 1024,
uint16_t brightness_scale = 64); // max: 255 uint16_t brightness_scale = fasttrigon::SCALE/4); // max: 255
void loop(uint64_t frame) override; void loop(uint64_t frame) override;

View file

@ -14,8 +14,13 @@
#include <cstdint> #include <cstdint>
#define FASTTRIGON_8BIT(x) ((x) >> (fasttrigon::PRECISION_BITS - 8))
namespace fasttrigon { namespace fasttrigon {
static const uint32_t LUT_SIZE = 1024; static const uint32_t LUT_SIZE = 2048;
static const uint32_t PRECISION_BITS = 11;
static const int32_t SCALE = 1023;
static const uint32_t UNIT_SHIFT = PRECISION_BITS-1;
/*! /*!
* \returns 127 * sin(2π * arg / LUT_SIZE) * \returns 127 * sin(2π * arg / LUT_SIZE)

17
scripts/fasttrigon_gen_lut.py Executable file
View file

@ -0,0 +1,17 @@
#!/usr/bin/env python3
import numpy as np
LUT_SIZE = 2048
PRECISION_BITS = 11
SCALE = (1 << (PRECISION_BITS-1)) - 1
x = np.array(range(LUT_SIZE)) * 2*np.pi / LUT_SIZE
y = SCALE * np.sin(x)
print(f"static const uint32_t LUT_SIZE = {LUT_SIZE};")
print(f"static const uint32_t PRECISION_BITS = {PRECISION_BITS};")
print(f"static const uint32_t SCALE = {SCALE};")
print(list(y.astype('int')))

View file

@ -78,6 +78,10 @@ void AnimationController::changeAnimation(AnimationController::DefaultAnimation
anim.reset(new RgbwSinusAnimation(m_fader)); anim.reset(new RgbwSinusAnimation(m_fader));
break; break;
case RGBW_PSYCHEDELIC:
anim.reset(new RgbwPsychedelicAnimation(m_fader));
break;
case CHRISTMAS_GLITTER: case CHRISTMAS_GLITTER:
anim.reset(new ChristmasGlitterAnimation(m_fader)); anim.reset(new ChristmasGlitterAnimation(m_fader));
break; break;

View file

@ -8,7 +8,6 @@ ConnectingAnimation::ConnectingAnimation(Fader *fader)
void ConnectingAnimation::loop(uint64_t frame) void ConnectingAnimation::loop(uint64_t frame)
{ {
std::size_t nled = m_fader->modules_per_strip();
std::size_t nstrip = m_fader->strips(); std::size_t nstrip = m_fader->strips();
uint8_t intensity = 0; uint8_t intensity = 0;
@ -17,7 +16,7 @@ void ConnectingAnimation::loop(uint64_t frame)
} }
for(std::size_t strip = 0; strip < nstrip; strip++) { for(std::size_t strip = 0; strip < nstrip; strip++) {
intensity = (fasttrigon::fastsin(1 * frame * fasttrigon::LUT_SIZE / 60 + fasttrigon::LUT_SIZE*3/4) + 127) / 4; intensity = (FASTTRIGON_8BIT(fasttrigon::fastsin(1 * frame * fasttrigon::LUT_SIZE / 60 + fasttrigon::LUT_SIZE*3/4)) + 127) / 4;
Fader::Color c; Fader::Color c;
c.b = intensity; c.b = intensity;

View file

@ -28,8 +28,8 @@ void FireworkRocket::move(uint64_t frame)
case PHASE_SPREADING: case PHASE_SPREADING:
for(size_t i = 0; i < m_flareXPos.size(); i++) { for(size_t i = 0; i < m_flareXPos.size(); i++) {
int speedX = fasttrigon::fastcos(fasttrigon::LUT_SIZE / 12 + i * fasttrigon::LUT_SIZE / m_flareXPos.size()) / 2; int speedX = FASTTRIGON_8BIT(fasttrigon::fastcos(fasttrigon::LUT_SIZE / 12 + i * fasttrigon::LUT_SIZE / m_flareXPos.size())) / 2;
int speedY = fasttrigon::fastsin(fasttrigon::LUT_SIZE / 12 + i * fasttrigon::LUT_SIZE / m_flareXPos.size()) / 2; int speedY = FASTTRIGON_8BIT(fasttrigon::fastsin(fasttrigon::LUT_SIZE / 12 + i * fasttrigon::LUT_SIZE / m_flareXPos.size())) / 2;
m_flareXPos[i] += speedX; m_flareXPos[i] += speedX;
m_flareYPos[i] += speedY; m_flareYPos[i] += speedY;

View file

@ -0,0 +1,92 @@
#include <algorithm>
//#include <iostream>
#include "Animation/RgbwPsychedelicAnimation.h"
RgbwPsychedelicAnimation::RgbwPsychedelicAnimation(Fader *fader,
const rgbw_val_array &move_speeds,
const rgbw_val_array &tilt_speeds,
int32_t tilt_maxperiods,
uint32_t move_speed_divider,
uint32_t tilt_speed_divider,
uint16_t brightness_scale)
: Animation(fader),
m_move_speeds(move_speeds),
m_tilt_speeds(move_speeds),
m_moveSpeedDivider(move_speed_divider),
m_tiltSpeedDivider(tilt_speed_divider),
m_brightnessScale(brightness_scale),
m_tilt_maxperiods(tilt_maxperiods),
m_move_phi{800,600,400,200},
m_tilt_phi{200,400,600,800},
m_moveOverflowInterval(fasttrigon::LUT_SIZE * move_speed_divider),
m_tiltOverflowInterval(fasttrigon::LUT_SIZE * tilt_speed_divider)
{
reset();
}
void RgbwPsychedelicAnimation::loop(uint64_t frame)
{
std::size_t nled = m_fader->modules_per_strip();
std::size_t nstrip = m_fader->strips();
if(!m_stopping) {
for(unsigned i = 0; i < m_move_speeds.size(); i++) {
m_move_phi[i] += m_move_speeds[i];
if(m_move_phi[i] > m_moveOverflowInterval) {
m_move_phi[i] -= m_moveOverflowInterval;
}
}
rgbw_val_array tilt_nperiods;
for(unsigned i = 0; i < m_tilt_speeds.size(); i++) {
m_tilt_phi[i] += m_tilt_speeds[i];
if(m_tilt_phi[i] > m_tiltOverflowInterval) {
m_tilt_phi[i] -= m_tiltOverflowInterval;
}
tilt_nperiods[i] = m_tilt_maxperiods * fasttrigon::fastsin(m_tilt_phi[i] / m_tiltSpeedDivider);
}
for(std::size_t led = 0; led < nled; led++) {
for(std::size_t strip = 0; strip < nstrip; strip++) {
int32_t x = fasttrigon::LUT_SIZE * led / nled;
int32_t y = fasttrigon::LUT_SIZE * strip / nstrip;
rgbw_val_array rgbw {
(fasttrigon::SCALE + fasttrigon::fastsin(m_move_phi[0] / m_moveSpeedDivider + ((x * tilt_nperiods[0]) >> fasttrigon::UNIT_SHIFT) + y)),
(fasttrigon::SCALE + fasttrigon::fastsin(m_move_phi[1] / m_moveSpeedDivider + ((x * tilt_nperiods[1]) >> fasttrigon::UNIT_SHIFT) + y)),
(fasttrigon::SCALE + fasttrigon::fastsin(m_move_phi[2] / m_moveSpeedDivider + ((x * tilt_nperiods[2]) >> fasttrigon::UNIT_SHIFT) + y)),
(fasttrigon::SCALE + fasttrigon::fastsin(m_move_phi[3] / m_moveSpeedDivider + ((x * tilt_nperiods[3]) >> fasttrigon::UNIT_SHIFT) + y))
};
Fader::Color color{
static_cast<int16_t>((FASTTRIGON_8BIT(rgbw[0] * rgbw[0] >> fasttrigon::UNIT_SHIFT) * m_brightnessScale) >> fasttrigon::PRECISION_BITS),
static_cast<int16_t>((FASTTRIGON_8BIT(rgbw[1] * rgbw[1] >> fasttrigon::UNIT_SHIFT) * m_brightnessScale) >> fasttrigon::PRECISION_BITS),
static_cast<int16_t>((FASTTRIGON_8BIT(rgbw[2] * rgbw[2] >> fasttrigon::UNIT_SHIFT) * m_brightnessScale) >> fasttrigon::PRECISION_BITS),
static_cast<int16_t>((FASTTRIGON_8BIT(rgbw[3] * rgbw[3] >> fasttrigon::UNIT_SHIFT) * m_brightnessScale) >> (fasttrigon::PRECISION_BITS + 2))}; // white is too bright otherwise
//std::cerr << rgbw[0] << " " << rgbw[1] << " " << rgbw[2] << " " << rgbw[3] << std::endl;
//std::cerr << color.r << " " << color.g << " " << color.b << " " << color.w << std::endl;
m_fader->set_color(strip, led, color);
}
}
} else {
m_fader->fade_color(Fader::Color{0, 0, 0, 0});
}
m_fader->update();
m_running = !m_stopping || m_fader->something_changed();
}
void RgbwPsychedelicAnimation::reset(void)
{
m_stopping = false;
m_running = true;
}

View file

@ -32,13 +32,13 @@ void RgbwSinusAnimation::loop(uint64_t frame)
for(std::size_t led = 0; led < nled; led++) { for(std::size_t led = 0; led < nled; led++) {
for(std::size_t strip = 0; strip < nstrip; strip++) { for(std::size_t strip = 0; strip < nstrip; strip++) {
uint32_t pixelphase = led * fasttrigon::LUT_SIZE / nstrip + strip * fasttrigon::LUT_SIZE / nstrip; uint32_t pixelphase = led * fasttrigon::LUT_SIZE / nled + strip * fasttrigon::LUT_SIZE / nstrip;
Fader::Color color{ Fader::Color color{
static_cast<int16_t>(((127 + fasttrigon::fastsin(m_phi[0] / m_speedDivider + pixelphase)) * m_brightnessScale) >> 8), static_cast<int16_t>(((fasttrigon::SCALE + fasttrigon::fastsin(m_phi[0] / m_speedDivider + pixelphase)) * m_brightnessScale) >> fasttrigon::PRECISION_BITS),
static_cast<int16_t>(((127 + fasttrigon::fastsin(m_phi[1] / m_speedDivider + pixelphase)) * m_brightnessScale) >> 8), static_cast<int16_t>(((fasttrigon::SCALE + fasttrigon::fastsin(m_phi[1] / m_speedDivider + pixelphase)) * m_brightnessScale) >> fasttrigon::PRECISION_BITS),
static_cast<int16_t>(((127 + fasttrigon::fastsin(m_phi[2] / m_speedDivider + pixelphase)) * m_brightnessScale) >> 8), static_cast<int16_t>(((fasttrigon::SCALE + fasttrigon::fastsin(m_phi[2] / m_speedDivider + pixelphase)) * m_brightnessScale) >> fasttrigon::PRECISION_BITS),
static_cast<int16_t>(((127 + fasttrigon::fastsin(m_phi[3] / m_speedDivider + pixelphase)) * m_brightnessScale) >> 9)}; // white is too bright otherwise static_cast<int16_t>(((fasttrigon::SCALE + fasttrigon::fastsin(m_phi[3] / m_speedDivider + pixelphase)) * m_brightnessScale) >> (fasttrigon::PRECISION_BITS + 2))}; // white is too bright otherwise
m_fader->set_color(strip, led, color); m_fader->set_color(strip, led, color);
} }

View file

@ -23,7 +23,7 @@ void SnowfallAnimation::SnowFlake::move(void)
m_phase -= fasttrigon::LUT_SIZE; m_phase -= fasttrigon::LUT_SIZE;
} }
m_posStrip = m_basePosStrip + 2*fasttrigon::fastsin(m_phase); m_posStrip = m_basePosStrip + FASTTRIGON_8BIT(2*fasttrigon::fastsin(m_phase));
m_posLED -= m_vertSpeed; m_posLED -= m_vertSpeed;
} }

View file

@ -3,80 +3,182 @@
#include "fasttrigon.h" #include "fasttrigon.h"
namespace fasttrigon { namespace fasttrigon {
static const std::array<int8_t, LUT_SIZE> LUT { static const std::array<int16_t, LUT_SIZE> LUT {
0, 1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 9, 9, 10, 11, 12, 12, 13, 14, 15, 16, 0, 3, 6, 9, 12, 15, 18, 21, 25, 28, 31, 34, 37, 40, 43, 47, 50, 53, 56,
16, 17, 18, 19, 19, 20, 21, 22, 22, 23, 24, 25, 26, 26, 27, 28, 29, 59, 62, 65, 68, 72, 75, 78, 81, 84, 87, 90, 94, 97, 100, 103, 106,
29, 30, 31, 32, 32, 33, 34, 35, 35, 36, 37, 38, 38, 39, 40, 41, 41, 109, 112, 115, 118, 122, 125, 128, 131, 134, 137, 140, 143, 147,
42, 43, 44, 44, 45, 46, 46, 47, 48, 49, 49, 50, 51, 51, 52, 53, 54, 150, 153, 156, 159, 162, 165, 168, 171, 174, 177, 181, 184, 187,
54, 55, 56, 56, 57, 58, 58, 59, 60, 61, 61, 62, 63, 63, 64, 65, 65, 190, 193, 196, 199, 202, 205, 208, 211, 214, 218, 221, 224, 227,
66, 67, 67, 68, 69, 69, 70, 71, 71, 72, 72, 73, 74, 74, 75, 76, 76, 230, 233, 236, 239, 242, 245, 248, 251, 254, 257, 260, 263, 266,
77, 78, 78, 79, 79, 80, 81, 81, 82, 82, 83, 84, 84, 85, 85, 86, 86, 269, 272, 275, 278, 281, 284, 287, 290, 293, 296, 299, 302, 305,
87, 88, 88, 89, 89, 90, 90, 91, 91, 92, 93, 93, 94, 94, 95, 95, 96, 308, 311, 314, 317, 320, 323, 326, 329, 332, 335, 338, 341, 344,
96, 97, 97, 98, 98, 99, 99, 100, 100, 101, 101, 102, 102, 102, 103, 347, 350, 353, 356, 359, 362, 365, 368, 371, 374, 376, 379, 382,
103, 104, 104, 105, 105, 106, 106, 106, 107, 107, 108, 108, 109, 109, 385, 388, 391, 394, 397, 400, 403, 405, 408, 411, 414, 417, 420,
109, 110, 110, 111, 111, 111, 112, 112, 112, 113, 113, 113, 114, 114, 423, 426, 428, 431, 434, 437, 440, 443, 445, 448, 451, 454, 457,
114, 115, 115, 115, 116, 116, 116, 117, 117, 117, 118, 118, 118, 118, 459, 462, 465, 468, 471, 473, 476, 479, 482, 485, 487, 490, 493,
119, 119, 119, 120, 120, 120, 120, 121, 121, 121, 121, 122, 122, 122, 496, 498, 501, 504, 506, 509, 512, 515, 517, 520, 523, 525, 528,
122, 122, 123, 123, 123, 123, 123, 124, 124, 124, 124, 124, 124, 125, 531, 533, 536, 539, 541, 544, 547, 549, 552, 555, 557, 560, 563,
125, 125, 125, 125, 125, 125, 126, 126, 126, 126, 126, 126, 126, 126, 565, 568, 570, 573, 576, 578, 581, 583, 586, 589, 591, 594, 596,
126, 126, 126, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 599, 601, 604, 606, 609, 611, 614, 616, 619, 621, 624, 626, 629,
127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 631, 634, 636, 639, 641, 644, 646, 648, 651, 653, 656, 658, 661,
127, 127, 127, 127, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 663, 665, 668, 670, 672, 675, 677, 679, 682, 684, 687, 689, 691,
126, 125, 125, 125, 125, 125, 125, 125, 124, 124, 124, 124, 124, 124, 693, 696, 698, 700, 703, 705, 707, 709, 712, 714, 716, 718, 721,
123, 123, 123, 123, 123, 122, 122, 122, 122, 122, 121, 121, 121, 121, 723, 725, 727, 729, 732, 734, 736, 738, 740, 743, 745, 747, 749,
120, 120, 120, 120, 119, 119, 119, 118, 118, 118, 118, 117, 117, 117, 751, 753, 755, 757, 760, 762, 764, 766, 768, 770, 772, 774, 776,
116, 116, 116, 115, 115, 115, 114, 114, 114, 113, 113, 113, 112, 112, 778, 780, 782, 784, 786, 788, 790, 792, 794, 796, 798, 800, 802,
112, 111, 111, 111, 110, 110, 109, 109, 109, 108, 108, 107, 107, 106, 804, 806, 808, 810, 812, 814, 816, 817, 819, 821, 823, 825, 827,
106, 106, 105, 105, 104, 104, 103, 103, 102, 102, 102, 101, 101, 100, 829, 830, 832, 834, 836, 838, 839, 841, 843, 845, 847, 848, 850,
100, 99, 99, 98, 98, 97, 97, 96, 96, 95, 95, 94, 94, 93, 93, 92, 91, 852, 854, 855, 857, 859, 860, 862, 864, 865, 867, 869, 870, 872,
91, 90, 90, 89, 89, 88, 88, 87, 86, 86, 85, 85, 84, 84, 83, 82, 82, 874, 875, 877, 879, 880, 882, 883, 885, 886, 888, 890, 891, 893,
81, 81, 80, 79, 79, 78, 78, 77, 76, 76, 75, 74, 74, 73, 72, 72, 71, 894, 896, 897, 899, 900, 902, 903, 905, 906, 908, 909, 910, 912,
71, 70, 69, 69, 68, 67, 67, 66, 65, 65, 64, 63, 63, 62, 61, 61, 60, 913, 915, 916, 917, 919, 920, 922, 923, 924, 926, 927, 928, 930,
59, 58, 58, 57, 56, 56, 55, 54, 54, 53, 52, 51, 51, 50, 49, 49, 48, 931, 932, 933, 935, 936, 937, 939, 940, 941, 942, 943, 945, 946,
47, 46, 46, 45, 44, 44, 43, 42, 41, 41, 40, 39, 38, 38, 37, 36, 35, 947, 948, 949, 951, 952, 953, 954, 955, 956, 957, 958, 959, 961,
35, 34, 33, 32, 32, 31, 30, 29, 29, 28, 27, 26, 26, 25, 24, 23, 22, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974,
22, 21, 20, 19, 19, 18, 17, 16, 16, 15, 14, 13, 12, 12, 11, 10, 9, 9, 975, 976, 977, 978, 978, 979, 980, 981, 982, 983, 984, 985, 985,
8, 7, 6, 5, 5, 4, 3, 2, 2, 1, 0, -1, -2, -2, -3, -4, -5, -5, -6, -7, 986, 987, 988, 989, 990, 990, 991, 992, 993, 993, 994, 995, 996,
-8, -9, -9, -10, -11, -12, -12, -13, -14, -15, -16, -16, -17, -18, 996, 997, 998, 998, 999, 1000, 1000, 1001, 1002, 1002, 1003, 1003,
-19, -19, -20, -21, -22, -22, -23, -24, -25, -26, -26, -27, -28, -29, 1004, 1005, 1005, 1006, 1006, 1007, 1007, 1008, 1008, 1009, 1010,
-29, -30, -31, -32, -32, -33, -34, -35, -35, -36, -37, -38, -38, -39, 1010, 1010, 1011, 1011, 1012, 1012, 1013, 1013, 1014, 1014, 1014,
-40, -41, -41, -42, -43, -44, -44, -45, -46, -46, -47, -48, -49, -49, 1015, 1015, 1016, 1016, 1016, 1017, 1017, 1017, 1018, 1018, 1018,
-50, -51, -51, -52, -53, -54, -54, -55, -56, -56, -57, -58, -58, -59, 1018, 1019, 1019, 1019, 1019, 1020, 1020, 1020, 1020, 1021, 1021,
-60, -61, -61, -62, -63, -63, -64, -65, -65, -66, -67, -67, -68, -69, 1021, 1021, 1021, 1021, 1022, 1022, 1022, 1022, 1022, 1022, 1022,
-69, -70, -71, -71, -72, -72, -73, -74, -74, -75, -76, -76, -77, -78, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1023, 1022, 1022, 1022,
-78, -79, -79, -80, -81, -81, -82, -82, -83, -84, -84, -85, -85, -86, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022,
-86, -87, -88, -88, -89, -89, -90, -90, -91, -91, -92, -93, -93, -94, 1021, 1021, 1021, 1021, 1021, 1021, 1020, 1020, 1020, 1020, 1019,
-94, -95, -95, -96, -96, -97, -97, -98, -98, -99, -99, -100, -100, 1019, 1019, 1019, 1018, 1018, 1018, 1018, 1017, 1017, 1017, 1016,
-101, -101, -102, -102, -102, -103, -103, -104, -104, -105, -105, 1016, 1016, 1015, 1015, 1014, 1014, 1014, 1013, 1013, 1012, 1012,
-106, -106, -106, -107, -107, -108, -108, -109, -109, -109, -110, 1011, 1011, 1010, 1010, 1010, 1009, 1008, 1008, 1007, 1007, 1006,
-110, -111, -111, -111, -112, -112, -112, -113, -113, -113, -114, 1006, 1005, 1005, 1004, 1003, 1003, 1002, 1002, 1001, 1000, 1000,
-114, -114, -115, -115, -115, -116, -116, -116, -117, -117, -117, 999, 998, 998, 997, 996, 996, 995, 994, 993, 993, 992, 991, 990,
-118, -118, -118, -118, -119, -119, -119, -120, -120, -120, -120, 990, 989, 988, 987, 986, 985, 985, 984, 983, 982, 981, 980, 979,
-121, -121, -121, -121, -122, -122, -122, -122, -122, -123, -123, 978, 978, 977, 976, 975, 974, 973, 972, 971, 970, 969, 968, 967,
-123, -123, -123, -124, -124, -124, -124, -124, -124, -125, -125, 966, 965, 964, 963, 962, 961, 959, 958, 957, 956, 955, 954, 953,
-125, -125, -125, -125, -125, -126, -126, -126, -126, -126, -126, 952, 951, 949, 948, 947, 946, 945, 943, 942, 941, 940, 939, 937,
-126, -126, -126, -126, -126, -127, -127, -127, -127, -127, -127, 936, 935, 933, 932, 931, 930, 928, 927, 926, 924, 923, 922, 920,
-127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, 919, 917, 916, 915, 913, 912, 910, 909, 908, 906, 905, 903, 902,
-127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, 900, 899, 897, 896, 894, 893, 891, 890, 888, 886, 885, 883, 882,
-127, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, 880, 879, 877, 875, 874, 872, 870, 869, 867, 865, 864, 862, 860,
-126, -125, -125, -125, -125, -125, -125, -125, -124, -124, -124, 859, 857, 855, 854, 852, 850, 848, 847, 845, 843, 841, 839, 838,
-124, -124, -124, -123, -123, -123, -123, -123, -122, -122, -122, 836, 834, 832, 830, 829, 827, 825, 823, 821, 819, 817, 816, 814,
-122, -122, -121, -121, -121, -121, -120, -120, -120, -120, -119, 812, 810, 808, 806, 804, 802, 800, 798, 796, 794, 792, 790, 788,
-119, -119, -118, -118, -118, -118, -117, -117, -117, -116, -116, 786, 784, 782, 780, 778, 776, 774, 772, 770, 768, 766, 764, 762,
-116, -115, -115, -115, -114, -114, -114, -113, -113, -113, -112, 760, 757, 755, 753, 751, 749, 747, 745, 743, 740, 738, 736, 734,
-112, -112, -111, -111, -111, -110, -110, -109, -109, -109, -108, 732, 729, 727, 725, 723, 721, 718, 716, 714, 712, 709, 707, 705,
-108, -107, -107, -106, -106, -106, -105, -105, -104, -104, -103, 703, 700, 698, 696, 693, 691, 689, 687, 684, 682, 679, 677, 675,
-103, -102, -102, -102, -101, -101, -100, -100, -99, -99, -98, -98, 672, 670, 668, 665, 663, 661, 658, 656, 653, 651, 648, 646, 644,
-97, -97, -96, -96, -95, -95, -94, -94, -93, -93, -92, -91, -91, -90, 641, 639, 636, 634, 631, 629, 626, 624, 621, 619, 616, 614, 611,
-90, -89, -89, -88, -88, -87, -86, -86, -85, -85, -84, -84, -83, -82, 609, 606, 604, 601, 599, 596, 594, 591, 589, 586, 583, 581, 578,
-82, -81, -81, -80, -79, -79, -78, -78, -77, -76, -76, -75, -74, -74, 576, 573, 570, 568, 565, 563, 560, 557, 555, 552, 549, 547, 544,
-73, -72, -72, -71, -71, -70, -69, -69, -68, -67, -67, -66, -65, -65, 541, 539, 536, 533, 531, 528, 525, 523, 520, 517, 515, 512, 509,
-64, -63, -63, -62, -61, -61, -60, -59, -58, -58, -57, -56, -56, -55, 506, 504, 501, 498, 496, 493, 490, 487, 485, 482, 479, 476, 473,
-54, -54, -53, -52, -51, -51, -50, -49, -49, -48, -47, -46, -46, -45, 471, 468, 465, 462, 459, 457, 454, 451, 448, 445, 443, 440, 437,
-44, -44, -43, -42, -41, -41, -40, -39, -38, -38, -37, -36, -35, -35, 434, 431, 428, 426, 423, 420, 417, 414, 411, 408, 405, 403, 400,
-34, -33, -32, -32, -31, -30, -29, -29, -28, -27, -26, -26, -25, -24, 397, 394, 391, 388, 385, 382, 379, 376, 374, 371, 368, 365, 362,
-23, -22, -22, -21, -20, -19, -19, -18, -17, -16, -16, -15, -14, -13, 359, 356, 353, 350, 347, 344, 341, 338, 335, 332, 329, 326, 323,
-12, -12, -11, -10, -9, -9, -8, -7, -6, -5, -5, -4, -3, -2, -2, -1 320, 317, 314, 311, 308, 305, 302, 299, 296, 293, 290, 287, 284,
281, 278, 275, 272, 269, 266, 263, 260, 257, 254, 251, 248, 245,
242, 239, 236, 233, 230, 227, 224, 221, 218, 214, 211, 208, 205,
202, 199, 196, 193, 190, 187, 184, 181, 177, 174, 171, 168, 165,
162, 159, 156, 153, 150, 147, 143, 140, 137, 134, 131, 128, 125,
122, 118, 115, 112, 109, 106, 103, 100, 97, 94, 90, 87, 84, 81, 78,
75, 72, 68, 65, 62, 59, 56, 53, 50, 47, 43, 40, 37, 34, 31, 28, 25,
21, 18, 15, 12, 9, 6, 3, 0, -3, -6, -9, -12, -15, -18, -21, -25,
-28, -31, -34, -37, -40, -43, -47, -50, -53, -56, -59, -62, -65,
-68, -72, -75, -78, -81, -84, -87, -90, -94, -97, -100, -103, -106,
-109, -112, -115, -118, -122, -125, -128, -131, -134, -137, -140,
-143, -147, -150, -153, -156, -159, -162, -165, -168, -171, -174,
-177, -181, -184, -187, -190, -193, -196, -199, -202, -205, -208,
-211, -214, -218, -221, -224, -227, -230, -233, -236, -239, -242,
-245, -248, -251, -254, -257, -260, -263, -266, -269, -272, -275,
-278, -281, -284, -287, -290, -293, -296, -299, -302, -305, -308,
-311, -314, -317, -320, -323, -326, -329, -332, -335, -338, -341,
-344, -347, -350, -353, -356, -359, -362, -365, -368, -371, -374,
-376, -379, -382, -385, -388, -391, -394, -397, -400, -403, -405,
-408, -411, -414, -417, -420, -423, -426, -428, -431, -434, -437,
-440, -443, -445, -448, -451, -454, -457, -459, -462, -465, -468,
-471, -473, -476, -479, -482, -485, -487, -490, -493, -496, -498,
-501, -504, -506, -509, -512, -515, -517, -520, -523, -525, -528,
-531, -533, -536, -539, -541, -544, -547, -549, -552, -555, -557,
-560, -563, -565, -568, -570, -573, -576, -578, -581, -583, -586,
-589, -591, -594, -596, -599, -601, -604, -606, -609, -611, -614,
-616, -619, -621, -624, -626, -629, -631, -634, -636, -639, -641,
-644, -646, -648, -651, -653, -656, -658, -661, -663, -665, -668,
-670, -672, -675, -677, -679, -682, -684, -687, -689, -691, -693,
-696, -698, -700, -703, -705, -707, -709, -712, -714, -716, -718,
-721, -723, -725, -727, -729, -732, -734, -736, -738, -740, -743,
-745, -747, -749, -751, -753, -755, -757, -760, -762, -764, -766,
-768, -770, -772, -774, -776, -778, -780, -782, -784, -786, -788,
-790, -792, -794, -796, -798, -800, -802, -804, -806, -808, -810,
-812, -814, -816, -817, -819, -821, -823, -825, -827, -829, -830,
-832, -834, -836, -838, -839, -841, -843, -845, -847, -848, -850,
-852, -854, -855, -857, -859, -860, -862, -864, -865, -867, -869,
-870, -872, -874, -875, -877, -879, -880, -882, -883, -885, -886,
-888, -890, -891, -893, -894, -896, -897, -899, -900, -902, -903,
-905, -906, -908, -909, -910, -912, -913, -915, -916, -917, -919,
-920, -922, -923, -924, -926, -927, -928, -930, -931, -932, -933,
-935, -936, -937, -939, -940, -941, -942, -943, -945, -946, -947,
-948, -949, -951, -952, -953, -954, -955, -956, -957, -958, -959,
-961, -962, -963, -964, -965, -966, -967, -968, -969, -970, -971,
-972, -973, -974, -975, -976, -977, -978, -978, -979, -980, -981,
-982, -983, -984, -985, -985, -986, -987, -988, -989, -990, -990,
-991, -992, -993, -993, -994, -995, -996, -996, -997, -998, -998,
-999, -1000, -1000, -1001, -1002, -1002, -1003, -1003, -1004,
-1005, -1005, -1006, -1006, -1007, -1007, -1008, -1008, -1009,
-1010, -1010, -1010, -1011, -1011, -1012, -1012, -1013, -1013,
-1014, -1014, -1014, -1015, -1015, -1016, -1016, -1016, -1017,
-1017, -1017, -1018, -1018, -1018, -1018, -1019, -1019, -1019,
-1019, -1020, -1020, -1020, -1020, -1021, -1021, -1021, -1021,
-1021, -1021, -1022, -1022, -1022, -1022, -1022, -1022, -1022,
-1022, -1022, -1022, -1022, -1022, -1022, -1022, -1023, -1022,
-1022, -1022, -1022, -1022, -1022, -1022, -1022, -1022, -1022,
-1022, -1022, -1022, -1022, -1021, -1021, -1021, -1021, -1021,
-1021, -1020, -1020, -1020, -1020, -1019, -1019, -1019, -1019,
-1018, -1018, -1018, -1018, -1017, -1017, -1017, -1016, -1016,
-1016, -1015, -1015, -1014, -1014, -1014, -1013, -1013, -1012,
-1012, -1011, -1011, -1010, -1010, -1010, -1009, -1008, -1008,
-1007, -1007, -1006, -1006, -1005, -1005, -1004, -1003, -1003,
-1002, -1002, -1001, -1000, -1000, -999, -998, -998, -997, -996,
-996, -995, -994, -993, -993, -992, -991, -990, -990, -989, -988,
-987, -986, -985, -985, -984, -983, -982, -981, -980, -979, -978,
-978, -977, -976, -975, -974, -973, -972, -971, -970, -969, -968,
-967, -966, -965, -964, -963, -962, -961, -959, -958, -957, -956,
-955, -954, -953, -952, -951, -949, -948, -947, -946, -945, -943,
-942, -941, -940, -939, -937, -936, -935, -933, -932, -931, -930,
-928, -927, -926, -924, -923, -922, -920, -919, -917, -916, -915,
-913, -912, -910, -909, -908, -906, -905, -903, -902, -900, -899,
-897, -896, -894, -893, -891, -890, -888, -886, -885, -883, -882,
-880, -879, -877, -875, -874, -872, -870, -869, -867, -865, -864,
-862, -860, -859, -857, -855, -854, -852, -850, -848, -847, -845,
-843, -841, -839, -838, -836, -834, -832, -830, -829, -827, -825,
-823, -821, -819, -817, -816, -814, -812, -810, -808, -806, -804,
-802, -800, -798, -796, -794, -792, -790, -788, -786, -784, -782,
-780, -778, -776, -774, -772, -770, -768, -766, -764, -762, -760,
-757, -755, -753, -751, -749, -747, -745, -743, -740, -738, -736,
-734, -732, -729, -727, -725, -723, -721, -718, -716, -714, -712,
-709, -707, -705, -703, -700, -698, -696, -693, -691, -689, -687,
-684, -682, -679, -677, -675, -672, -670, -668, -665, -663, -661,
-658, -656, -653, -651, -648, -646, -644, -641, -639, -636, -634,
-631, -629, -626, -624, -621, -619, -616, -614, -611, -609, -606,
-604, -601, -599, -596, -594, -591, -589, -586, -583, -581, -578,
-576, -573, -570, -568, -565, -563, -560, -557, -555, -552, -549,
-547, -544, -541, -539, -536, -533, -531, -528, -525, -523, -520,
-517, -515, -512, -509, -506, -504, -501, -498, -496, -493, -490,
-487, -485, -482, -479, -476, -473, -471, -468, -465, -462, -459,
-457, -454, -451, -448, -445, -443, -440, -437, -434, -431, -428,
-426, -423, -420, -417, -414, -411, -408, -405, -403, -400, -397,
-394, -391, -388, -385, -382, -379, -376, -374, -371, -368, -365,
-362, -359, -356, -353, -350, -347, -344, -341, -338, -335, -332,
-329, -326, -323, -320, -317, -314, -311, -308, -305, -302, -299,
-296, -293, -290, -287, -284, -281, -278, -275, -272, -269, -266,
-263, -260, -257, -254, -251, -248, -245, -242, -239, -236, -233,
-230, -227, -224, -221, -218, -214, -211, -208, -205, -202, -199,
-196, -193, -190, -187, -184, -181, -177, -174, -171, -168, -165,
-162, -159, -156, -153, -150, -147, -143, -140, -137, -134, -131,
-128, -125, -122, -118, -115, -112, -109, -106, -103, -100, -97,
-94, -90, -87, -84, -81, -78, -75, -72, -68, -65, -62, -59, -56,
-53, -50, -47, -43, -40, -37, -34, -31, -28, -25, -21, -18, -15,
-12, -9, -6, -3
}; };
int32_t fastsin(int32_t arg) int32_t fastsin(int32_t arg)