Skip to content

Commit

Permalink
feat: improve color
Browse files Browse the repository at this point in the history
  • Loading branch information
rei1024 committed Oct 21, 2024
1 parent bdb312e commit 2bc1c67
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
Binary file modified public/p96_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 3 additions & 5 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export function dataToColor(list: number[], data: number) {
const value = index / list.length;

// 80% 0.1
return `oklch(92% 0.35 ${value * 360})`;
// return `lch(70% 70 ${value * 360})`;
// return `oklch(92% 0.35 ${value * 360})`;
return `lch(70% 70 ${value * 360})`;
// return `hsl(${value * 360} 100% 70%)`;

// Heap map
Expand Down Expand Up @@ -244,9 +244,7 @@ export class App {

const mapData = this.getMapData();
const cellData = mapData.data[y][x];
const index = mapData.list
.filter((x) => x !== 0)
.findIndex((x) => x === cellData);
const index = mapData.list.findIndex((x) => x === cellData);
if (index === -1) {
return undefined;
}
Expand Down
17 changes: 10 additions & 7 deletions src/lib/getMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,22 @@ export function getMap({
periodArray[y][x] = findPeriod(states);
});

const periodCountMap = getCountMap(periodArray);
periodCountMap.delete(0);

const frequencyCountMap = getCountMap(frequencyArray);
frequencyCountMap.delete(0);

return {
periodMap: {
data: periodArray,
list: mapUnique(periodArray),
countMap: getCountMap(periodArray),
list: mapUnique(periodArray).filter((x) => x !== 0),
countMap: periodCountMap,
},
frequencyMap: {
data: frequencyArray,
list: mapUnique(frequencyArray),
countMap: getCountMap(frequencyArray),
list: mapUnique(frequencyArray).filter((x) => x !== 0),
countMap: frequencyCountMap,
},
};
}
Expand All @@ -78,9 +84,6 @@ function getCountMap(map: number[][]): Map<number, number> {
const countMap = new Map<number, number>();
for (const row of map) {
for (const x of row) {
if (x === 0) {
continue;
}
const currentCount = countMap.get(x);
if (currentCount !== undefined) {
countMap.set(x, currentCount + 1);
Expand Down
3 changes: 0 additions & 3 deletions src/ui/colorTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ export function setColorTable(
}

for (const item of list) {
if (item === 0) {
continue;
}
const row = document.createElement("tr");
const color = dataToColor(list, item);
const $color = document.createElement("td");
Expand Down

0 comments on commit 2bc1c67

Please sign in to comment.