2024-11-24 22:37:53 -05:00
|
|
|
// hidden-start
|
|
|
|
import { randomBiUnit } from "../src/randomBiUnit";
|
|
|
|
import { randomChoice } from "../src/randomChoice";
|
|
|
|
import { plot } from "./plot"
|
2024-11-29 23:08:47 -05:00
|
|
|
import {Transform} from "../src/transform";
|
|
|
|
const iterations = 50_000;
|
|
|
|
const step = 1000;
|
2024-11-24 22:37:53 -05:00
|
|
|
// hidden-end
|
2024-12-08 22:50:46 -05:00
|
|
|
export type Props = {
|
2024-12-01 21:57:10 -05:00
|
|
|
width: number,
|
|
|
|
height: number,
|
|
|
|
transforms: [number, Transform][]
|
|
|
|
}
|
2024-12-08 19:53:06 -05:00
|
|
|
export function* chaosGameWeighted(
|
|
|
|
{width, height, transforms}: Props
|
|
|
|
) {
|
|
|
|
let img = new ImageData(width, height);
|
|
|
|
let [x, y] = [
|
|
|
|
randomBiUnit(),
|
|
|
|
randomBiUnit()
|
|
|
|
];
|
2024-11-24 22:37:53 -05:00
|
|
|
|
2024-12-08 22:50:46 -05:00
|
|
|
// TODO: Explain quality
|
2024-12-08 19:53:06 -05:00
|
|
|
const iterations = width * height * 0.5;
|
|
|
|
for (let c = 0; c < iterations; c++) {
|
|
|
|
// highlight-start
|
|
|
|
const [_, xform] = randomChoice(transforms);
|
|
|
|
// highlight-end
|
|
|
|
[x, y] = xform(x, y);
|
2024-11-24 22:37:53 -05:00
|
|
|
|
2024-12-08 19:53:06 -05:00
|
|
|
if (c > 20)
|
|
|
|
plot(x, y, img);
|
2024-11-24 22:37:53 -05:00
|
|
|
|
2024-12-08 19:53:06 -05:00
|
|
|
if (c % step === 0)
|
|
|
|
yield img;
|
|
|
|
}
|
2024-11-24 22:37:53 -05:00
|
|
|
|
2024-12-08 19:53:06 -05:00
|
|
|
yield img;
|
2024-11-24 22:37:53 -05:00
|
|
|
}
|