import java.util.*;
import java.awt.*;
public class Animations{
static DrawingPanel drawingPanel = new DrawingPanel(800,800);
static Color color = new Color(255,255,255);
static Graphics pen = drawingPanel.getGraphics();
static Scanner scnr = new Scanner (System.in);
static int numShapes;
static int numTimeShapes;
static String[] shapes =new String[20]; //{"Square" ,"Circle","Triangle"}; change later
static int[] shapeSize= new int[20];
static String[] shapeColor = {"Red", "Blue", "Pink", "Yellow", "Green", "Magenta", "Cyan ", "Orange", "Dark_gray",
"Light_gray", "Gray"};
static int[] directionShape= new int[20]; //{0,2,4,6}; // 0 for left,2 = up,4 =right,6 =down
static int[] shapeSpeed= new int[20];
static int[] posX = new int[20]; // x position of top left corner of every shape
static int [] posY = new int[20]; // y position of top left corner of every shape
static int width = 800; //init
static int height = 800;
public static void getShapeInformation() { //Will get the information for all the shapes from the user
for (int i=0;i<numShapes;i++){
System.out.print("Input type of shape:");
shapes[i] = scnr.next();
System.out.print("Input shape size:");
shapeSize[i] = scnr.nextInt();
System.out.print("Input the color of the shape");
shapeColor[i] = scnr.next();
System.out.print("Input the direction for the shape");
directionShape[i] = scnr.nextInt();
System.out.print("Input the speed of the shape");
shapeSpeed[i] = scnr.nextInt();
}
}
public static void initialPosition(DrawingPanel drawingPanel){ // Will calculate the top left position of every shape at the beginning of the program's execution
boolean booleanValue = true;
for(int i= 0;i<numShapes;i++){
//calculate and update initial x&y pos in i-th shape
posX[i] = ((width/2) - (shapeSize[i]/2));
posY[i] = ((drawingPanel.getHeight()/2) -(shapeSize[i]/2));
showShapes(drawingPanel,booleanValue);
drawingPanel.sleep(100);
}
}
public static void showShapesMoving(DrawingPanel drawingPanel){ //Will emulate the movement of the shapes
for (int i=0;i<numTimeShapes;i++){
showShapes(drawingPanel,false);
changePositions();
showShapes(drawingPanel, true);
drawingPanel.sleep(100);
}
}
public static void changePositions() { //Will calculate the new x and y positions of the top left corner of all the shapes
for(int i=0;i<numShapes;i++){
if(directionShape[i] == 0){ //moves left
posX[i] = posX[i] - shapeSpeed[i];
}
if(directionShape[i] == 2){ // moves up
posY[i] = posY[i] + shapeSpeed[i];
}
if(directionShape[i] == 4){ //moves right
posX[i] = posX[i] + shapeSpeed[i];
}
if(directionShape[i] == 6){ // moves down
posY[i] = posY[i] - shapeSpeed[i];
}
}
}
public static void showShapes(DrawingPanel drawingPanel, boolean booleanValue){ //Will call methods to change color and show the specific forms
for(int i =0;i<numShapes;i++){
if (booleanValue){
graphicsSetColor(drawingPanel,i);
}
else{
setNoColor(drawingPanel);
}
if(shapes[i].equals("Square")){
showSquare(drawingPanel,i,booleanValue);
}
else if(shapes[i].equals("Circle")){
showCircle(drawingPanel,i,booleanValue);
}
}
drawingPanel.sleep(100);
setNoColor(drawingPanel);
}
public static void setNoColor(DrawingPanel drawingPanel) { //Will set the color similar to the background (aka. WHITE), used to emulate the movement
pen.setColor(color.WHITE);
}
public static void graphicsSetColor(DrawingPanel drawingPanel, int i){ // Will set the color of the i-th shape to be printed
if (shapeColor[i].equals("Red")){
pen.setColor(color.RED);
}
else if (shapeColor[i].equals("Blue")){
pen.setColor(color.BLUE);
}
else if (shapeColor[i].equals("Pink")){
pen.setColor(color.PINK);
}
else if (shapeColor[i].equals("Yellow")){
pen.setColor(color.YELLOW);
}
else if (shapeColor[i].equals("Green")){
pen.setColor(color.GREEN);
}
else if (shapeColor[i].equals("Magenta")){
pen.setColor(color.MAGENTA);
}
else if (shapeColor[i].equals("Cyan")){
pen.setColor(color.CYAN);
}
else if (shapeColor[i].equals("Orange")){
pen.setColor(color.ORANGE);
}
else if (shapeColor[i].equals("Dark_gray")){
color = new Color(255,255,255);
pen.setColor(color.DARK_GRAY); //darkgrey
}
else if (shapeColor[i].equals("Light_grey")){
pen.setColor(color.LIGHT_GRAY); //lightgrey
}
else if (shapeColor[i].equals("Grey")){
pen.setColor(color.GRAY);
}
// pen.setColor(color.shapeColor);
}
public static void showSquare(DrawingPanel drawingPanel, int i, boolean booleanValue){ // Will show the filled i-th shape as a square with BLACK border
pen.fillRect(posX[i],posY[i],shapeSize[i],shapeSize[i]);
//setNoColor(drawingPanel);
if(booleanValue){
pen.setColor(color.BLACK);
pen.drawRect(posX[i],posY[i],shapeSize[i],shapeSize[i]);
setNoColor(drawingPanel);
}
}
public static void showCircle(DrawingPanel drawingPanel, int i, boolean booleanValue){ // Will show the filled i-th shape as a circle with BLACK border
pen.fillOval(posX[i],posY[i],shapeSize[i],shapeSize[i]);
if(booleanValue){
pen.setColor(color.BLACK);
pen.drawOval(posX[i],posY[i],shapeSize[i],shapeSize[i]);
}
}
public static void main(String [] args){ //Will show your specifics and obtain basic information for the execution
System.out.println("UTSA - Fall 2021 - CS1083 – Section 002 - Project 3 - written by RABIAT SADIQ \n");
System.out.println("Please input width, height of the panel, # of shapes, # of times to move followed by the shape, size, color, direction, and speed of every shape: ");
System.out.print("Input width of drawing panel:");
System.out.print("Input heigth of drawing panel:");
width = scnr.nextInt(); //init
height = scnr.nextInt();
System.out.print("Input number of shapes:");
numShapes = scnr.nextInt();
System.out.print("Input number of times shape would move:");
numTimeShapes = scnr.nextInt();
getShapeInformation();
drawingPanel = new DrawingPanel(width,height);
initialPosition(drawingPanel);
showShapesMoving(drawingPanel);
}
}
/*
testing numbers 600 800 10 50 Square 100 Red 0 3 Circle 80 Blue 2 2 Square 60 Green 4 1 Circle 50 Black
0 4 Square 80 Blue 6 5 Circle 25 Magenta 0 10 Square 60 Orange 2 4 Circle 80 Light_gray
4 6 Square 120 Yellow 6 2 Circle 60 Cyan 0 7
*/