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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. import java.util.Collections;
  26. /**
  27. * A collection of frames that represent an entire animation.
  28. *
  29. * @author Thomas Buck
  30. * @author Max Nuding
  31. * @author Felix Bäder
  32. * @version 1.0
  33. */
  34. public class Animation {
  35. AFrame frames[] = new AFrame[1];
  36. private String name = "Animation";
  37. private static int lastIndex = 1;
  38. /**
  39. * Create an empty frame in this new animation.
  40. */
  41. public Animation() {
  42. frames[0] = new AFrame();
  43. name = "Animation " + lastIndex++;
  44. }
  45. /**
  46. * Gets the specified frame in this animation
  47. *
  48. * @param i Index of frame you want
  49. * @return The selected frame
  50. */
  51. public AFrame getFrame(int i) {
  52. if (i >= frames.length) {
  53. return null;
  54. } else {
  55. return frames[i];
  56. }
  57. }
  58. /**
  59. * Move an frame up.
  60. * @param i the animation you want to move
  61. */
  62. public void moveFrameUp(int i) {
  63. if (i > 0) {
  64. AFrame tmp = frames[i];
  65. frames[i] = frames[i - 1];
  66. frames[i - 1] = tmp;
  67. }
  68. }
  69. /**
  70. * Move an frame down.
  71. * @param i the animation you want to move
  72. */
  73. public void moveFrameDown(int i) {
  74. if (i < (frames.length - 1)) {
  75. AFrame tmp = frames[i];
  76. frames[i] = frames[i + 1];
  77. frames[i + 1] = tmp;
  78. }
  79. }
  80. /**
  81. * Sets the selected Frame
  82. *
  83. * @param f the frame you want to place in this animation
  84. * @param i Index of the frame you want to override
  85. */
  86. public void setFrame(AFrame f, int i) {
  87. if (i < frames.length) {
  88. frames[i] = f;
  89. } else {
  90. addFrame(f);
  91. }
  92. }
  93. /**
  94. * Add a new (empty) frame at the end
  95. */
  96. public void addFrame() {
  97. extendArray();
  98. frames[frames.length - 1] = new AFrame();
  99. }
  100. /**
  101. * Add a specified frame at the end
  102. *
  103. * @param f data for new frame
  104. */
  105. public void addFrame(AFrame f) {
  106. addFrame();
  107. frames[frames.length - 1] = f;
  108. }
  109. /**
  110. * Return size of this animation, in number of frames.
  111. *
  112. * @return number of frames
  113. */
  114. public int size() {
  115. return frames.length;
  116. }
  117. /**
  118. * Removes a frame. Subsequent frames shift to the left.
  119. *
  120. * @param i Index of frame you want to remove
  121. */
  122. public void removeFrame(int i) {
  123. shiftOver(i);
  124. shrinkArray();
  125. }
  126. /**
  127. * Gets the name of this animation
  128. *
  129. * @return name of this animation
  130. */
  131. public String getName() {
  132. return name;
  133. }
  134. /**
  135. * Sets the name of this animation
  136. *
  137. * @param s
  138. * new name
  139. */
  140. public void setName(String s) {
  141. name = s;
  142. }
  143. private void extendArray() {
  144. AFrame newArray[] = new AFrame[frames.length + 1];
  145. for (int i = 0; i < frames.length; i++) {
  146. newArray[i] = frames[i];
  147. }
  148. frames = newArray;
  149. }
  150. private void shrinkArray() {
  151. AFrame newArray[] = new AFrame[frames.length - 1];
  152. for (int i = 0; i < newArray.length; i++) {
  153. newArray[i] = frames[i];
  154. }
  155. frames = newArray;
  156. }
  157. /* private void shiftSpace(int newFree) {
  158. AFrame temp = null;
  159. for (int i = newFree; i < (frames.length - 1); i++) {
  160. // Max i: vorletztes element
  161. AFrame tmp = frames[i];
  162. frames[i] = temp;
  163. temp = frames[i + 1];
  164. frames[i + 1] = tmp;
  165. }
  166. } */
  167. private void shiftOver(int toForget) {
  168. for (int i = (toForget + 1); i < frames.length; i++) {
  169. frames[i - 1] = frames[i];
  170. }
  171. }
  172. }