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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. /**
  25. * A collection of frames that represent an entire animation.
  26. * @author Thomas Buck
  27. * @author Max Nuding
  28. * @author Felix Bäder
  29. * @version 1.0
  30. */
  31. public class Animation {
  32. ArrayList<AFrame> frames = new ArrayList<AFrame>();
  33. private int lastFrameIndex = 0;
  34. private String name = "Animation";
  35. /**
  36. * Gets the name of this animation
  37. * @return name of this animation
  38. */
  39. public String getName() {
  40. return name;
  41. }
  42. /**
  43. * Sets the name of this animation
  44. * @param s new name
  45. */
  46. public void setName(String s) {
  47. name = s;
  48. }
  49. /**
  50. * Gets the specified frame in this animation
  51. * @param i Index of frame you want
  52. * @return The selected frame
  53. */
  54. public AFrame get(int i) {
  55. try {
  56. return frames.get(i);
  57. } catch (IndexOutOfBoundsException e) {
  58. System.out.println(e.toString());
  59. return null;
  60. }
  61. }
  62. /**
  63. * Sets the selected Frame
  64. * @param f the frame you want to place in this animation
  65. * @param i Index of the frame you want to override
  66. */
  67. public void set(AFrame f, int i) {
  68. if (lastFrameIndex <= i) {
  69. try {
  70. frames.set(i, f);
  71. } catch (IndexOutOfBoundsException e) {
  72. System.out.println(e.toString());
  73. }
  74. }
  75. }
  76. /**
  77. * Removes a frame. Subsequent frames shift to the left.
  78. * @param i Index of frame you want to remove
  79. */
  80. public void remove(int i) {
  81. try {
  82. frames.remove(i);
  83. } catch (IndexOutOfBoundsException e) {
  84. System.out.println(e.toString());
  85. }
  86. }
  87. /**
  88. * Add a new (empty) frame at the specified position
  89. * @param i Index you want to place the new frame in
  90. * @see Animation#size size()
  91. */
  92. public void add(int i) {
  93. try {
  94. frames.add(i, new AFrame());
  95. lastFrameIndex++;
  96. } catch (IndexOutOfBoundsException e) {
  97. System.out.println(e.toString());
  98. }
  99. }
  100. /**
  101. * Add a specified frame at the specified position
  102. * @param i Index for new frame
  103. * @param f data for new frame
  104. */
  105. public void add(int i, AFrame f) {
  106. try {
  107. frames.add(i, f);
  108. lastFrameIndex++;
  109. } catch (IndexOutOfBoundsException e) {
  110. System.out.println(e.toString());
  111. }
  112. }
  113. /**
  114. * Return size of this animation, in number of frames
  115. * @return number of frames
  116. */
  117. public int size() {
  118. return frames.size();
  119. }
  120. }