Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pushRotated(angle, transparency) #1877

Closed
elC1a opened this issue Jun 14, 2022 · 1 comment
Closed

pushRotated(angle, transparency) #1877

elC1a opened this issue Jun 14, 2022 · 1 comment

Comments

@elC1a
Copy link

elC1a commented Jun 14, 2022

If transparency isn't specified the function uses 0xFFFF as the transparent color.
The white text is not displayed if transparency isn't specified.

In Sprite.h transparency is specified as an OPTION but also with a value:
Push a rotated copy of Sprite to TFT with optional transparent colour
bool pushRotated(int16_t angle, uint32_t transp = 0x00FFFFFF); // Using fixed point maths

Is there a reason for the default transparency value?

Another question about the time completing a call to pushRotated.
Mostly about 107ms in the example below but sometimes it grows up to 200ms or more.
It seems that happened always at the same angles.

I understand that the amount of data grows up if a sprite rectangle rotated because the bounding rectangle increases.
But the time increases more than expected.
Okay, my situation:
The sprite is a circle, a compass.
In this situation (circle) there is no "worst case", about 45 degrees or so, the bounding rectangle is always radius * 2.
Maybe you like to include an option to rotate a sprite in the original size.
In that case the time for the function pushRotated() should be the same.

#include <TFT_eSPI.h> // TFT_espi Library
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite sprite = TFT_eSprite(&tft); // sprite

int16_t angle = 0;
uint32_t update = 0;
uint32_t speed = 0;
int32_t width = 320;
int32_t height = 480;

void setup(void)
{
tft.init();
tft.fillScreen(0x0000);
tft.setPivot(width / 2, height / 2 + 32);
Draw();
update = millis(); // next update time
}

void loop()
{
if (update <= millis())
{
SpritePlot(); // draw sprite
angle = angle+1; // increase angle
if (angle >= 360) angle = 0; // limit angle
update = millis() + 500; // update time in milliseconds
}
}

void Draw(void)
{
// draw title text
tft.setTextSize(1);
tft.setTextColor(0x0000, 0xFFFF);
tft.setCursor(8, 8, 2);
tft.print(" Time to complete pushRotated() = ");
tft.setTextSize(2);
tft.setCursor(8, 28, 1);
tft.print("Time > 190ms at deg");

// create sprite
sprite.createSprite(width, width);
sprite.setColorDepth(16);
sprite.setPivot(width / 2, width / 2);

// fill sprite background
sprite.fillSprite(0x0000);

// draw scope arc lines
sprite.drawCircle(width / 2, width / 2, width * 0.4, 0x03E0);
sprite.drawCircle(width / 2, width / 2, width * 0.32, 0x03E0);
sprite.drawCircle(width / 2, width / 2, width * 0.24, 0x03E0);
sprite.drawCircle(width / 2, width / 2, width * 0.16, 0x03E0);
sprite.drawCircle(width / 2, width / 2, width * 0.08, 0x03E0);

// draw scope angle lines
sprite.drawLine(width / 2, width / 2, width / 2 + (width * 0.4 * cos(90 * DEG_TO_RAD)), width / 2 - (width * 0.4 * sin(90 * DEG_TO_RAD)), 0x03E0);

// draw angle text
sprite.setTextSize(2);
sprite.setTextColor(0xFFFF, 0x0000);
sprite.setCursor(width / 2 - 34, width / 2 - 8, 1);
sprite.print("Rotate");
}

void SpritePlot()
{
speed = millis();
//*********************************************************************************************************************
// Push rotated sprite.
// It seems that if transparency isn't specified the function uses 0xFFFF as the transparent color
// The white text is not displayed if transparency isn't specified
// In Sprite.h transparency is specified as an option but also with a value:
// Push a rotated copy of Sprite to TFT with optional transparent colour
// bool pushRotated(int16_t angle, uint32_t transp = 0x00FFFFFF); // Using fixed point maths
//*********************************************************************************************************************
sprite.pushRotated(angle, 0x1234); // with white text
//sprite.pushRotated(angle); // no white text

// draw speed time
speed = millis() - speed;
tft.setTextColor(TFT_BLACK, TFT_WHITE);
tft.setTextSize(2);
tft.setCursor(240, 8, 1);
tft.printf("%ims ", speed);

// draw last Time > 190ms at degrees
if (speed >= 190)
{
tft.setTextColor(0x0000, 0xFFFF);
tft.setTextSize(2);
tft.setCursor(244, 28, 1);
tft.printf("%i ", angle);
}
}

@Bodmer
Copy link
Owner

Bodmer commented Jun 16, 2022

Looks like I broke this function so it is a bug. Thanks for reporting this I will fix it.

@Bodmer Bodmer closed this as completed in 781b0bc Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants