Skip to content

Instantly share code, notes, and snippets.

@TheStaticTurtle
Created June 15, 2022 07:01
Show Gist options
  • Save TheStaticTurtle/dd08adde66372487933701fcec25eba2 to your computer and use it in GitHub Desktop.
Save TheStaticTurtle/dd08adde66372487933701fcec25eba2 to your computer and use it in GitHub Desktop.
Simple spinner with variable speed and size
//Call at least every 10ms
void oled_spinner() {
int x = 64, y = 35, r = 15;
static uint32_t millis = board_millis();
static float angle = 0;
if (board_millis() - millis < 10) return;
millis += 10;
oledFill(&oled, 0x00, false);
angle += (angle - 3.1415) * (angle - 3.1415) / 130 + 0.08;
float size = (angle - 3.1415) * (angle - 3.1415) / 20 + 0.55;
float spinner_start_angle = angle;
float spinner_end_angle = spinner_start_angle + size;
for (float spinner_angle = spinner_start_angle; spinner_angle < spinner_end_angle; spinner_angle += 0.05) {
for(float thickness=0; thickness < 2.5; thickness += 0.5) {
oledSetPixel(&oled, x + cos(spinner_angle) * (r-thickness), y + sin(spinner_angle) * (r-thickness), 0x01, false);
}
}
if(angle > 6.28) angle = 0;
oledDumpBuffer(&oled, oled_buffer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment