Simple single-color 8x8x8 LED Cube with AVRs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Animation.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Animation.java
  3. *
  4. * Copyright 2011 Thomas Buck <xythobuz@me.com>
  5. * Copyright 2011 Max Nuding <max.nuding@gmail.com>
  6. * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
  7. *
  8. * This file is part of LED-Cube.
  9. *
  10. * LED-Cube is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * LED-Cube is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. import java.util.ArrayList;
  24. import java.util.List;
  25. /**
  26. * A collection of frames that represent an entire animation.
  27. *
  28. * @author Thomas Buck
  29. * @author Max Nuding
  30. * @author Felix Bäder
  31. * @version 1.0
  32. */
  33. public class Animation {
  34. List<AFrame> frames = new ArrayList<AFrame>();
  35. private int lastFrameIndex = 0;
  36. private String name = "Animation";
  37. /**
  38. * Gets the name of this animation
  39. *
  40. * @return name of this animation
  41. */
  42. public String getName() {
  43. return name;
  44. }
  45. /**
  46. * Sets the name of this animation
  47. *
  48. * @param s
  49. * new name
  50. */
  51. public void setName(String s) {
  52. name = s;
  53. }
  54. /**
  55. * Gets the specified frame in this animation
  56. *
  57. * @param i Index of frame you want
  58. * @return The selected frame
  59. */
  60. public AFrame get(int i) {
  61. try {
  62. return frames.get(i);
  63. } catch (IndexOutOfBoundsException e) {
  64. System.out.println(e.toString());
  65. return null;
  66. }
  67. }
  68. /**
  69. * Sets the selected Frame
  70. *
  71. * @param f the frame you want to place in this animation
  72. * @param i Index of the frame you want to override
  73. */
  74. public void set(AFrame f, int i) {
  75. if (lastFrameIndex <= i) {
  76. try {
  77. frames.set(i, f);
  78. } catch (IndexOutOfBoundsException e) {
  79. System.out.println(e.toString());
  80. }
  81. }
  82. }
  83. /**
  84. * Removes a frame. Subsequent frames shift to the left.
  85. *
  86. * @param i Index of frame you want to remove
  87. */
  88. public void remove(int i) {
  89. try {
  90. frames.remove(i);
  91. } catch (IndexOutOfBoundsException e) {
  92. System.out.println(e.toString());
  93. }
  94. }
  95. /**
  96. * Add a new (empty) frame at the specified position
  97. *
  98. * @param i Index you want to place the new frame in
  99. * @see Animation#size size()
  100. */
  101. public void add(int i) {
  102. try {
  103. frames.add(i, new AFrame());
  104. lastFrameIndex++;
  105. } catch (IndexOutOfBoundsException e) {
  106. System.out.println(e.toString());
  107. }
  108. }
  109. /**
  110. * Add a specified frame at the specified position
  111. *
  112. * @param i Index for new frame
  113. * @param f data for new frame
  114. */
  115. public void add(int i, AFrame f) {
  116. try {
  117. frames.add(i, f);
  118. lastFrameIndex++;
  119. } catch (IndexOutOfBoundsException e) {
  120. System.out.println(e.toString());
  121. }
  122. }
  123. /**
  124. * Return size of this animation, in number of frames
  125. *
  126. * @return number of frames
  127. */
  128. public int size() {
  129. return frames.size();
  130. }
  131. }