react-fractals
react-fractals copied to clipboard
This should solve your problems with the angles
Had to brush up on how to do this, but this seems to fix it. (also made sure left is left and right is right, you somehow got those all mixed up ;))
const Pythagoras = ({ maxlvl, w, x, y, lvl, left, right }) => {
if (lvl > maxlvl || w < 1) {
return null;
}
const nextLeft = .4 * Factor * w;
const nextRight = .6 * Factor * w;
const leftAngle = Math.deg(Math.acos((nextLeft * nextLeft + w * w - nextRight * nextRight) / (2 * nextLeft * w)));
const rightAngle = Math.deg(Math.acos((nextRight * nextRight + w * w - nextLeft * nextLeft) / (2 * nextRight * w)));
let rotate = '';
if (left) {
rotate = `rotate(${-leftAngle} 0 ${w})`;
}else if (right) {
rotate = `rotate(${rightAngle} ${w} ${w})`;
}
return (
<g transform={`translate(${x} ${y}) ${rotate}`}>
<rect width={w} height={w}
x={0} y={0}
style={{fill: interpolateViridis(lvl/maxlvl)}} />
<Pythagoras w={nextLeft}
x={0} y={-nextLeft} lvl={lvl+1} maxlvl={maxlvl}
left />
<Pythagoras w={nextRight}
x={w-nextRight} y={-nextRight} lvl={lvl+1} maxlvl={maxlvl}
right />
</g>
);
};