Skip to content

Commit a25cb69

Browse files
committed
make pulses random order
1 parent 9a02249 commit a25cb69

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

‎src/components/Stats.js‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,26 @@ function StatsNumber({number, text}) {
2020
);
2121
}
2222

23+
function pickRandomIntBetween(int1, int2) {
24+
const min = Math.min(int1, int2);
25+
const max = Math.max(int1, int2);
26+
27+
// To make it inclusive, need max + 1
28+
return Math.floor(min + Math.random() * (max + 1 - min));
29+
}
30+
2331
export default function Stats({stats, setDisplay}) {
24-
let pulseOrder = 0;
32+
const maxPulseOrder = stats.collectedSwatchIndexes.length;
33+
2534
const swatches = palette.map((colors, index) => {
2635
const isColored = stats.collectedSwatchIndexes.includes(index);
2736

28-
if (isColored) {
29-
pulseOrder++;
30-
}
31-
3237
return isColored ? (
3338
<Swatch
3439
color={calculateMixedColor(colors)}
35-
pulseOrder={pulseOrder}
40+
// Doing pulseOrder like this to give the possibility of having multiple swatches pulse at the same time.
41+
// The animation is fast enough that the pause if that happens still looks cohesive.
42+
pulseOrder={pickRandomIntBetween(1, maxPulseOrder)}
3643
key={colors}
3744
></Swatch>
3845
) : (

0 commit comments

Comments
 (0)