2024-11-29 23:08:47 -05:00
|
|
|
import {useContext, useEffect, useState} from "react";
|
2024-11-29 19:25:29 -05:00
|
|
|
import {Transform} from "../src/transform";
|
|
|
|
import {
|
2024-11-30 17:35:42 -05:00
|
|
|
identityCoefs,
|
2024-11-29 19:25:29 -05:00
|
|
|
xform1Coefs,
|
|
|
|
xform1Weight,
|
|
|
|
xform2Coefs,
|
|
|
|
xform2Weight,
|
|
|
|
xform3Coefs,
|
|
|
|
xform3Weight
|
|
|
|
} from "../src/params";
|
2024-11-29 23:08:47 -05:00
|
|
|
import {PainterContext} from "../src/Canvas"
|
2024-11-30 17:35:42 -05:00
|
|
|
import {buildBlend, buildTransform} from "./buildTransform"
|
|
|
|
import {chaosGameFinal} from "./chaosGameFinal"
|
|
|
|
import {VariationEditor, VariationProps} from "./VariationEditor"
|
2024-11-29 19:25:29 -05:00
|
|
|
|
|
|
|
export default function FlameBlend() {
|
2024-11-29 23:08:47 -05:00
|
|
|
const {width, height, setPainter} = useContext(PainterContext);
|
|
|
|
|
2024-11-30 17:35:42 -05:00
|
|
|
const xform1Default: VariationProps = {
|
2024-11-29 19:25:29 -05:00
|
|
|
linear: 0,
|
|
|
|
julia: 1,
|
|
|
|
popcorn: 0,
|
|
|
|
pdj: 0,
|
|
|
|
}
|
|
|
|
const [xform1Variations, setXform1Variations] = useState(xform1Default)
|
|
|
|
|
2024-11-30 17:35:42 -05:00
|
|
|
const xform2Default: VariationProps = {
|
2024-11-29 19:25:29 -05:00
|
|
|
linear: 1,
|
|
|
|
julia: 0,
|
|
|
|
popcorn: 1,
|
|
|
|
pdj: 0
|
|
|
|
}
|
|
|
|
const [xform2Variations, setXform2Variations] = useState(xform2Default)
|
|
|
|
|
2024-11-30 17:35:42 -05:00
|
|
|
const xform3Default: VariationProps = {
|
2024-11-29 19:25:29 -05:00
|
|
|
linear: 0,
|
|
|
|
julia: 0,
|
|
|
|
popcorn: 0,
|
|
|
|
pdj: 1
|
|
|
|
}
|
|
|
|
const [xform3Variations, setXform3Variations] = useState(xform3Default)
|
|
|
|
|
2024-11-30 17:35:42 -05:00
|
|
|
// Cheating a bit here; for purposes of code re-use, use the post- and final-transform-enabled chaos game,
|
|
|
|
// and swap in identity components for each
|
|
|
|
const identityXform: Transform = (x, y) => [x, y];
|
2024-11-29 19:25:29 -05:00
|
|
|
|
2024-11-30 17:35:42 -05:00
|
|
|
useEffect(() => setPainter(chaosGameFinal(width, height, [
|
|
|
|
[xform1Weight, buildTransform(xform1Coefs, buildBlend(xform1Coefs, xform1Variations))],
|
|
|
|
[xform2Weight, buildTransform(xform2Coefs, buildBlend(xform2Coefs, xform2Variations))],
|
|
|
|
[xform3Weight, buildTransform(xform3Coefs, buildBlend(xform3Coefs, xform3Variations))]
|
|
|
|
], identityXform)), [xform1Variations, xform2Variations, xform3Variations]);
|
2024-11-29 19:25:29 -05:00
|
|
|
|
|
|
|
return (
|
2024-11-30 17:35:42 -05:00
|
|
|
<>
|
|
|
|
<VariationEditor title={"Transform 1"} variations={xform1Variations} setVariations={setXform1Variations}/>
|
|
|
|
<VariationEditor title={"Transform 2"} variations={xform2Variations} setVariations={setXform2Variations}/>
|
|
|
|
<VariationEditor title={"Transform 3"} variations={xform3Variations} setVariations={setXform3Variations}/>
|
|
|
|
</>
|
2024-11-29 19:25:29 -05:00
|
|
|
)
|
|
|
|
}
|