From 299272b7aafaa6c2dcb4ebce690c947b53af1f95 Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Tue, 19 Mar 2024 15:14:23 +0800 Subject: [PATCH] Shiny orb What could it be? --- app_render.cpp | 16 ++++++++++++++++ render_pattern.c | 8 ++++++-- render_pattern.h | 15 ++++++++++++++- render_util.cpp | 16 ++++++++++------ render_util.h | 7 ++++--- 5 files changed, 50 insertions(+), 12 deletions(-) diff --git a/app_render.cpp b/app_render.cpp index 726650f..6fe8e85 100644 --- a/app_render.cpp +++ b/app_render.cpp @@ -4,10 +4,17 @@ #include "physics.h" #include "easyx.h" #include "util/tree.h" +#include "types.h" +#include "render_util.h" #include #include +namespace { +TimePoint since = time_Now(); +} // namespace + + extern "C" { @@ -30,5 +37,14 @@ void app_Render(App *app) { (int)round(box.lefttop.y + box.size.y)); } } + + static FillMode mode_rotate = { + .rotate = Duration{.microseconds = 100 * 1000}}; + + + setfillcolor(RGB(255, 255, 255)); + setbkcolor(RGB(0, 0, 0)); + render_SetModes(mode_rotate, since); + render_FillCircleW(app, vec2(200, 100), 20); } } diff --git a/render_pattern.c b/render_pattern.c index b849075..7946034 100644 --- a/render_pattern.c +++ b/render_pattern.c @@ -2,16 +2,20 @@ #include -BYTE *render_DissolvePattern(double progress) { +BYTE *render_DissolvePatternOut(double progress) { if (progress < .0) progress = .0; if (progress > 1.0) progress = 1.0; - int index = round(progress * 65); + int index = round(progress * 64); return (BYTE *)(render_DissolvePatternData + index * 8); } +BYTE *render_DissolvePatternIn(double progress) { + return render_DissolvePatternOut(1.0 - progress); +} + // generated from test_generate_pattern.cpp char render_DissolvePatternData[520] = diff --git a/render_pattern.h b/render_pattern.h index 42de8b9..956f2b8 100644 --- a/render_pattern.h +++ b/render_pattern.h @@ -3,8 +3,21 @@ // for BYTE #include +#ifdef __cplusplus +extern "C" { +#endif + // Returns a dissolve pattern for the given progress in [0,1] -BYTE *render_DissolvePattern(double progress); +// From empty to full +BYTE *render_DissolvePatternIn(double progress); +// From full to empty +BYTE *render_DissolvePatternOut(double progress); + // The underlying data. 520 bytes extern char render_DissolvePatternData[520]; + + +#ifdef __cplusplus +} +#endif diff --git a/render_util.cpp b/render_util.cpp index b4323c9..51c411d 100644 --- a/render_util.cpp +++ b/render_util.cpp @@ -52,21 +52,25 @@ const FillMode render_DefaultMode = { .style = BS_SOLID, .hatch = 0, .rotate = {.microseconds = 0}, - .dissolve = {.microseconds = 0}}; + .dissolve = {.microseconds = 0}, + .fadein = false}; void render_SetModes(FillMode mode, TimePoint since) { if (mode.dissolve.microseconds != 0) { // Dissolve mode double progress = duration_Seconds(time_Since(since)) / duration_Seconds(mode.dissolve); - setfillstyle(render_DissolvePattern(progress)); // progress is capped into [0,1] in this func + if (mode.fadein) + setfillstyle(render_DissolvePatternIn(progress)); // progress is capped into [0,1] in this func + else + setfillstyle(render_DissolvePatternOut(progress)); setrop2(R2_COPYPEN); return; } if (mode.rotate.microseconds != 0) { // Rotate mode - int steps = round(duration_Seconds(time_Since(since)) / duration_Seconds(mode.dissolve)); + int steps = round(duration_Seconds(time_Since(since)) / duration_Seconds(mode.rotate)); static const long hatches[] = {HS_HORIZONTAL, HS_FDIAGONAL, HS_VERTICAL, HS_BDIAGONAL}; setfillstyle(BS_HATCHED, hatches[steps % 4], NULL); @@ -79,11 +83,11 @@ void render_SetModes(FillMode mode, TimePoint since) { setrop2(mode.rop2); } -void render_FillScreen(FillMode mode, TimePoint since) { +void render_FillScreen() { solidrectangle(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); } -void render_FillRectW(App *app, Box2 rect, FillMode mode, TimePoint since) { +void render_FillRectW(App *app, Box2 rect) { if (app->camera) rect = camera_TransformBox2(app->camera, rect); else @@ -95,7 +99,7 @@ void render_FillRectW(App *app, Box2 rect, FillMode mode, TimePoint since) { (int)round(rect.lefttop.y + rect.size.y)); } -void render_FillCircleW(App *app, Vec2 center, double radius, FillMode mode, TimePoint since) { +void render_FillCircleW(App *app, Vec2 center, double radius) { if (app->camera) { center = camera_TransformVec2(app->camera, center); radius = camera_TransformSize(app->camera, vec2(radius, 0)).x; // TODO non-aspect scaling diff --git a/render_util.h b/render_util.h index 482ecfa..4f1dd6c 100644 --- a/render_util.h +++ b/render_util.h @@ -42,6 +42,7 @@ typedef struct { // Dissolve the entire screen in an animation in this // amount of time. Overrides rotate, style & hatch Duration dissolve; + bool fadein; // Fade Into being full for true, fade out of otherwise } FillMode; // Default fill mode. @@ -56,12 +57,12 @@ typedef struct _App App; void render_SetModes(FillMode mode, TimePoint since); // Fills the entire screen -void render_FillScreen(FillMode mode, TimePoint since); +void render_FillScreen(); // Fills a rectangle in world coordinates -void render_FillRectW(App *app, Box2 rect, FillMode mode, TimePoint since); +void render_FillRectW(App *app, Box2 rect); // Fills a circle in world coordinates -void render_FillCircleW(App *app, Vec2 center, double radius, FillMode mode, TimePoint since); +void render_FillCircleW(App *app, Vec2 center, double radius); #ifdef __cplusplus