2024-12-01 21:57:10 -05:00
|
|
|
import React, {useContext, useEffect} from "react";
|
|
|
|
import * as params from "../src/params";
|
2024-12-01 18:17:36 -05:00
|
|
|
import {PainterContext} from "../src/Canvas";
|
2024-12-01 21:57:10 -05:00
|
|
|
import {chaosGameHistogram} from "@site/blog/2024-11-15-playing-with-fire/3-log-density/chaosGameHistogram";
|
2024-12-01 15:16:30 -05:00
|
|
|
|
2024-12-01 21:57:10 -05:00
|
|
|
type Props = {
|
|
|
|
quality?: number;
|
|
|
|
paintFn: (width: number, histogram: Uint32Array) => ImageData;
|
|
|
|
children?: React.ReactElement;
|
2024-12-01 18:17:36 -05:00
|
|
|
}
|
2024-12-01 21:57:10 -05:00
|
|
|
export default function FlameHistogram({quality, paintFn, children}: Props) {
|
2024-12-01 18:17:36 -05:00
|
|
|
const {width, height, setPainter} = useContext(PainterContext);
|
|
|
|
|
2024-12-01 21:57:10 -05:00
|
|
|
useEffect(() => {
|
|
|
|
const gameParams = {
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
transforms: params.xforms,
|
|
|
|
final: params.xformFinal,
|
|
|
|
quality,
|
|
|
|
painter: paintFn
|
|
|
|
}
|
|
|
|
setPainter(chaosGameHistogram(gameParams));
|
|
|
|
}, []);
|
2024-12-01 18:17:36 -05:00
|
|
|
|
2024-12-01 21:57:10 -05:00
|
|
|
return children;
|
2024-12-01 15:16:30 -05:00
|
|
|
}
|