/** Internal routine for generating the List of particles on collision. */ public static ArrayList<Particle> generateParticles(Ball ball, Body body) { double centerX = ball.getCenter().x(); double centerY = ball.getCenter().y(); double speed = ball.getVelocity().magnitude() * ((body != null) ? (body.getRadius() / 100.0) : 1); if (speed < .50) speed = .50; if (speed > 2.50) speed = 2.50; if (body != null) { double max = Math.pow(body.getRadius() + ball.getRadius(), 2); while (body.getCenter().distanceSquared(new Point2d(centerX, centerY)) < max) { centerX -= ball.getVelocity().xComponent(); centerY -= ball.getVelocity().yComponent(); } } ArrayList<Particle> particles = new ArrayList<Particle>(); int num = (int) (300 * speed); if (num < 150) num = 150; else if (num > 400) num = 400; for (int i = 0; i < num; i++) { double angle = (Math.random() * 2 * Math.PI); double xSpeed = 0.75 * (Math.random() * speed * Math.cos(angle)); double ySpeed = 0.75 * (Math.random() * speed * Math.sin(angle)); Color c; double rand = Math.random(); if (body == null) c = CalcHelp.getShiftedColor(ball.getColor(), 100); else if (rand < 0.3) c = CalcHelp.getShiftedColor(body.getColor(), 100); else if (rand < 0.40) c = CalcHelp.getShiftedColor(new Color(230, 130, 70), 100); else c = CalcHelp.getShiftedColor(ball.getColor(), 100); Particle newParticle = new Particle(centerX, centerY, xSpeed, ySpeed, c); particles.add(newParticle); } return particles; }