Skip to content

Commit

Permalink
Shuffle csp icons in the same location
Browse files Browse the repository at this point in the history
  • Loading branch information
seokho-son committed May 20, 2024
1 parent bda1c17 commit 856f637
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3147,8 +3147,18 @@ window.onload = function () {
getMcis();
};

// Draw
let drawCounter = 0;
const shuffleInterval = 100; // Shuffle every 100 draws
let shuffledKeys = Object.keys(cspIconStyles); // Initialize with original keys

function shuffleKeys() {
shuffledKeys = Object.keys(cspIconStyles)
.map((key) => ({ key, sort: Math.random() })) // Map to array of objects with random sort values
.sort((a, b) => a.sort - b.sort) // Sort by random values
.map(({ key }) => key); // Extract the keys
}

// Draw
function drawObjects(event) {
//event.frameState = event.frameState / 10;
//console.log("event.frameState");
Expand All @@ -3158,11 +3168,17 @@ function drawObjects(event) {
var frameState = event.frameState;
var theta = (2 * Math.PI * frameState.time) / omegaTheta;

// Draw CSP location first
Object.keys(cspIconStyles).forEach((csp) => {
if (Array.isArray(geoCspPoints[csp]) && geoCspPoints[csp].length) {
vectorContext.setStyle(cspIconStyles[csp]);
vectorContext.drawGeometry(geoCspPoints[csp][0]);
// Shuffle keys every shuffleInterval draws
drawCounter++;
if (drawCounter % shuffleInterval === 0) {
shuffleKeys();
}

// Draw CSP location first with the stored random order
shuffledKeys.forEach((key) => {
if (Array.isArray(geoCspPoints[key]) && geoCspPoints[key].length) {
vectorContext.setStyle(cspIconStyles[key]);
vectorContext.drawGeometry(geoCspPoints[key][0]);
}
});

Expand Down

0 comments on commit 856f637

Please sign in to comment.