Simple single-color 8x8x8 LED Cube with AVRs
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Animation.java 3.2KB

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