example: updated particle
Some checks are pending
Android / build_x86_64 (push) Waiting to run
Android / build_aarch64 (push) Waiting to run
iOS / build_x86_64 (push) Waiting to run
iOS / build_arm64 (push) Waiting to run
macOS / build (push) Waiting to run
macOS / compact_test (push) Waiting to run
macOS / unit_test (push) Waiting to run
Ubuntu / build (push) Waiting to run
Ubuntu / compact_test (push) Waiting to run
Ubuntu / unit_test (push) Waiting to run
Windows / build (push) Waiting to run
Windows / compact_test (push) Waiting to run
Windows / unit_test (push) Waiting to run

- arrange the particle bg brightness
- added clouds effects
This commit is contained in:
Hermet Park 2025-06-19 12:58:14 +09:00 committed by Hermet Park
parent 2c048f72e8
commit e20562c8c2
3 changed files with 45 additions and 11 deletions

View file

@ -29,13 +29,15 @@
struct UserExample : tvgexam::Example struct UserExample : tvgexam::Example
{ {
struct Particle { struct Particle {
tvg::Shape* shape; tvg::Paint* obj;
float x, y; float x, y;
float speed; float speed;
float size;
}; };
const float COUNT = 1200.0f; const float COUNT = 1200.0f;
std::vector<Particle> rects; std::vector<Particle> raindrops;
std::vector<Particle> clouds;
uint32_t w, h; uint32_t w, h;
@ -49,19 +51,42 @@ struct UserExample : tvgexam::Example
city->load(EXAMPLE_DIR"/image/particle.jpg"); city->load(EXAMPLE_DIR"/image/particle.jpg");
canvas->push(city); canvas->push(city);
auto night = tvg::Shape::gen(); auto cloud1 = tvg::Picture::gen();
night->appendRect(0, 0, w, h); cloud1->load(EXAMPLE_DIR"/image/clouds.png");
night->fill(0, 0, 0, 220); cloud1->opacity(60);
canvas->push(night); canvas->push(cloud1);
float size;
cloud1->size(&size, nullptr);
clouds.push_back({cloud1, 0, 0, 0.25f, size});
auto cloud2 = cloud1->duplicate();
cloud2->opacity(30);
cloud2->translate(400, 100);
canvas->push(cloud2);
clouds.push_back({cloud2, 400, 100, 0.125f, size});
auto cloud3 = cloud1->duplicate();
cloud3->opacity(20);
cloud3->translate(1200, 200);
canvas->push(cloud3);
clouds.push_back({cloud3, 1200, 200, 0.075f, size});
auto darkness = tvg::Shape::gen();
darkness->appendRect(0, 0, w, h);
darkness->fill(0, 0, 0, 150);
canvas->push(darkness);
//rain drops //rain drops
auto size = w / COUNT; size = w / COUNT;
rects.reserve(COUNT); raindrops.reserve(COUNT);
for (int i = 0; i < COUNT; ++i) { for (int i = 0; i < COUNT; ++i) {
auto shape = tvg::Shape::gen(); auto shape = tvg::Shape::gen();
float x = size * i; float x = size * i;
rects.push_back({shape, x, float(rand()%h), 10 + float(rand() % 100) * 0.1f}); raindrops.push_back({shape, x, float(rand()%h), 10 + float(rand() % 100) * 0.1f, 0 /* unused */});
shape->appendRect(0, 0, 1, rand() % 15 + size); shape->appendRect(0, 0, 1, rand() % 15 + size);
shape->fill(255, 255, 255, 55 + rand() % 100); shape->fill(255, 255, 255, 55 + rand() % 100);
canvas->push(shape); canvas->push(shape);
@ -76,13 +101,22 @@ struct UserExample : tvgexam::Example
bool update(tvg::Canvas* canvas, uint32_t elapsed) override bool update(tvg::Canvas* canvas, uint32_t elapsed) override
{ {
if (!canvas) return false; if (!canvas) return false;
for (auto& p : rects) { for (auto& p : raindrops) {
p.y += p.speed; p.y += p.speed;
if (p.y > h) { if (p.y > h) {
p.y -= h; p.y -= h;
} }
p.shape->translate(p.x, p.y); p.obj->translate(p.x, p.y);
} }
for (auto& p : clouds) {
p.x -= p.speed;
if (p.x + p.size < 0) {
p.x = w;
}
p.obj->translate(p.x, p.y);
}
canvas->update(); canvas->update();
return true; return true;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 974 KiB

After

Width:  |  Height:  |  Size: 973 KiB