package frc.robot.LEDAnimationKit.animations.animations2D; import java.util.Random; import frc.robot.LEDAnimationKit.Animation; import frc.robot.LEDAnimationKit.LEDStrip2DWrapper; import edu.wpi.first.wpilibj.util.Color8Bit; public class Ricochet2D extends Animation { private RicochetHelper[] helpers; private Random random; private LEDStrip2DWrapper wrapper; public Ricochet2D(LEDStrip2DWrapper wrapper, double timeDelay, int numBalls, Color8Bit[] colors) { super(wrapper, timeDelay); this.wrapper = wrapper; helpers = new RicochetHelper[numBalls]; random = new Random(); for(int i = 0; i < numBalls; i++) { helpers[i] = new RicochetHelper(random.nextInt(wrapper.getWidth()), random.nextInt(wrapper.getHeight()), wrapper.getWidth(), wrapper.getHeight(), colors[random.nextInt(colors.length)]); } } @Override public boolean update() { if(shouldUpdate()) { for(int i = 0; i < wrapper.getWidth(); i++) { for(int j = 0; j < wrapper.getHeight(); j++) { wrapper.setRGBColor(i, j, 0, 0, 0); } } for(int i = 0; i < helpers.length; i++) { helpers[i].updatePosition(); wrapper.setRGBColor(helpers[i].getCurrentXPosition(), helpers[i].getCurrentYPosition(), helpers[i].getCurrentColor()); } resetTiming(); return true; } return false; } }