46 lines
1.5 KiB
C++
46 lines
1.5 KiB
C++
#ifndef TILEDSERPENTINEARRANGEMENT_H
|
|
#define TILEDSERPENTINEARRANGEMENT_H
|
|
|
|
#include "ILEDArrangement.h"
|
|
|
|
class TiledSerpentineArrangement : public ILEDArrangement {
|
|
public:
|
|
TiledSerpentineArrangement(bool _isColumnSerpentine, bool _isVerticallyTiled,
|
|
int16_t _tileWidth, int16_t _tileHeight) : isColumnSerpentine(_isColumnSerpentine),
|
|
isVerticallyTiled(_isVerticallyTiled), tileWidth(_tileWidth), tileHeight(_tileHeight) {}
|
|
virtual ~TiledSerpentineArrangement() {}
|
|
|
|
int16_t XY(int16_t x, int16_t y, int16_t width, int16_t height) {
|
|
int16_t tileNumber = isVerticallyTiled ? y / tileHeight : x / tileHeight;
|
|
|
|
int16_t modX = x % tileWidth;
|
|
int16_t modY = y % tileHeight;
|
|
|
|
int16_t tilePosition = 0;
|
|
|
|
if(isColumnSerpentine) {
|
|
if (x & 0x1) {
|
|
tilePosition = modX * tileHeight + (tileHeight - 1 - modY);
|
|
} else {
|
|
tilePosition = modX * tileHeight + modY;
|
|
}
|
|
} else {
|
|
if (y & 0x1) {
|
|
tilePosition = modY * tileWidth + (tileWidth - 1 - modX);
|
|
} else {
|
|
tilePosition = modY * tileWidth + modX;
|
|
}
|
|
}
|
|
|
|
return tileWidth * tileHeight * tileNumber + tilePosition;
|
|
}
|
|
private:
|
|
bool
|
|
isColumnSerpentine,
|
|
isVerticallyTiled;
|
|
int16_t
|
|
tileWidth,
|
|
tileHeight;
|
|
};
|
|
|
|
#endif |