Skip to content

Commit

Permalink
Merge pull request #58 from lovyan03/develop
Browse files Browse the repository at this point in the history
0.2.5
  • Loading branch information
lovyan03 authored Oct 31, 2020
2 parents a40224f + bb7a527 commit b1e9255
Show file tree
Hide file tree
Showing 23 changed files with 1,703 additions and 762 deletions.
27 changes: 12 additions & 15 deletions examples/Game/BallMaze/BallMaze.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include <LovyanGFX.hpp>


Expand Down Expand Up @@ -107,11 +106,9 @@ static void draw(void)

float fx = (cx - ox);
float fy = (cy - oy);
float len = sqrt(fx * fx + fy * fy) * zoom;
float theta = atan2(fx, fy) + rad;
std::int32_t vx = round(sin(theta) * len);
std::int32_t vy = round(cos(theta) * len);
sp.pushRotateZoom(px - vx, py - vy, angle, zoom, zoom);
float len = sqrtf(fx * fx + fy * fy) * zoom;
float theta = atan2f(fx, fy) + rad;
sp.pushRotateZoom(px - sinf(theta) * len, py - cosf(theta) * len, angle, zoom, zoom);
}

static void game_init(void)
Expand Down Expand Up @@ -178,15 +175,15 @@ static bool game_main(void)
add_angle = add_angle * 9 / 10;
rad = angle * - deg_to_rad;

ax += sin(rad) * gravity;
ay -= cos(rad) * gravity;
ax += sinf(rad) * gravity;
ay -= cosf(rad) * gravity;
ax = ax * 9.7 / 10;
ay = ay * 9.7 / 10;

float addy = (ay<0.0) ? -cr:cr;
auto tmpy = round(cy+ay+addy);
auto tmpy = roundf(cy+ay+addy);

if ( 3 == sp.readPixelValue(round(cx), tmpy))
if ( 3 == sp.readPixelValue(roundf(cx), tmpy))
{
cy = tmpy - addy + (ay < 0.0 ? 0.5 : -0.5);
ay = -ay * 9.0 / 10;
Expand All @@ -197,8 +194,8 @@ static bool game_main(void)
}

float addx = (ax<0.0) ? -cr:cr;
auto tmpx = round(cx+ax+addx);
if ( 3 == sp.readPixelValue(tmpx, round(cy)))
auto tmpx = roundf(cx+ax+addx);
if ( 3 == sp.readPixelValue(tmpx, roundf(cy)))
{
cx = tmpx - addx + (ax < 0.0 ? 0.5 : -0.5);
ax = -ax * 9.0 / 10;
Expand All @@ -208,10 +205,10 @@ static bool game_main(void)
cx += ax;
}

std::uint32_t pv = sp.readPixelValue(round(cx), round(cy));
std::uint32_t pv = sp.readPixelValue(roundf(cx), roundf(cy));
if ( 0 == pv)
{
sp.drawPixel(round(cx), round(cy), 2);
sp.drawPixel(roundf(cx), roundf(cy), 2);
}
else if (1 == pv) return true;

Expand Down Expand Up @@ -241,7 +238,7 @@ void loop(void)
{
if (!game_main())
{
lcd.fillCircle(px, py, round(cr*zoom), 0xFFFF00U);
lcd.fillCircle(px, py, roundf(cr*zoom), 0xFFFF00U);
}
else
{
Expand Down
358 changes: 270 additions & 88 deletions examples/HowToUse/5_images/5_images.ino

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions examples/HowToUse/5_images/image.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
_ _ _ _ _ _ _ _ _ _ _ _ _ R R R R R R R _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ R R R R R R R R R R R _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ R R R R R R R R R R R R R _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ R R R R _ _ _ _ _ _ R R R R R _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ R R R R R _ _ R R R _ _ R R R R R _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ R R R R R _ _ R R R _ _ R R R R R _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ R R R R R R _ _ _ _ _ _ R R R R R R R _ _ _ _ _ _ _
_ _ _ _ _ _ _ R R R R R R _ _ R R _ _ R R R R R R R _ _ _ _ _ _ _
_ _ _ _ _ _ _ R R R R R R _ _ R R R _ _ R R R R R R _ _ _ _ _ _ _
_ _ _ _ _ _ _ R R R R R R _ _ R R R _ _ R R R R R R _ _ _ _ _ _ _
_ _ _ _ _ _ _ R R R R R R _ _ R R R _ _ R R R R R R _ _ _ _ _ _ _
_ _ _ _ _ _ _ R R R R R R R R R R R R R R R R R R R _ _ _ _ _ _ _
_ _ _ _ _ _ G Y Y Y Y Y Y R R R R R R R M M M M M M B _ _ _ _ _ _
_ _ _ _ G G G G Y Y Y Y Y Y Y R R R M M M M M M M B B B B _ _ _ _
_ _ _ G G G G G Y Y Y Y Y Y Y Y R M M M M M M M M B B B B B _ _ _
_ _ G G G G G G G Y Y Y Y Y Y Y W M M M M M M M B B B B B B B _ _
_ G G G G G G G G G Y Y Y Y Y W W W M M M M M B B B B B B B B B _
_ G G G G G G G G G G Y Y Y Y W W W M M M M B B B B B B B B B B _
G G G G G G G G G G G G G Y W W W W W M B B B B B B B B B B B B B
G G G G G _ _ _ _ G G G G G C C C C C B B B B _ _ _ _ _ B B B B B
G G G G _ _ G G _ _ G G G G C C C C C B B B B _ _ B B _ _ B B B B
G G G G _ _ G G G G G G G G C C C C C B B B B _ _ B B _ _ B B B B
G G G G _ _ G G G G G G G G C C C C C B B B B _ _ _ _ _ B B B B B
G G G G _ _ G _ _ _ G G G G C C C C C B B B B _ _ B B _ _ B B B B
G G G G _ _ G G _ _ G G G G C C C C C B B B B _ _ B B _ _ B B B B
_ G G G _ _ G G _ _ G G G G G C C C B B B B B _ _ B B _ _ B B B _
_ G G G G _ _ _ _ G G G G G G C C C B B B B B _ _ _ _ _ B B B B _
_ _ G G G G G G G G G G G G G G C B B B B B B B B B B B B B B _ _
_ _ _ G G G G G G G G G G G G G _ B B B B B B B B B B B B B _ _ _
_ _ _ _ G G G G G G G G G G G _ _ _ B B B B B B B B B B B _ _ _ _
_ _ _ _ _ _ G G G G G G G _ _ _ _ _ _ _ B B B B B B B _ _ _ _ _ _
30 changes: 0 additions & 30 deletions examples/HowToUse/5_images/image.txt

This file was deleted.

82 changes: 44 additions & 38 deletions examples/Sprite/CollisionCircles/CollisionCircles.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,8 @@ volatile bool _is_running;
volatile std::uint32_t _draw_count;
volatile std::uint32_t _loop_count;


static void drawfunc(void)
static void diffDraw(LGFX_Sprite* sp0, LGFX_Sprite* sp1)
{
ball_info_t *balls;
ball_info_t *a;
LGFX_Sprite *sprite;

auto width = _sprites[0].width();
auto height = _sprites[0].height();

std::size_t flip = _draw_count & 1;
balls = &_balls[flip][0];

sprite = &(_sprites[flip]);
sprite->clear();

for (int32_t i = 8; i < width; i += 16) {
sprite->drawFastVLine(i, 0, height, 0x1F);
}
for (int32_t i = 8; i < height; i += 16) {
sprite->drawFastHLine(0, i, width, 0x1F);
}
for (std::uint32_t i = 0; i < _ball_count; i++) {
a = &balls[i];
sprite->fillCircle( a->x >> SHIFTSIZE
, a->y >> SHIFTSIZE
, a->r >> SHIFTSIZE
, a->color);
}

sprite->setCursor(1,1);
sprite->setTextColor(TFT_BLACK);
sprite->printf("obj:%d fps:%d", _ball_count, _fps);
sprite->setCursor(0,0);
sprite->setTextColor(TFT_WHITE);
sprite->printf("obj:%d fps:%d", _ball_count, _fps);

union
{
std::uint32_t* s32;
Expand All @@ -76,8 +41,11 @@ static void drawfunc(void)
std::uint32_t* p32;
std::uint8_t* p;
};
s32 = (std::uint32_t*)sprite->getBuffer();
p32 = (std::uint32_t*)_sprites[!flip].getBuffer();
s32 = (std::uint32_t*)sp0->getBuffer();
p32 = (std::uint32_t*)sp1->getBuffer();

auto width = sp0->width();
auto height = sp0->height();

auto w32 = (width+3) >> 2;
std::int32_t y = 0;
Expand All @@ -103,6 +71,44 @@ static void drawfunc(void)
s32 += w32;
p32 += w32;
} while (++y < height);
}

static void drawfunc(void)
{
ball_info_t *balls;
ball_info_t *a;
LGFX_Sprite *sprite;

auto width = _sprites[0].width();
auto height = _sprites[0].height();

std::size_t flip = _draw_count & 1;
balls = &_balls[flip][0];

sprite = &(_sprites[flip]);
sprite->clear();

for (int32_t i = 8; i < width; i += 16) {
sprite->drawFastVLine(i, 0, height, 0x1F);
}
for (int32_t i = 8; i < height; i += 16) {
sprite->drawFastHLine(0, i, width, 0x1F);
}
for (std::uint32_t i = 0; i < _ball_count; i++) {
a = &balls[i];
sprite->fillCircle( a->x >> SHIFTSIZE
, a->y >> SHIFTSIZE
, a->r >> SHIFTSIZE
, a->color);
}

sprite->setCursor(1,1);
sprite->setTextColor(TFT_BLACK);
sprite->printf("obj:%d fps:%d", _ball_count, _fps);
sprite->setCursor(0,0);
sprite->setTextColor(TFT_WHITE);
sprite->printf("obj:%d fps:%d", _ball_count, _fps);
diffDraw(&_sprites[flip], &_sprites[!flip]);
++_draw_count;
}

Expand Down
11 changes: 5 additions & 6 deletions examples/Sprite/MeterSample/MeterSample.ino
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void setup(void)

canvas.createSprite(width, width); // メモリ確保
base .createSprite(width, width);
needle.createSprite(11, 109);
needle.createSprite(3, 11);

base.setFont(&fonts::Orbitron_Light_24); // フォント種類を変更(盤の文字用)
//base.setFont(&fonts::Roboto_Thin_24); // フォント種類を変更(盤の文字用)
Expand Down Expand Up @@ -72,10 +72,8 @@ void setup(void)
}
}

needle.setPivot(5, 100); // 針パーツの回転中心座標を設定する
needle.fillRect(2, 0, 7, 100, 2);
needle.fillCircle(5, 100, 4, 1);
needle.drawCircle(5, 100, 4, 3);
needle.setPivot(1, 9); // 針パーツの回転中心座標を設定する
needle.drawRect(0, 0, 3, 11, 2);

canvas.setPaletteColor(1, 0, 0, 15);
canvas.setPaletteColor(2, 255, 31, 31);
Expand All @@ -90,7 +88,8 @@ void draw(float value)
base.pushSprite(0, 0); // 描画用バッファに盤の画像を上書き

float angle = 270 + value * 90.0;
needle.pushRotateZoom( angle, 1.0, 1.0, transpalette); // 針をバッファに描画する
needle.pushRotateZoom( angle, 3.0, 10.0, transpalette); // 針をバッファに描画する
canvas.fillCircle(halfwidth, halfwidth, 7, 3);
canvas.pushRotateZoom(0, zoom, zoom, transpalette); // 完了した盤をLCDに描画する
if (value >= 1.5)
lcd.fillCircle(lcd.width()>>1, (lcd.height()>>1) + width * 4/10, 5, 0x007FFFU);
Expand Down
93 changes: 93 additions & 0 deletions examples/Test/save_png/save_png.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#if defined (ARDUINO_WIO_TERMINAL)
#include <Seeed_FS.h>
#include <SD/Seeed_SD.h>
#else
#include <SD.h>
#include <SPIFFS.h>
#endif

#include <LovyanGFX.hpp>

static LGFX lcd;

static constexpr char filename[] = "/lovyangfx_test.png";

#ifndef SDCARD_SS_PIN
#define SDCARD_SS_PIN 4
#endif

#ifndef SDCARD_SPI
#define SDCARD_SPI SPI
#endif


bool saveToSD()
{
// createPng関数で指定範囲の画像からPNG形式のデータを生成します。
// SAMD51の場合 172x172程度が上限です。
// ESP32の場合 192x192程度が上限です。
// メモリ使用状況によってさらに縮みます。
// ESP32でPSRAMが有効な場合は大きなサイズでも保存できる可能性があります。
std::size_t dlen;
std::uint8_t* png = (std::uint8_t*)lcd.createPng(&dlen, 0, 0, 128, 128);
if (!png)
{
Serial.print("error:createPng\n");
return false;
}

Serial.print("success:createPng\n");

bool result = false;
File file = SD.open(filename, "w");
if (file)
{
file.write((std::uint8_t*)png, dlen);
file.close();
result = true;
}
else
{
Serial.print("error:file open failure\n");
}

free(png);
return result;
}

void setup()
{
lcd.init();

Serial.begin(115200);

lcd.setColorDepth(24);

lcd.setColor(TFT_WHITE);
lcd.startWrite();
for (int x = 0; x < 128; ++x)
{
for (int y = 0; y < 128; ++y)
{
lcd.writePixel(x, y, lcd.color888(x << 1, x + y, y << 1));
}
}
lcd.print("PNG save test\n");
lcd.endWrite();

do {
SD.end();
delay(1000);

SD.begin(SDCARD_SS_PIN, SDCARD_SPI, 25000000);

} while (!saveToSD());


lcd.print("PNG save success.");
}

void loop(void)
{
delay(1000);
}
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"type": "git",
"url": "https://github.com/lovyan03/LovyanGFX"
},
"version": "0.2.4",
"version": "0.2.5",
"framework": "arduino, espidf",
"platforms": "espressif32, atmelsam",
"build": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=LovyanGFX
version=0.2.4
version=0.2.5
author=lovyan03
maintainer=Lovyan <[email protected]>
sentence=LCD Graphics driver with touch for ESP32 and SAMD51
Expand Down
2 changes: 2 additions & 0 deletions src/LovyanGFX.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Original Source:
#undef setFont
#endif

#include "gitTagVersion.h"

#include "lgfx/lgfx_common.hpp" // common include (always include)

#include "lgfx/lgfx_filesystem_support.hpp" // filesystem extention (optional)
Expand Down
Loading

0 comments on commit b1e9255

Please sign in to comment.