particle test

This commit is contained in:
biglyderv 2025-03-05 01:00:00 -05:00
parent 6be7f85b93
commit 659274b087
Signed by: biglyderv
GPG key ID: 0E2EB0B4CD7397B5
4 changed files with 54 additions and 21 deletions

View file

@ -1,35 +1,61 @@
var nothingness = 1, nGain = 0.00001;
var nothingness = 1, nGain = 0.003;
var getBonus = 0;
var mx = 0, my = 0;
let clicking = false;
var cubePos = [
];
window.addEventListener('mousemove', (e) => {
mx = e.pageX;
my = e.pageY;
});
window.addEventListener('click', (e) => {
let p1 = MDN.perspectiveMatrix(Math.PI * 100 / 180, ratio, 0.01, 1000);
for (let cubieI in cubePos) {
let cubie = cubePos[cubieI];
let p2 = MDN.multiplyPoint(p1, [cubie[0], cubie[1], cubie[2], 1]);
p2[0] /= width;
p2[1] /= height;
p2[0] += (mx - width / 2) / width * 2;
p2[1] -= (my - height / 2) / height * 2;
let b = 0.001 / (Math.sqrt(p2[0] ** 2 + p2[1] ** 2) + .003);
getBonus += b;
}
});
setInterval(function () {
nothingness += nGain;
nothingness += nGain + getBonus;
getBonus += 0.001 * cubePos.length;
getBonus *= 0.9;
for (let a of cubePos) {
a[0] += a[3] * 10;
a[1] += a[4] * 10;
a[0] = a[0] * 0.95 + a[3] * 10;
a[1] = a[1] * 0.95 + a[4] * 10;
let f = (nGain + 0.01) / (nothingness + 0.01);
a[0] *= 0.95
a[1] *= 0.95
let a3 = a[3], a4 = a[4];
f /= Math.sqrt(a[0] * a[0] + a[1] * a[1]);
f *= 100;
f *= 50000;
if (f > 0.3) f = 0.3;
a[3] = Math.sin(f) * a4 + Math.cos(f) * a3;
a[4] = -Math.sin(f) * a3 + Math.cos(f) * a4;
}
}1
}, 1000 / 60)
document.body.onclick = async function () {
window.addEventListener('click', async (e) => {
if (clicking) return;
clicking = true;
let oldNGain = nGain;
@ -40,10 +66,10 @@ document.body.onclick = async function () {
}
nGain = oldNGain;
clicking = false;
}
})
for (let i = 0; i < 100; i++) {
cubePos.push([Math.random() * 1000 - 500, Math.random() * 1000 - 500, Math.random() * 30 - 120,
Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1
])
}
setInterval(function() {
cubePos.push([Math.random() * 1000 - 500, Math.random() * 1000 - 500, Math.random() * 30 - 200,
Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1
])
},100)