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

improve text demo, clamp hue in hsv() utility function #59

Merged
merged 1 commit into from
Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions examples/text/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,11 @@ Lo, brave adventurer! Choose a tasty treat:\

title("Effects");

auto centre_text = [](std::string message, int32_t y, int32_t xo = 0) {
int32_t w, h;
measure(message, w, h);
text(message, 60 - (w / 2) + xo, y);
};
static float hue = 0.0f, hue_step = 1.0f / 7.0f;
color_t c1, c2;
hue += 0.01f;


std::string m;

// shadow text
auto shadow_text = [](std::string m, color_t c, color_t s, int32_t x, int32_t y, int32_t sx, int32_t sy) {
Expand All @@ -153,7 +151,8 @@ Lo, brave adventurer! Choose a tasty treat:\
text(m, x, y);
};
int32_t sx = sin(time() / 250.0f) * 3.0f;
shadow_text("Shadow text example", rgb(13, 13, 15), rgb(7, 7, 9, 4), 7, 20, sx, 2);
c1 = hsv(hue + (hue_step * 0), 0.8f, 1.0f);
shadow_text("Shadow text example", c1, rgb(7, 7, 9, 4), 7, 20, sx, 2);

// gradient text
auto gradient_text = [](std::string m, color_t c1, color_t c2, int32_t x, int32_t y) {
Expand All @@ -164,10 +163,7 @@ Lo, brave adventurer! Choose a tasty treat:\
pen(c2); clip(0, y + 6, 120, 2); text(m, x, y);
clip();
};
static float hue = 0.0f;
hue += 0.01f;
if(hue > 1.0f) hue = 0.0f;
color_t c1 = hsv(hue, 0.8f, 1.0f), c2 = hsv(hue, 0.6f, 0.75);
c1 = hsv(hue + (hue_step * 1), 0.8f, 1.0f); c2 = hsv(hue + (hue_step * 1), 0.8f, 1.0f);
gradient_text("Gradient text example", c1, c2, 5, 35);

// outline text
Expand All @@ -184,7 +180,8 @@ Lo, brave adventurer! Choose a tasty treat:\
text(m, x, y);
};
int32_t o = 1 + ((sin(time() / 250.0f) + 1.0f) * 2.0f);
outline_text("Outline text example", rgb(2, 14, 2), 10, 50, o);
c1 = hsv(hue + (hue_step * 2), 0.8f, 1.0f);
outline_text("Outline text example", c1, 10, 50, o);

// extrude text
auto extrude_text = [](std::string m, color_t c, color_t s, int32_t x, int32_t y, int32_t l) {
Expand All @@ -197,7 +194,8 @@ Lo, brave adventurer! Choose a tasty treat:\
text(m, x, y);
};
int32_t l = 1 + ((sin(time() / 250.0f) + 1.0f) * 2.0f);
extrude_text("Extrude text example", rgb(0, 15, 15), rgb(15, 0, 0, 12), 5, 65, l);
c1 = hsv(hue + (hue_step * 3), 0.8f, 1.0f); c2 = hsv(hue + (hue_step * 3) + 0.1f, 0.6f, 0.8f);
extrude_text("Extrude text example", c1, c2, 5, 65, l);


auto split_text = [](std::string m, color_t c1, color_t c2, int32_t x, int32_t y) {
Expand All @@ -214,7 +212,8 @@ Lo, brave adventurer! Choose a tasty treat:\
// split text
float hue2 = hue + 0.5;
if(hue2 > 1.0f) hue2 -= 1.0f;
split_text("Split text example", hsv(hue2, 0.6f, 1.0f), hsv(hue, 0.4f, 1.0f), 15, 80);
c1 = hsv(hue + (hue_step * 4), 0.8f, 1.0f); c2 = hsv(hue + (hue_step * 4) + 0.1f, 0.4f, 0.6f);
split_text("Split text example", c1, c2, 15, 80);

// glow text
auto glow_text = [](std::string m, color_t c, int32_t x, int32_t y) {
Expand All @@ -228,7 +227,8 @@ Lo, brave adventurer! Choose a tasty treat:\
text(m, x, y);
};
int32_t g = 1 + ((sin(time() / 250.0f) + 1.0f) * 2.0f);
glow_text("Glow text example", hsv(hue, 1.0f, 1.0f, 0.2f), 15, 95);
c1 = hsv(hue + (hue_step * 5), 0.8f, 1.0f, 0.2f);
glow_text("Glow text example", c1, 15, 95);

// glitch text
auto glitch_text = [](std::string m, color_t c, int32_t x, int32_t y) {
Expand All @@ -246,7 +246,8 @@ Lo, brave adventurer! Choose a tasty treat:\
};

// split text
glitch_text("Glitch text example", rgb(6, 15, 12), 13, 110);
c1 = hsv(hue + (hue_step * 6), 0.8f, 1.0f);
glitch_text("Glitch text example", c1, 13, 110);

}break;
}
Expand Down
1 change: 1 addition & 0 deletions libraries/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace picosystem {
}

color_t hsv(float h, float s, float v, float a) {
h = h - floor(h); // clamp to 0..1
float i = floor(h * 6.0f);
float f = h * 6.0f - i;
v *= 15.0f;
Expand Down