2024-11-30 17:35:42 -05:00
|
|
|
import {useContext, useEffect, useState} from "react";
|
|
|
|
import {Coefs} from "../src/coefs"
|
|
|
|
import {Transform} from "../src/transform";
|
2024-12-01 21:57:10 -05:00
|
|
|
import * as params from "../src/params";
|
2024-11-30 17:35:42 -05:00
|
|
|
import {PainterContext} from "../src/Canvas"
|
2024-12-01 21:57:10 -05:00
|
|
|
import {chaosGameFinal, ChaosGameFinalProps} from "./chaosGameFinal"
|
2024-11-30 17:35:42 -05:00
|
|
|
import {CoefEditor} from "./CoefEditor"
|
2024-12-01 21:57:10 -05:00
|
|
|
import {applyPost, applyTransform} from "@site/blog/2024-11-15-playing-with-fire/src/applyTransform";
|
2024-11-30 17:35:42 -05:00
|
|
|
|
|
|
|
export default function FlamePost() {
|
|
|
|
const {width, height, setPainter} = useContext(PainterContext);
|
|
|
|
|
2024-12-01 21:57:10 -05:00
|
|
|
const [xform1CoefsPost, setXform1CoefsPost] = useState<Coefs>(params.xform1CoefsPost);
|
|
|
|
const resetXform1CoefsPost = () => setXform1CoefsPost(params.xform1CoefsPost);
|
2024-11-30 18:01:29 -05:00
|
|
|
|
2024-12-01 21:57:10 -05:00
|
|
|
const [xform2CoefsPost, setXform2CoefsPost] = useState<Coefs>(params.xform2CoefsPost);
|
|
|
|
const resetXform2CoefsPost = () => setXform2CoefsPost(params.xform2CoefsPost);
|
2024-11-30 18:01:29 -05:00
|
|
|
|
2024-12-01 21:57:10 -05:00
|
|
|
const [xform3CoefsPost, setXform3CoefsPost] = useState<Coefs>(params.xform3CoefsPost);
|
|
|
|
const resetXform3CoefsPost = () => setXform1CoefsPost(params.xform3CoefsPost);
|
2024-11-30 17:35:42 -05:00
|
|
|
|
|
|
|
const identityXform: Transform = (x, y) => [x, y];
|
|
|
|
|
2024-12-01 21:57:10 -05:00
|
|
|
const gameParams: ChaosGameFinalProps = {
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
transforms: [
|
|
|
|
[params.xform1Weight, applyPost(xform1CoefsPost, applyTransform(params.xform1Coefs, params.xform1Variations))],
|
|
|
|
[params.xform2Weight, applyPost(xform2CoefsPost, applyTransform(params.xform2Coefs, params.xform2Variations))],
|
|
|
|
[params.xform3Weight, applyPost(xform3CoefsPost, applyTransform(params.xform3Coefs, params.xform3Variations))],
|
|
|
|
],
|
|
|
|
final: identityXform
|
|
|
|
}
|
|
|
|
useEffect(() => setPainter(chaosGameFinal(gameParams)), [xform1CoefsPost, xform2CoefsPost, xform3CoefsPost]);
|
2024-11-30 17:35:42 -05:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2024-11-30 18:01:29 -05:00
|
|
|
<CoefEditor title={"Transform 1 Post"} isPost={true} coefs={xform1CoefsPost} setCoefs={setXform1CoefsPost}
|
|
|
|
resetCoefs={resetXform1CoefsPost}/>
|
|
|
|
<CoefEditor title={"Transform 2 Post"} isPost={true} coefs={xform2CoefsPost} setCoefs={setXform2CoefsPost}
|
|
|
|
resetCoefs={resetXform2CoefsPost}/>
|
|
|
|
<CoefEditor title={"Transform 3 Post"} isPost={true} coefs={xform3CoefsPost} setCoefs={setXform3CoefsPost}
|
|
|
|
resetCoefs={resetXform3CoefsPost}/>
|
2024-11-30 17:35:42 -05:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|