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

/examples/prime-numbers.js 感觉不太对的样子 #4

Open
std-microblock opened this issue Jan 30, 2021 · 0 comments
Open

/examples/prime-numbers.js 感觉不太对的样子 #4

std-microblock opened this issue Jan 30, 2021 · 0 comments

Comments

@std-microblock
Copy link

import * as mo from "movy";

const gridSize = [21, 12];

mo.enableMotionBlur();

let n = 1;
for (let i = 1; i < gridSize[1]; i++) {
    for (let j = 1; j < gridSize[0]; j++) {
        const prime = isPrime(n);
        const position = [j, -i];

        mo.addText(n.toString(), {
            position: position.concat([0]),
            scale: 0.3,
            color: "white",
        });

        mo.addRectOutline({ position, lineWidth: 0.03 });

        if (prime) {
            mo.addRect({ position: position.concat([0.01]), color: "#fad390" }).grow2({
                t: "<0.1",
            });
            mo.addText(n.toString(), {
                position: position.concat([0.02]),
                scale: 0.3,
                color: "black"
            }).grow2({
                t: "<0.1",
            });
        }

        n++;
    }
}

mo.cameraMoveTo({ position: [3, -3, 5], rx: 0.2, duration: 0, t: 0 });
mo.cameraMoveTo({
    position: [gridSize[0] * 0.5, -gridSize[1] * 0.5, 10],
    rx: 0,
    t: "<",
    duration: 10,
});

mo.run();

function isPrime(num) {
    for (let i = 2, s = Math.sqrt(num); i <= s; i++)
        if (num % i === 0) return false;
    return num > 1;
}

改成这样?不然一开始不会显示质数,有点水(

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