speice.io/blog/2024-11-15-playing-with-fire/3-log-density/FlameHistogram.tsx

27 lines
782 B
TypeScript
Raw Normal View History

2024-12-01 21:57:10 -05:00
import React, {useContext, useEffect} from "react";
2024-12-08 16:17:21 -05:00
import {xforms as transforms, xformFinal as final} from "../src/params";
import {PainterContext} from "../src/Canvas";
import {chaosGameHistogram} from "./chaosGameHistogram";
2024-12-01 15:16:30 -05:00
2024-12-01 21:57:10 -05:00
type Props = {
quality?: number;
2024-12-08 16:17:21 -05:00
paint: (width: number, histogram: Uint32Array) => ImageData;
2024-12-01 21:57:10 -05:00
children?: React.ReactElement;
}
2024-12-08 16:17:21 -05:00
export default function FlameHistogram({quality, paint, children}: Props) {
const {width, height, setPainter} = useContext(PainterContext);
2024-12-01 21:57:10 -05:00
useEffect(() => {
const gameParams = {
width,
height,
2024-12-08 16:17:21 -05:00
transforms,
final,
2024-12-01 21:57:10 -05:00
quality,
2024-12-08 16:17:21 -05:00
paint
2024-12-01 21:57:10 -05:00
}
setPainter(chaosGameHistogram(gameParams));
}, []);
2024-12-01 21:57:10 -05:00
return children;
2024-12-01 15:16:30 -05:00
}