// Fws3D.java // Flower Works Fire Balls Class // Copyright (C) 1997,1998 Yukinori NAGATANI // nagatani@eken.phys.nagoya-u.ac.jp import java.awt.Graphics; import java.awt.Color; import Fw3D; public class Fws3D { public Fw3D first; Fws3D () { first = null; } public void add (Fw3D fw) { Fw3D newFw = new Fw3D (fw); if (newFw == null) return; newFw.next = first; first = newFw; } // public void remove (Fw3D fw) { // if (fw == null) // return; // Fw3D next = fw.next; // //// delete fw; // fw = next; // } // public void remove () { // for (Fw3D fw = first ; fw != null ; ) { // if (fw.nGeneration == 0) { // remove (fw); // } else // fw = fw.next; // } // } public void remove () { Fw3D ref = null; for (Fw3D fw = first ; fw != null ; ) { if (fw.nGeneration == 0) { // remove (fw); if (ref == null) first = fw.next; else ref.next = fw.next; fw = fw.next; } else { ref = fw; fw = fw.next; } } } public void addCluster (int nNumber, Fw3D origin) { for (int n = 0 ; n < nNumber ; n++) { Fw3D fw = new Fw3D (origin); fw.nGeneration --; double rAngle = 2.0 * Math.PI * n / nNumber; fw.xV += 1.0 * Math.cos (rAngle); fw.yV += 0.0; fw.zV += 1.0 * Math.sin (rAngle); fw.nTime = fw.nLifeTime = origin.nLifeTime; add (fw); } } public void addCluster2 (int nNumber, Fw3D origin) { double V = 3.0 + 5.0*Math.random (); int nTimeBase = 30, nTimeFrac = 5; if (Math.random () < 0.3){ // Long Life nTimeBase = 30; nTimeFrac = 100; V = 6.0 + 4.0*Math.random (); } double rFricBase = 0.10, rFricFrac = 0.01; if (Math.random () < 0.2){ rFricFrac = 0.03*Math.random (); } Color fwColorFirst = Color.getHSBColor ((float) Math.random (), 0.4f, 1.0f); Color fwColorMid = fwColorFirst, fwColorFinal = fwColorFirst; if (Math.random () < 0.3) fwColorFinal = Color.white; if (Math.random () < 0.3) fwColorFirst = Color.getHSBColor ((float) Math.random (), 0.4f, 1.0f); for (int n = 0 ; n < nNumber ; n++) { Fw3D fw = new Fw3D (origin); fw.nGeneration --; double rPhi = 2.0*Math.PI * Math.random (), rTheta = Math.acos (-1.0 + 2.0*Math.random ()); fw.xV += V * Math.sin (rTheta) * Math.cos (rPhi); fw.yV += V * Math.sin (rTheta) * Math.sin (rPhi); fw.zV += V * Math.cos (rTheta); fw.nTime = fw.nLifeTime = nTimeBase + (int)(nTimeFrac*Math.random ()); fw.rFriction = rFricBase + rFricFrac*Math.random (); fw.colorFirst = new Color (fwColorFirst.getRGB ()); fw.colorMid = new Color (fwColorMid.getRGB ()); fw.colorFinal = new Color (fwColorFinal.getRGB ()); add (fw); } } public void evolute () { for (Fw3D fw = first ; fw != null ; fw = fw.next) fw.evolute (); for (Fw3D fw = first ; fw != null ; fw = fw.next) if (fw.nTime == 0) { if (fw.nGeneration > 1) addCluster2 (400, fw); fw.nGeneration = 0; } remove (); } // public void print (void) { // for (Fw3D * fw = first ; fw != null ; fw = fw->next) // fw->print (); // } };