Skip to content

Commit

Permalink
Update main.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jcponce committed Jul 15, 2024
1 parent 490399e commit 80f85de
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions threejs/particle-life-3d/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ let numParticles = 1000; // Increase number of particles
let numTypes;
let colorStep;
let forces, minDistances, radii;
let particleGeometry, particleMaterial;

let worldDimensions = new THREE.Vector3(500, 500, 500);

Expand Down Expand Up @@ -58,6 +57,15 @@ class Particle {
for (let i = 0; i < particles.length; i++) {
if (particles[i] !== this) {
let direction = particles[i].position.clone().sub(this.position);

if (direction.x > worldDimensions.x / 2) direction.x -= worldDimensions.x;
if (direction.x < -worldDimensions.x / 2) direction.x += worldDimensions.x;
if (direction.y > worldDimensions.y / 2) direction.y -= worldDimensions.y;
if (direction.y < -worldDimensions.y / 2) direction.y += worldDimensions.y;
if (direction.z > worldDimensions.z / 2) direction.z -= worldDimensions.z;
if (direction.z < -worldDimensions.z / 2) direction.z += worldDimensions.z;


let dis = direction.length();
direction.normalize();

Expand Down Expand Up @@ -131,13 +139,7 @@ function init() {
const hemiLight = new THREE.HemisphereLight(0xffffff, 0x444444);
scene.add(hemiLight);

numTypes = Math.floor(Math.random() * 4) + 2;
colorStep = 360 / numTypes;

forces = Array.from({ length: numTypes }, () => Array(numTypes).fill(0));
minDistances = Array.from({ length: numTypes }, () => Array(numTypes).fill(0));
radii = Array.from({ length: numTypes }, () => Array(numTypes).fill(0));
setParameters();


// Sprites BG
const gradientBackground = getLayer({
Expand All @@ -157,6 +159,14 @@ function init() {
});
*/

numTypes = Math.floor(Math.random() * 7) + 2;
colorStep = 360 / numTypes;

forces = Array.from({ length: numTypes }, () => Array(numTypes).fill(0));
minDistances = Array.from({ length: numTypes }, () => Array(numTypes).fill(0));
radii = Array.from({ length: numTypes }, () => Array(numTypes).fill(0));
setParameters();

for (let i = 0; i < numParticles; i++) {
particles.push(new Particle());
}
Expand Down

0 comments on commit 80f85de

Please sign in to comment.