mirror of
https://github.com/bspeice/speice.io
synced 2024-12-23 00:58:09 -05:00
Bradlee Speice
79b66337e8
It takes a lot of render time to get a usable result, and it's not that interesting. Committing so I can save the work if I want to revisit it, but abandoning the idea for now.
23 lines
784 B
TypeScript
23 lines
784 B
TypeScript
// hidden-start
|
|
import {camera, histIndex} from "../src/camera";
|
|
// hidden-end
|
|
export function plot(x: number, y: number, width: number, hitCount: Uint32Array) {
|
|
const [pixelX, pixelY] = camera(x, y, width);
|
|
const pixelIndex = histIndex(pixelX, pixelY, width, 1);
|
|
hitCount[pixelIndex] += 1;
|
|
}
|
|
|
|
export type PlotData = {x: number, y: number}[];
|
|
export function plotHistogram(hitCount: Uint32Array) {
|
|
const data = new Map<number, number>();
|
|
hitCount.forEach(value => {
|
|
const bucket = 32 - Math.clz32(value);
|
|
const currentCount = data.get(bucket) ?? 0;
|
|
data.set(bucket, currentCount + 1);
|
|
})
|
|
|
|
const output: PlotData = [];
|
|
data.forEach((value, bucket) =>
|
|
output.push({x: Math.pow(2, bucket), y: value}));
|
|
return output;
|
|
} |