asigalov61 commited on
Commit
8559cde
·
1 Parent(s): 7426207

Update javascript/app.js

Browse files
Files changed (1) hide show
  1. javascript/app.js +23 -18
javascript/app.js CHANGED
@@ -169,24 +169,29 @@ class MidiVisualizer extends HTMLElement{
169
  }
170
 
171
  getColor(track, channel) {
172
- // Create a unique hash for each track and channel combination
173
- let hash = track * 1000 + channel;
174
-
175
- // Convert the hash to a color
176
- let color = hashToColor(hash);
177
-
178
- return color;
179
- }
180
-
181
- // Function to convert a hash to an RGB color
182
- hashToColor(hash) {
183
- // Use bitwise operations to extract RGB components
184
- let r = (hash & 0xFF0000) >> 16;
185
- let g = (hash & 0x00FF00) >> 8;
186
- let b = hash & 0x0000FF;
187
-
188
- // Convert RGB values to a CSS color string
189
- return `rgb(${r}, ${g}, ${b}, 1)`;
 
 
 
 
 
190
  }
191
 
192
 
 
169
  }
170
 
171
  getColor(track, channel) {
172
+ const colors = [
173
+ [255, 0, 0], // Red
174
+ [255, 255, 0], // Yellow
175
+ [0, 128, 0], // Green
176
+ [0, 255, 255], // Cyan
177
+ [0, 0, 255], // Blue
178
+ [255, 192, 203], // Pink
179
+ [255, 165, 0], // Orange
180
+ [128, 0, 128], // Purple
181
+ [128, 128, 128], // Gray
182
+ [255, 255, 255], // White
183
+ [255, 215, 0], // Gold
184
+ [192, 192, 192] // Silver
185
+ ];
186
+
187
+ // Calculate an index based on the track and channel
188
+ const index = (track + channel) % colors.length;
189
+
190
+ // Get the RGB values from the colors array
191
+ const [r, g, b] = colors[index];
192
+
193
+ // Return the RGB color in the format "rgb(r, g, b)"
194
+ return `r: ${r}, g: ${g}, b: ${b})`;
195
  }
196
 
197