mirror of
https://github.com/bspeice/speice.io
synced 2025-07-05 07:44:54 -04:00
Fix final transform modifying coordinates
This commit is contained in:
@ -5,9 +5,9 @@ import {ChaosGameFinalProps} from "../2-transforms/chaosGameFinal";
|
||||
import {camera, histIndex} from "../src/camera";
|
||||
// hidden-end
|
||||
export type ChaosGameHistogramProps = ChaosGameFinalProps & {
|
||||
painter: (width: number, histogram: Uint32Array) => ImageData;
|
||||
paint: (width: number, histogram: Uint32Array) => ImageData;
|
||||
}
|
||||
export function* chaosGameHistogram({width, height, transforms, final, quality, step, painter}: ChaosGameHistogramProps) {
|
||||
export function* chaosGameHistogram({width, height, transforms, final, quality, step, paint}: ChaosGameHistogramProps) {
|
||||
let iterations = (quality ?? 1) * width * height;
|
||||
step = step ?? 100_000;
|
||||
|
||||
@ -18,17 +18,17 @@ export function* chaosGameHistogram({width, height, transforms, final, quality,
|
||||
for (let i = 0; i < iterations; i++) {
|
||||
const [_, transform] = randomChoice(transforms);
|
||||
[x, y] = transform(x, y);
|
||||
[x, y] = final(x, y);
|
||||
const [finalX, finalY] = final(x, y);
|
||||
|
||||
if (i > 20) {
|
||||
const [pixelX, pixelY] = camera(x, y, width);
|
||||
const [pixelX, pixelY] = camera(finalX, finalY, width);
|
||||
const pixelIndex = histIndex(pixelX, pixelY, width, 1);
|
||||
histogram[pixelIndex] += 1;
|
||||
}
|
||||
|
||||
if (i % step === 0)
|
||||
yield painter(width, histogram);
|
||||
yield paint(width, histogram);
|
||||
}
|
||||
|
||||
yield painter(width, histogram);
|
||||
yield paint(width, histogram);
|
||||
}
|
Reference in New Issue
Block a user