From 551326da47d849dc336fb01ceaaba80b8154b65a Mon Sep 17 00:00:00 2001 From: Malte Schmitz <malte@schmitz-sh.de> Date: Sun, 29 May 2022 22:27:22 +0200 Subject: [PATCH] Use fill --- src/main.cpp | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1e3030c..616d953 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -101,18 +101,12 @@ int state = STATE_PAUSE; void show() { pixels.clear(); if (state == STATE_PAUSE) { - for (int i = 0; i < greenLength; i++) { - pixels.setPixelColor(i, 0x00FF00); - } + pixels.fill(0x00FF00, 0, greenLength); if (singlePlayer) { - for (int i = NEOPIXEL_LEN / 2; i < NEOPIXEL_LEN; i++) { - pixels.setPixelColor(i, 0x0000FF); - } + pixels.fill(0x0000FF, NEOPIXEL_LEN / 2); } else { - for (int i = NEOPIXEL_LEN - greenLength - 1; i < NEOPIXEL_LEN; i++) { - pixels.setPixelColor(i, 0x00FF00); - } - + pixels.fill(0x00FF00, NEOPIXEL_LEN - greenLength - 1); + int points = pointsInternal; if (lastPointInternal && hideLastPoint) { points = max(0, points - 1); @@ -131,17 +125,11 @@ void show() { } } else if (state == STATE_FORWARD || state == STATE_BACKWARD) { - for (int i = 0; i < greenLength; i++) { - pixels.setPixelColor(i, 0x00FF00); - } + pixels.fill(0x00FF00, 0, greenLength); if (singlePlayer) { - for (int i = NEOPIXEL_LEN / 2; i < NEOPIXEL_LEN; i++) { - pixels.setPixelColor(i, 0x0000FF); - } + pixels.fill(0x0000FF, NEOPIXEL_LEN / 2); } else { - for (int i = NEOPIXEL_LEN - greenLength - 1; i < NEOPIXEL_LEN; i++) { - pixels.setPixelColor(i, 0x00FF00); - } + pixels.fill(0x00FF00, NEOPIXEL_LEN - greenLength - 1); } pixels.setPixelColor(position, 0xFFFFFF); } @@ -231,18 +219,14 @@ void handleButton() { void handleExternalMissedAnimation() { int step = (100 - taskExternalMissedAnimation.getIterations()) % 25; pixels.clear(); - for (int i = NEOPIXEL_LEN - 1 - 25; i < NEOPIXEL_LEN - 25 + step; i++) { - pixels.setPixelColor(i, 0xFF0000); - } + pixels.fill(0xFF0000, NEOPIXEL_LEN - 1 - 25, step + 1); pixels.show(); } void handleInternalMissedAnimation() { int step = (100 - taskInternalMissedAnimation.getIterations()) % 25; pixels.clear(); - for (int i = 25 - step; i < 25; i++) { - pixels.setPixelColor(i, 0xFF0000); - } + pixels.fill(0xFF0000, 25 - step, step + 1); pixels.show(); } -- GitLab