import React, { useContext, useEffect } from "react"; import * as params from "../src/params"; import { PainterContext } from "../src/Canvas"; import {chaosGameCamera, Props as ChaosGameColorProps} from "./chaosGameCamera"; import styles from "../src/css/styles.module.css"; type Props = { children?: React.ReactElement; } export default function FlameCamera({ children }: Props) { const { width, height, setPainter } = useContext(PainterContext); // Scale chosen so the largest axis is `[-2, 2]` in IFS coordinates, // the smaller axis will be a shorter range to maintain the aspect ratio. const scale = Math.max(width, height) / 4; const [zoom, setZoom] = React.useState(0); const [rotate, setRotate] = React.useState(0); const [offsetX, setOffsetX] = React.useState(0); const [offsetY, setOffsetY] = React.useState(0); const resetCamera = () => { setZoom(0); setRotate(0); setOffsetX(0); setOffsetY(0); } const resetButton = ; useEffect(() => { const gameParams: ChaosGameColorProps = { width, height, transforms: params.xforms, final: params.xformFinal, palette: params.palette, colors: [ {color: params.xform1Color, colorSpeed: 0.5}, {color: params.xform2Color, colorSpeed: 0.5}, {color: params.xform3Color, colorSpeed: 0.5} ], finalColor: { color: params.xformFinalColor, colorSpeed: 0.5 }, scale, zoom, rotate: rotate / 180 * Math.PI, offsetX, offsetY }; setPainter(chaosGameCamera(gameParams)); }, [scale, zoom, rotate, offsetX, offsetY]); return ( <>
Camera {resetButton}
Zoom: {zoom}
setZoom(Number(e.currentTarget.value))}/>Rotate (deg): {rotate}
setRotate(Number(e.currentTarget.value))}/>Offset X: {offsetX}
setOffsetX(Number(e.currentTarget.value))}/>Offset Y: {offsetY}
setOffsetY(Number(e.currentTarget.value))}/>