////////////////////////////////////////// class SceneParticles extends Scene { SceneParticles() { super(); m_iNumBalls = 25; m_aBalls = new Ball[m_iNumBalls]; for (int i = 0; i < m_iNumBalls; i++) { m_aBalls[i] = new Ball(); } m_fVelocity = 0.01; } void Start() { super.Start(); for (int i = 0; i < m_iNumBalls; i++) { m_aBalls[i].Reset(); } } void Draw() { super.Draw(); viewManager.SetViewType(3); m_fRotEye += m_fVelocity; float fRotAt = fTime * -0.1; camera(sin(m_fRotEye)*300, 0, cos(m_fRotEye)*300, sin(fRotAt)*200, 0, cos(fRotAt)*200, 0, 1, 0); // camera(0,0,2000,0,0,0,0,1,0); noStroke(); for (int i = 0; i < m_iNumBalls; i++) { m_aBalls[i].Draw(); } } void Kick() { super.Kick(); m_fRotEye += 0.5; } int m_iNumBalls; Ball[] m_aBalls; float m_fRotEye; float m_fVelocity; } ////////////////////////////////////////// class Ball { Ball() { m_fDist = random(1); m_fAng = random(PI*2); m_fY = random(-1,1) * (1-m_fDist) * 200; m_iFreq = (int)((m_fDist) * (iNumAverages - 1)); m_fRGB = 0; m_ParticleSystem = new ParticleSystem(100); } void Reset() { m_ParticleSystem.Reset(); } void Draw() { PVector vecPos = new PVector(sin(m_fAng) * m_fDist * 300 + 100, m_fY, cos(m_fAng) * m_fDist * 300 + 100); float fFftValue = constrain(fft.getAvg(m_iFreq), 0, 10); m_fRGB = m_fRGB * 0.7 + fFftValue * 0.2; float fRGB = constrain(m_fRGB, 0, 1); pushMatrix(); translate(vecPos.x, vecPos.y, vecPos.z); fill(fRGB*30, fRGB*45, fRGB*100); noStroke(); sphere(20); popMatrix(); m_ParticleSystem.Draw(vecPos); if (fFftValue < 1) { m_ParticleSystem.Spawn(vecPos); } } float m_fDist; float m_fAng; float m_fY; int m_iFreq; float m_fRGB; ParticleSystem m_ParticleSystem; } ////////////////////////////////////////// class ParticleSystem { ParticleSystem(int iNumParticles) { m_iNumParticles = iNumParticles; m_aParticles = new Particle[m_iNumParticles]; for (int i = 0; i < m_iNumParticles; i++) { m_aParticles[i] = new Particle(); } } void Reset() { for (int i = 0; i < m_iNumParticles; i++) { m_aParticles[i].m_bAlive = false; } } void Draw(PVector vecSrc) { for (int i = 0; i < m_iNumParticles; i++) { m_aParticles[i].Draw(vecSrc); } } void Spawn(PVector vecPos) { for (int i = 0; i < m_iNumParticles; i++) { if (m_aParticles[i].m_bAlive == false) { m_aParticles[i].Spawn(vecPos); break; } } } int m_iNumParticles; Particle[] m_aParticles; } ////////////////////////////////////////// class Particle { Particle() { m_bAlive = false; } void Spawn(PVector vecPos) { m_vecVelocity = new PVector(random(-10, +10), random(-10, +10), random(-10, +10)); m_vecPos = vecPos; m_fInitialLife = random(10, 20); m_fLife = m_fInitialLife; m_bAlive = true; } void Draw(PVector vecSrc) { if (m_bAlive == true) { m_vecPos.add(m_vecVelocity); m_vecVelocity.mult(0.75); strokeWeight(m_fLife/m_fInitialLife*10); stroke(m_fLife/m_fInitialLife*140,m_fLife/m_fInitialLife*150,m_fLife/m_fInitialLife*20); line(vecSrc.x,vecSrc.y,vecSrc.z,m_vecPos.x, m_vecPos.y, m_vecPos.z); m_fLife -= 1; if (m_fLife <= 0) { m_bAlive = false; } } } PVector m_vecPos; PVector m_vecVelocity; float m_fInitialLife; float m_fLife; boolean m_bAlive; }