xxxxxxxxxx
81
var particles = [];
var nums = [];
var den = 40;
let zoom = 1.01;
let delta;
function preload() {
for (let i = 0; i < 10; i++) {
nums[i] = loadImage(String(i) + ".png");
nums[i].resize(width, height);
nums[i].loadPixels();
}
}
function setup() {
createCanvas(600, 600);
imageMode(CENTER);
rectMode(CENTER);
delta = width / den;
for (let i = 0; i < width; i += delta) {
for (let j = 0; j < height; j += delta) {
let color = nums[0].get(i, j);
if (color[3] == 255) {
particles.push(new Particle(i, j, 9));
}
}
}
}
function draw() {
background(255);
zoom = frameCount * 0.01 + 1;
for (let i = 0; i < particles.length; i++) {
particles[i].update();
particles[i].display();
}
}
class Particle {
constructor(x, y, num) {
this.num = num;
this.x = x;
this.y = y;
this.dx;
this.dy;
this.size = 10;
this.cx;
this.cy;
}
update() {
this.dx = 300 - particles[10].x;
this.dy = 300 - particles[10].y;
}
display() {
textSize(10 * zoom);
this.cx = this.x * zoom - this.dx;
this.cy = this.y * zoom - this.dy;
text(1, this.cx, this.cy);
}
}
function number(num) {
if (num == 0) {
for (let i = 0; i < width; i += delta) {
for (let j = 0; j < height; j += delta) {
let color = nums[0].get(i, j);
if (color[3] != 255) {
particles.push(new Particle(i, j, 0));
}
}
}
}
if (num > 0) {
number(num - 1);
}
}