package lectures.animation.loops;
import util.annotations.WebDocuments;
import lectures.animation.threads_commands.ThreadSupport;
import lectures.composite.objects_shapes.PlottedShuttle;
import bus.uigen.OEFrame;
@WebDocuments({"Lectures/AnimationLoops.pptx", "Lectures/AnimationLoops.pdf", "Videos/AnimationLoops.avi"})
public class AShuttleAnimator implements ShuttleAnimator {
public void animateFromOrigin(PlottedShuttle shuttle, int animationStep, int animationPauseTime) {
int originalX = shuttle.getShuttleX();
int originalY = shuttle.getShuttleY();
int curX = 0;
int curY = 0;
shuttle.setShuttleX(curX);
shuttle.setShuttleY(curY);
animateYFromOrigin(shuttle, animationStep, animationPauseTime, curY, originalY);
animateXFromOrigin(shuttle, animationStep, animationPauseTime, curX, originalX);
}
protected void animateYFromOrigin(PlottedShuttle shuttle, int animationStep, int animationPauseTime, int startY, int endY) {
while (startY < endY) {
ThreadSupport.sleep(animationPauseTime);
startY += animationStep;
shuttle.setShuttleY(startY);
}
shuttle.setShuttleY(endY);
}
protected void animateXFromOrigin(PlottedShuttle shuttle, int animationStep, int animationPauseTime, int startX, int endX) {
while (startX < endX) {
ThreadSupport.sleep(animationPauseTime);
startX += animationStep;
shuttle.setShuttleX(startX);
}
shuttle.setShuttleX(endX);
}
public void animateFromOrigin(PlottedShuttle shuttle, int animationStep, int animationPauseTime, OEFrame frame) {
int originalX = shuttle.getShuttleX();
int originalY = shuttle.getShuttleY();
int curX = 0;
int curY = 0;
System.out.println("Animation with refresh");
shuttle.setShuttleX(curX);
shuttle.setShuttleY(curY);
animateYFromOrigin(shuttle, animationStep, animationPauseTime, curY, originalY, frame);
animateXFromOrigin(shuttle, animationStep, animationPauseTime, curX, originalX, frame);
}
protected void animateYFromOrigin(PlottedShuttle shuttle, int animationStep, int animationPauseTime, int curY, int originalY, OEFrame frame) {
System.out.println("Animation in Y Direction");
while (curY < originalY) {
ThreadSupport.sleep(animationPauseTime);
curY += animationStep;
shuttle.setShuttleY(curY);
frame.refresh();
}
shuttle.setShuttleY(originalY);
}
protected void animateXFromOrigin(PlottedShuttle shuttle, int animationStep, int animationPauseTime, int startX, int endX, OEFrame frame) {
while (startX < endX) {
ThreadSupport.sleep(animationPauseTime);
startX += animationStep;
shuttle.setShuttleX(startX);
frame.refresh();
}
shuttle.setShuttleX(endX);
}
}