001/* Copyright (C) Cross The Road Electronics 2024 */ 002package com.ctre.phoenix.led; 003 004/** 005 * The base class for all animations that CANdle supports. 006 */ 007public abstract class Animation { 008 private int animationIdx, numLed, ledOffset; 009 private double speed; 010 /** 011 * Constructor for an Animation class 012 * @param idx The animation-specific ID 013 * @param speed The rate at which the animation runs at. Higher is generally faster 014 * @param numLed The number of LEDs to run the animation on 015 * @param ledOffset Where to start the animation 016 */ 017 public Animation(int idx, double speed, int numLed, int ledOffset) { 018 this.animationIdx = idx; 019 setSpeed(speed); 020 setNumLed(numLed); 021 setLedOffset(ledOffset); 022 } 023 /** 024 * Sets the speed of the animation 025 * @param speed The rate at which the animation runs at. Higher is generally faster 026 */ 027 public void setSpeed(double speed) { 028 if(speed > 1) speed = 1; 029 if(speed < 0) speed = 0; 030 this.speed = speed; 031 } 032 /** 033 * Sets the number of LEDs the animation will run on 034 * @param numLed The number of LEDs to run the animation on 035 */ 036 public void setNumLed(int numLed) { 037 if(numLed > 511) numLed = 511; 038 if(numLed < 0) numLed = 511; 039 this.numLed = numLed; 040 } 041 /** 042 * Sets where the animation will start along the LED strip 043 * @param ledOffset Where to start the animation 044 */ 045 public void setLedOffset(int ledOffset) { 046 if(ledOffset > 511) ledOffset = 511; 047 if(ledOffset < 0) ledOffset = 511; 048 this.ledOffset = ledOffset; 049 } 050 051 abstract BaseStandardAnimation getBaseStandardAnimation(); 052 abstract BaseTwoSizeAnimation getBaseTwoSizeAnimation(); 053 054 int getAnimationIdx() { return this.animationIdx; } 055 double getSpeed() { return this.speed; } 056 int getNumLed() { return this.numLed; } 057 int getLedOffset() { return this.ledOffset; } 058}