volatile double objX = 300;
volatile double objY = 200;
static double objDir = 0.3;
static double objVel = 10;
static constexpr int objSize = 25;
static uint32_t bgParkMillerState = 1;
static constexpr int borderSize = 20;
constexpr int scanlinesPerCallback = 2;
static TaskHandle_t mainTaskHandle;
volatile int objIntX;
volatile int objIntY;
inline int fastRandom()
{
bgParkMillerState = (uint64_t)bgParkMillerState * 48271 % 0x7fffffff;
return bgParkMillerState % 4;
}
void IRAM_ATTR drawScanline(void * arg, uint8_t * dest, int scanLine)
{
auto fgcolor = DisplayController.createRawPixel(RGB222(3, 0, 0));
auto bgcolor = DisplayController.createRawPixel(RGB222(0, 0, 2));
for (int i = 0; i < scanlinesPerCallback; ++i) {
if (scanLine < borderSize || scanLine >
height - borderSize)
bgcolor = DisplayController.createRawPixel(RGB222(fastRandom(), fastRandom(), fastRandom()));
memset(dest, bgcolor,
width);
if (scanLine >= objIntY - objSize / 2 && scanLine <= objIntY + objSize / 2) {
for (int col = objIntX - objSize / 2; col < objIntX + objSize / 2; ++col) {
if (col >= 0 && col <
width) {
VGA_PIXELINROW(dest, col) = fgcolor;
}
}
}
++scanLine;
}
vTaskNotifyGiveFromISR(mainTaskHandle, NULL);
}
}
void setup()
{
mainTaskHandle = xTaskGetCurrentTaskHandle();
DisplayController.begin();
}
void loop()
{
if (objX < objSize / 2 || objX > DisplayController.
getScreenWidth() - objSize / 2)
objDir = PI - objDir;
else if (objY < borderSize + objSize / 2 || objY > DisplayController.
getScreenHeight() - borderSize - objSize / 2)
objDir = 2 * PI - objDir;
objX += objVel * cos(objDir);
objY += objVel * sin(objDir);
objIntX = objX;
objIntY = objY;
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
}
int getScreenHeight()
Determines the screen height in pixels.
int getScreenWidth()
Determines the screen width in pixels.
void setDrawScanlineCallback(DrawScanlineCallback drawScanlineCallback, void *arg=nullptr)
Sets the callback used when VGADirectController needs to prepare a new scanline to be sent to the VGA...
void setScanlinesPerCallBack(int value)
Sets number of scanlines to draw in a single callback.
Represents a base abstract class for direct draw VGA controller.
This file is the all in one include file. Application can just include this file to use FabGL library...