xxxxxxxxxx
75
let primeCount = 1000;
let primeList = [2, 3];
let dotSize = 4;
function setup()
{
createCanvas(windowWidth, windowHeight);
background(40);
stroke(255);
strokeWeight(dotSize);
GeneratePrimeList();
let oX = 0;
let oY = windowHeight - 100;
for (let i = 2; i < width / dotSize; ++i)
{
let x = oX + i * dotSize;
let y = oY - FactorCount(i) * dotSize;
point(x, y);
}
}
function GeneratePrimeList()
{
for (let p = 5; primeList.length < primeCount; p += 2)
if (IsPrime(p))
primeList.push(p);
}
function IsPrime(n)
{
let sr = sqrt(n);
for (const prime of primeList)
{
if (prime > sr)
return true;
if (n % prime === 0)
return false;
}
return true;
}
function FactorCount(n)
{
let output = 0;
for (let i = 0; i < primeList.length; ++i)
{
let p = primeList[i];
if (p > n) break;
let count = 0;
while (n % p === 0)
{
++count;
n /= p;
}
output += count;
}
return output;
}