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

Feature: New RGB Animation "Starlight Smooth" #24137

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

hbbit-dev
Copy link
Contributor

@hbbit-dev hbbit-dev commented Jul 18, 2024

Description

New RGB Matrix animation compatible with all keyboards. Will link a video below. I made a previous pull request to add starlight, starlight dual hue, starlight dual sat, and at the last minute I changed the name of starlight smooth to "riverflow" because it didn't have the randomness I was looking for, it was essentially just an angled wave.

I've sat down and tried again this past week and was able to get it to what I originally had in mind for starlight smooth. LEDs randomly raise and lower in brightness, speed and color can be controlled by the user. Updates to the docs as well.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Issues Fixed or Closed by This PR

  • none

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Supporting Media

output.mp4

@hbbit-dev
Copy link
Contributor Author

@filterpaper thank you for these change suggestions, and for fixing my embarrassing typo in the effect name...I have made those changes and tested the animation, still works as expected.

@tzarc tzarc added the develop-fast-track Intended to be merged early in the next develop cycle. label Aug 12, 2024
Copy link
Member

@KarlK90 KarlK90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hbbit-dev Thanks for the new effect, looks nice. The code changes LGTM. There is one remaining suggestion from filterpaper that would be worth including?

@filterpaper
Copy link
Contributor

filterpaper commented Oct 15, 2024

The RGB and HSV structs can be updated to rgb_t and hsv_t with #24476 merged. The effect_runner_i can also be used to reduce code size:

#ifdef ENABLE_RGB_MATRIX_STARLIGHT_SMOOTH
RGB_MATRIX_EFFECT(STARLIGHT_SMOOTH)
#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS

static uint16_t time_offsets[RGB_MATRIX_LED_COUNT];

hsv_t STARLIGHT_SMOOTH_maths(hsv_t hsv, uint8_t i, uint8_t time) {
    uint16_t time = scale16by8((g_rgb_timer / 2) + time_offsets[i], rgb_matrix_config.speed / 16);
    hsv.v         = scale8(abs8(sin8(time) - 128) * 2, hsv.v);
    return hsv;
}

bool STARLIGHT_SMOOTH(effect_params_t* params) {
    if (params->init) {
        for (uint8_t i = 0; i < RGB_MATRIX_LED_COUNT; i++) {
            time_offsets[i] = random16_max(65000);
        }
    }

    return effect_runner_i(params, &STARLIGHT_SMOOTH_maths);
}

#    endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
#endif     // ENABLE_RGB_MATRIX_STARLIGHT_SMOOTH

Replacing time with hsv.h will make the starlight light multi-coloured.

@drashna
Copy link
Member

drashna commented Oct 25, 2024

The RGB and HSV structs can be updated to rgb_t and hsv_t with #24476 merged. The effect_runner_i can also be used to reduce code size:

#ifdef ENABLE_RGB_MATRIX_STARLIGHT_SMOOTH
RGB_MATRIX_EFFECT(STARLIGHT_SMOOTH)
#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS

static uint16_t time_offsets[RGB_MATRIX_LED_COUNT];

hsv_t STARLIGHT_SMOOTH_maths(hsv_t hsv, uint8_t i, uint8_t time) {
    uint16_t time = scale16by8((g_rgb_timer / 2) + time_offsets[i], rgb_matrix_config.speed / 16);
    hsv.v         = scale8(abs8(sin8(time) - 128) * 2, hsv.v);
    return hsv;
}

bool STARLIGHT_SMOOTH(effect_params_t* params) {
    if (params->init) {
        for (uint8_t i = 0; i < RGB_MATRIX_LED_COUNT; i++) {
            time_offsets[i] = random16_max(65000);
        }
    }

    return effect_runner_i(params, &STARLIGHT_SMOOTH_maths);
}

#    endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
#endif     // ENABLE_RGB_MATRIX_STARLIGHT_SMOOTH

Replacing time with hsv.h will make the starlight light multi-coloured.

This code block doesn't work, as time is a parameter, so you can't redefine it. (but setting uint16_t time = , and time in the next line to a different name does appear to work)

@filterpaper
Copy link
Contributor

filterpaper commented Oct 25, 2024

This code block doesn't work, as time is a parameter, so you can't redefine it. (but setting uint16_t time = , and time in the next line to a different name does appear to work)

Corrected:

#ifdef ENABLE_RGB_MATRIX_STARLIGHT_SMOOTH
RGB_MATRIX_EFFECT(STARLIGHT_SMOOTH)
#    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS

static uint16_t time_offsets[RGB_MATRIX_LED_COUNT];

hsv_t STARLIGHT_SMOOTH_math(hsv_t hsv, uint8_t i, uint8_t time) {
    time  = scale16by8((g_rgb_timer / 2) + time_offsets[i], rgb_matrix_config.speed / 16);
    hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v);
    return hsv;
}

bool STARLIGHT_SMOOTH(effect_params_t* params) {
    if (params->init) {
        for (uint8_t i = 0; i < RGB_MATRIX_LED_COUNT; i++) {
            time_offsets[i] = random16_max(65000);
        }
    }

    return effect_runner_i(params, &STARLIGHT_SMOOTH_math);
}

#    endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
#endif     // ENABLE_RGB_MATRIX_STARLIGHT_SMOOTH

The existing PR could be merged and it can be refactored with the above later.

@filterpaper filterpaper mentioned this pull request Oct 28, 2024
14 tasks
Copy link

Thank you for your contribution!
This pull request has been automatically marked as stale because it has not had activity in the last 45 days. It will be closed in 30 days if no further activity occurs. Please feel free to give a status update now, or re-open when it's ready.
For maintainers: Please label with bug, awaiting review, breaking_change, in progress, or on hold to prevent the issue from being re-flagged.

@github-actions github-actions bot added the stale Issues or pull requests that have become inactive without resolution. label Dec 12, 2024
Comment on lines +5 to +6
bool STARLIGHT_SMOOTH(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool STARLIGHT_SMOOTH(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
static uint16_t time_offsets[RGB_MATRIX_LED_COUNT];

bool STARLIGHT_SMOOTH(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);

static uint16_t time_offsets[RGB_MATRIX_LED_COUNT] = {0};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static uint16_t time_offsets[RGB_MATRIX_LED_COUNT] = {0};
hsv_t STARLIGHT_SMOOTH_math(hsv_t hsv, uint8_t i, uint8_t time) {
time = scale16by8((g_rgb_timer / 2) + time_offsets[i], rgb_matrix_config.speed / 16);
hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v);
return hsv;
}
bool STARTLIGHT_SMOOTH(effect_params_t *params) {

Comment on lines +16 to +27
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();

uint16_t time = scale16by8((g_rgb_timer / 2) + time_offsets[i], rgb_matrix_config.speed / 16);
HSV hsv = rgb_matrix_config.hsv;
hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v);
RGB rgb = rgb_matrix_hsv_to_rgb(hsv);

rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}

return rgb_matrix_check_finished_leds(led_max);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
uint16_t time = scale16by8((g_rgb_timer / 2) + time_offsets[i], rgb_matrix_config.speed / 16);
HSV hsv = rgb_matrix_config.hsv;
hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v);
RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return rgb_matrix_check_finished_leds(led_max);
return effect_runner_i (params, &STARLIGHT_SMOOTH_math);

@github-actions github-actions bot removed the stale Issues or pull requests that have become inactive without resolution. label Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core develop-fast-track Intended to be merged early in the next develop cycle. documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants