2024-11-24 22:37:53 -05:00
|
|
|
// hidden-start
|
|
|
|
import { randomBiUnit } from "../src/randomBiUnit";
|
|
|
|
import { randomChoice } from "../src/randomChoice";
|
|
|
|
import { plot } from "./plot"
|
|
|
|
export type Transform = (x: number, y: number) => [number, number];
|
|
|
|
export type Params = {
|
|
|
|
transforms: [number, Transform][],
|
|
|
|
image: ImageData,
|
|
|
|
iterations: number,
|
|
|
|
step: number
|
|
|
|
}
|
|
|
|
// hidden-end
|
|
|
|
export function* chaosGameWeighted({transforms, image, iterations, step}: Params) {
|
|
|
|
var [x, y] = [randomBiUnit(), randomBiUnit()];
|
|
|
|
|
|
|
|
for (let i = 0; i < iterations; i++) {
|
|
|
|
// highlight-start
|
|
|
|
const [_, transform] = randomChoice(transforms);
|
|
|
|
// highlight-end
|
|
|
|
[x, y] = transform(x, y);
|
|
|
|
|
2024-11-29 19:25:29 -05:00
|
|
|
if (i > 20)
|
2024-11-24 22:37:53 -05:00
|
|
|
plot(x, y, image);
|
|
|
|
|
2024-11-29 19:25:29 -05:00
|
|
|
if (i % step === 0)
|
2024-11-24 22:37:53 -05:00
|
|
|
yield image;
|
|
|
|
}
|
|
|
|
|
|
|
|
yield image;
|
|
|
|
}
|