Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This should solve your problems with the angles #1

Open
Vlemert opened this issue Nov 19, 2016 · 0 comments
Open

This should solve your problems with the angles #1

Vlemert opened this issue Nov 19, 2016 · 0 comments

Comments

@Vlemert
Copy link

Vlemert commented Nov 19, 2016

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>
    );
};
sposmen pushed a commit to sposmen/maquette-fractals that referenced this issue Dec 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant