pitrix/functions.h

67 lines
1.3 KiB
C

int XYsafe(int x, int y) {
if ( x >= LED_WIDTH) return 0;
if ( y >= LED_HEIGHT) return 0;
if ( x < 0) return 0;
if ( y < 0) return 0;
// Invert y
y = LED_HEIGHT - 1 - y;
if (y & 1) x = LED_WIDTH - 1 - x;
// Invert x
//x = LED_WIDTH - 1 - x;
return y*LED_WIDTH+x;
}
void setPixel(int x, int y, CRGB color) {
if ( x >= LED_WIDTH) return;
if ( y >= LED_HEIGHT) return;
if ( x < 0) return;
if ( y < 0) return;
// Invert y
y = LED_HEIGHT - 1 - y;
if (y & 1) x = LED_WIDTH - 1 - x;
// Invert x
//x = LED_WIDTH - 1 - x;
leds[y*LED_WIDTH+x] = color;
}
void setPixel(int i, CRGB color) {
int x = i % LED_WIDTH;
int y = i / LED_WIDTH;
setPixel(x, y, color);
}
void clear() {
for ( byte y = 0; y < LED_HEIGHT; y++) {
for ( byte x = 0; x < LED_WIDTH; x++) {
leds[ XYsafe(x, y)] = CHSV((16*y)+(47*x), 255, 42);
}
}
}
inline double sines(double x, double y) {
return ((cos(x) * sin(y)) * 0.5) + 0.5;
}
inline double basefield(double x, double y) {
return (cos(x) * sin(y) * cos(sqrt((x*x) + (y*y))));
}
inline double addmod(double x, double mod, double delta) {
x = x + delta;
while( x >= mod ) x -= mod;
while( x < 0.0 ) x += mod;
return x;
}
inline double addmodpi(double x, double delta) {
return addmod(x, 2*PI, delta);
}