xxxxxxxxxx
47
const w = 700;
const h = 700;
function setup() {
createCanvas(w, h);
}
function isPrime(n) {
prime = true;
for (let d = 2; d <= Math.floor(n ** 0.5) + 1; d++) {
const r = n % d;
if (r == 0) {
prime = !prime;
break;
}
}
if (n == 2) {
prime = !prime;
}
return prime;
}
function drawNums() {
let n = 2;
let wd = textWidth();
let he = h / textSize();
for (let y = 10; y <= h; y = y + he) {
for (let x = 0; x <= w; x = x + wd) {
while (isPrime(n) === false){
n++;
}
//textSize(50)
text(str(n), x, y);
if (isPrime(n)==true){n++;}
}
}
}
function draw() {
background(220);
drawNums();
}