Last active
August 29, 2015 14:12
-
-
Save Hyperparticle/cda4fba9a2e34657552d to your computer and use it in GitHub Desktop.
Bad use of arrays for the first project in my first intro to Java class. I used arrays even though we didn't cover them in class because I thought I was being smart.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * TrafficAnimation.java | |
| * COMPSCI 121 Project 1: Traffic Animation | |
| */ | |
| /** | |
| * Animates two cars traveling at different speeds which wrap | |
| * back around to their starting position. | |
| * | |
| * @author Me | |
| */ | |
| public class TrafficAnimation extends JPanel | |
| { | |
| private int x = 0, x2 = 0; //anchor coordinates | |
| private int y = 0, y2 = 0; | |
| private final int R = 18; //Amount of rectangles | |
| private final int T = 12; //Amount of triangles | |
| private final int C = 9; //Amount of circles | |
| private final int L = 32; //Amount of lines | |
| private int t = 0, t2 = 0; | |
| Random random = new Random(); | |
| int a = random.nextInt(50)-50; | |
| int b = random.nextInt(3); | |
| public void paintComponent(Graphics canvas) | |
| { | |
| //clears the previous image | |
| //super.paintComponent(canvas); | |
| //account for changes to window size | |
| int width = getWidth(); // panel width | |
| int height = getHeight(); // panel height | |
| //Sets the "resolution" of the coordinate grid | |
| int resW = width/20; | |
| int resH = height/10; | |
| int speed = width/120; //Vehicle speed | |
| int speed2 = width/200; | |
| double angSpeed = speed/(2*Math.PI*3*resW/4); //Speed of wheel rotation | |
| double angSpeed2 = speed2/(2*Math.PI*3*resW/4); //Speed of wheel rotation | |
| //Fill the canvas with the background color | |
| canvas.setColor(getBackground()); | |
| canvas.fillRect(0, 0, width, height); | |
| int vehicleWidth = 9*resW; | |
| int vehicleHeight = 4*resH; | |
| //Calculate the new position | |
| x = x + speed; | |
| y = height/2 - vehicleHeight/2; //Sets the vehicle to the middle of the screen | |
| x2 = x2 + speed2; | |
| y2 = y - 11*resH/4; | |
| if (x > width) | |
| { | |
| x = -vehicleWidth - 3*resW; | |
| } | |
| if (x2 > width) | |
| { | |
| x2 = -vehicleWidth - 3*resW; | |
| } | |
| //Array of R rectangles | |
| int[] rectangleX = new int[R]; | |
| int[] rectangleY = new int[R]; | |
| int[] rectangleW = new int[R]; | |
| int[] rectangleH = new int[R]; | |
| //Array of T triangles | |
| int[][] triangleX = new int[T][3]; | |
| int[][] triangleY = new int[T][3]; | |
| //Array of C circles | |
| int[] circleX = new int[C]; | |
| int[] circleY = new int[C]; | |
| int[] circleW = new int[C]; | |
| int[] circleH = new int[C]; | |
| //Array of R rectangles | |
| int[] lineX1 = new int[L]; | |
| int[] lineY1 = new int[L]; | |
| int[] lineX2 = new int[L]; | |
| int[] lineY2 = new int[L]; | |
| //Rectangles | |
| rectangleX[0] = x; | |
| rectangleY[0] = y + 1*resH; | |
| rectangleW[0] = 8*resW; | |
| rectangleH[0] = 2*resH; | |
| rectangleX[1] = x + 3*resW; | |
| rectangleY[1] = y; | |
| rectangleW[1] = 3*resW; | |
| rectangleH[1] = 1*resH; | |
| rectangleX[2] = x + 8*resW; | |
| rectangleY[2] = y + 2*resH; | |
| rectangleW[2] = 1*resW; | |
| rectangleH[2] = 1*resH; | |
| rectangleX[3] = x + 3*resW + resW/4; | |
| rectangleY[3] = y + resH/4; | |
| rectangleW[3] = 1*resW; | |
| rectangleH[3] = 1*resH - resH/4; | |
| rectangleX[4] = x + 5*resW - resW/4; | |
| rectangleY[4] = y + resH/4; | |
| rectangleW[4] = 1*resW; | |
| rectangleH[4] = 1*resH - resH/4; | |
| rectangleX[5] = x; | |
| rectangleY[5] = y + 1*resH + resH/4; | |
| rectangleW[5] = resW/2; | |
| rectangleH[5] = resH/2; | |
| rectangleX[6] = x; | |
| rectangleY[6] = y + 2*resH - resH/8; | |
| rectangleW[6] = resW/2; | |
| rectangleH[6] = resH/4; | |
| rectangleX[7] = 0; | |
| rectangleY[7] = 5*resH/2; | |
| rectangleW[7] = width; | |
| rectangleH[7] = 10*resH/2; | |
| rectangleX[8] = resW; | |
| rectangleY[8] = 9*resH/2; | |
| rectangleW[8] = 2*resW; | |
| rectangleH[8] = resH/2; | |
| rectangleX[16] = 3*resW; | |
| rectangleY[16] = 0; | |
| rectangleW[16] = resW; | |
| rectangleH[16] = 2*resH; | |
| //Triangles | |
| triangleX[0][0] = x + 3*resW; | |
| triangleY[0][0] = y; | |
| triangleX[0][1] = x + 3*resW; | |
| triangleY[0][1] = y + 1*resH; | |
| triangleX[0][2] = x + 2*resW; | |
| triangleY[0][2] = y + 1*resH; | |
| triangleX[1][0] = x + 6*resW; | |
| triangleY[1][0] = y; | |
| triangleX[1][1] = x + 6*resW; | |
| triangleY[1][1] = y + 1*resH; | |
| triangleX[1][2] = x + 7*resW; | |
| triangleY[1][2] = y + 1*resH; | |
| triangleX[2][0] = x + 8*resW; | |
| triangleY[2][0] = y + 1*resH; | |
| triangleX[2][1] = x + 8*resW; | |
| triangleY[2][1] = y + 2*resH; | |
| triangleX[2][2] = x + 9*resW; | |
| triangleY[2][2] = y + 2*resH; | |
| triangleX[3][0] = x + 3*resW + resW/4; | |
| triangleY[3][0] = y + resH/4; | |
| triangleX[3][1] = x + 3*resW + resW/4; | |
| triangleY[3][1] = y + 1*resH; | |
| triangleX[3][2] = x + 2*resW + resW/2; | |
| triangleY[3][2] = y + 1*resH; | |
| triangleX[4][0] = x + 6*resW - resW/4; | |
| triangleY[4][0] = y + resH/4; | |
| triangleX[4][1] = x + 6*resW - resW/4; | |
| triangleY[4][1] = y + 1*resH; | |
| triangleX[4][2] = x + 7*resW - resW/2; | |
| triangleY[4][2] = y + 1*resH; | |
| triangleX[5][0] = x + 8*resW + resW/4; | |
| triangleY[5][0] = y + 1*resH + resH/4; | |
| triangleX[5][1] = x + 8*resW + resW/4; | |
| triangleY[5][1] = y + 2*resH - resH/4; | |
| triangleX[5][2] = x + 9*resW - resW/4; | |
| triangleY[5][2] = y + 2*resH - resH/4; | |
| //Circles | |
| circleX[0] = x + 1*resW; | |
| circleY[0] = y + 2*resH; | |
| circleW[0] = 2*resW; | |
| circleH[0] = 2*resH; | |
| circleX[1] = x + 6*resW; | |
| circleY[1] = y + 2*resH; | |
| circleW[1] = 2*resW; | |
| circleH[1] = 2*resH; | |
| circleX[2] = circleX[0] + resW/4; | |
| circleY[2] = circleY[0] + resH/4; | |
| circleW[2] = circleW[0] - resW/2; | |
| circleH[2] = circleH[0] - resH/2; | |
| circleX[3] = circleX[1] + resW/4; | |
| circleY[3] = circleY[1] + resH/4; | |
| circleW[3] = circleW[1] - resW/2; | |
| circleH[3] = circleH[1] - resH/2; | |
| circleX[4] = 11*resW; | |
| circleY[4] = 7*resH; | |
| circleW[4] = 1*resW; | |
| circleH[4] = 1*resH; | |
| //Lines | |
| lineX1[0] = x + 2*resW; | |
| lineY1[0] = y + 3*resH; | |
| lineX2[0] = lineX1[0] + (int)(Math.cos((double)t*Math.PI*angSpeed)*3*resW/4); | |
| lineY2[0] = lineY1[0] + (int)(Math.sin((double)t*Math.PI*angSpeed)*3*resH/4); | |
| lineX1[1] = x + 2*resW; | |
| lineY1[1] = y + 3*resH; | |
| lineX2[1] = lineX1[0] + (int)(Math.cos((double)t*Math.PI*angSpeed + Math.PI/2)*3*resW/4); | |
| lineY2[1] = lineY1[0] + (int)(Math.sin((double)t*Math.PI*angSpeed + Math.PI/2)*3*resH/4); | |
| lineX1[2] = x + 2*resW; | |
| lineY1[2] = y + 3*resH; | |
| lineX2[2] = lineX1[0] + (int)(Math.cos((double)t*Math.PI*angSpeed + Math.PI)*3*resW/4); | |
| lineY2[2] = lineY1[0] + (int)(Math.sin((double)t*Math.PI*angSpeed + Math.PI)*3*resH/4); | |
| lineX1[3] = x + 2*resW; | |
| lineY1[3] = y + 3*resH; | |
| lineX2[3] = lineX1[0] + (int)(Math.cos((double)t*Math.PI*angSpeed + 3*Math.PI/2)*3*resW/4); | |
| lineY2[3] = lineY1[0] + (int)(Math.sin((double)t*Math.PI*angSpeed + 3*Math.PI/2)*3*resH/4); | |
| lineX1[4] = x + 2*resW; | |
| lineY1[4] = y + 3*resH; | |
| lineX2[4] = lineX1[0] + (int)(Math.cos((double)t*Math.PI*angSpeed + Math.PI/4)*3*resW/4); | |
| lineY2[4] = lineY1[0] + (int)(Math.sin((double)t*Math.PI*angSpeed + Math.PI/4)*3*resH/4); | |
| lineX1[5] = x + 2*resW; | |
| lineY1[5] = y + 3*resH; | |
| lineX2[5] = lineX1[0] + (int)(Math.cos((double)t*Math.PI*angSpeed + 3*Math.PI/4)*3*resW/4); | |
| lineY2[5] = lineY1[0] + (int)(Math.sin((double)t*Math.PI*angSpeed + 3*Math.PI/4)*3*resH/4); | |
| lineX1[6] = x + 2*resW; | |
| lineY1[6] = y + 3*resH; | |
| lineX2[6] = lineX1[0] + (int)(Math.cos((double)t*Math.PI*angSpeed + 5*Math.PI/4)*3*resW/4); | |
| lineY2[6] = lineY1[0] + (int)(Math.sin((double)t*Math.PI*angSpeed + 5*Math.PI/4)*3*resH/4); | |
| lineX1[7] = x + 2*resW; | |
| lineY1[7] = y + 3*resH; | |
| lineX2[7] = lineX1[0] + (int)(Math.cos((double)t*Math.PI*angSpeed + 7*Math.PI/4)*3*resW/4); | |
| lineY2[7] = lineY1[0] + (int)(Math.sin((double)t*Math.PI*angSpeed + 7*Math.PI/4)*3*resH/4); | |
| lineX1[8] = x + 7*resW; | |
| lineY1[8] = y + 3*resH; | |
| lineX2[8] = lineX1[8] + (int)(Math.cos((double)t*Math.PI*angSpeed)*3*resW/4); | |
| lineY2[8] = lineY1[8] + (int)(Math.sin((double)t*Math.PI*angSpeed)*3*resH/4); | |
| lineX1[9] = x + 7*resW; | |
| lineY1[9] = y + 3*resH; | |
| lineX2[9] = lineX1[8] + (int)(Math.cos((double)t*Math.PI*angSpeed + Math.PI/2)*3*resW/4); | |
| lineY2[9] = lineY1[8] + (int)(Math.sin((double)t*Math.PI*angSpeed + Math.PI/2)*3*resH/4); | |
| lineX1[10] = x + 7*resW; | |
| lineY1[10] = y + 3*resH; | |
| lineX2[10] = lineX1[8] + (int)(Math.cos((double)t*Math.PI*angSpeed + Math.PI)*3*resW/4); | |
| lineY2[10] = lineY1[8] + (int)(Math.sin((double)t*Math.PI*angSpeed + Math.PI)*3*resH/4); | |
| lineX1[11] = x + 7*resW; | |
| lineY1[11] = y + 3*resH; | |
| lineX2[11] = lineX1[8] + (int)(Math.cos((double)t*Math.PI*angSpeed + 3*Math.PI/2)*3*resW/4); | |
| lineY2[11] = lineY1[8] + (int)(Math.sin((double)t*Math.PI*angSpeed + 3*Math.PI/2)*3*resH/4); | |
| lineX1[12] = x + 7*resW; | |
| lineY1[12] = y + 3*resH; | |
| lineX2[12] = lineX1[8] + (int)(Math.cos((double)t*Math.PI*angSpeed + Math.PI/4)*3*resW/4); | |
| lineY2[12] = lineY1[8] + (int)(Math.sin((double)t*Math.PI*angSpeed + Math.PI/4)*3*resH/4); | |
| lineX1[13] = x + 7*resW; | |
| lineY1[13] = y + 3*resH; | |
| lineX2[13] = lineX1[8] + (int)(Math.cos((double)t*Math.PI*angSpeed + 3*Math.PI/4)*3*resW/4); | |
| lineY2[13] = lineY1[8] + (int)(Math.sin((double)t*Math.PI*angSpeed + 3*Math.PI/4)*3*resH/4); | |
| lineX1[14] = x + 7*resW; | |
| lineY1[14] = y + 3*resH; | |
| lineX2[14] = lineX1[8] + (int)(Math.cos((double)t*Math.PI*angSpeed + 5*Math.PI/4)*3*resW/4); | |
| lineY2[14] = lineY1[8] + (int)(Math.sin((double)t*Math.PI*angSpeed + 5*Math.PI/4)*3*resH/4); | |
| lineX1[15] = x + 7*resW; | |
| lineY1[15] = y + 3*resH; | |
| lineX2[15] = lineX1[8] + (int)(Math.cos((double)t*Math.PI*angSpeed + 7*Math.PI/4)*3*resW/4); | |
| lineY2[15] = lineY1[8] + (int)(Math.sin((double)t*Math.PI*angSpeed + 7*Math.PI/4)*3*resH/4); | |
| //Vehicle 2 | |
| //Rectangles | |
| rectangleX[9] = x2; | |
| rectangleY[9] = y2 + 1*resH; | |
| rectangleW[9] = 8*resW; | |
| rectangleH[9] = 2*resH; | |
| rectangleX[10] = x2 + 3*resW; | |
| rectangleY[10] = y2; | |
| rectangleW[10] = 3*resW; | |
| rectangleH[10] = 1*resH; | |
| rectangleX[11] = x2 + 8*resW; | |
| rectangleY[11] = y2 + 2*resH; | |
| rectangleW[11] = 1*resW; | |
| rectangleH[11] = 1*resH; | |
| rectangleX[12] = x2 + 3*resW + resW/4; | |
| rectangleY[12] = y2 + resH/4; | |
| rectangleW[12] = 1*resW; | |
| rectangleH[12] = 1*resH - resH/4; | |
| rectangleX[13] = x2 + 5*resW - resW/4; | |
| rectangleY[13] = y2 + resH/4; | |
| rectangleW[13] = 1*resW; | |
| rectangleH[13] = 1*resH - resH/4; | |
| rectangleX[14] = x2; | |
| rectangleY[14] = y2 + 1*resH + resH/4; | |
| rectangleW[14] = resW/2; | |
| rectangleH[14] = resH/2; | |
| rectangleX[15] = x2; | |
| rectangleY[15] = y2 + 2*resH - resH/8; | |
| rectangleW[15] = resW/2; | |
| rectangleH[15] = resH/4; | |
| //Triangles | |
| triangleX[6][0] = x2 + 3*resW; | |
| triangleY[6][0] = y2; | |
| triangleX[6][1] = x2 + 3*resW; | |
| triangleY[6][1] = y2 + 1*resH; | |
| triangleX[6][2] = x2 + 2*resW; | |
| triangleY[6][2] = y2 + 1*resH; | |
| triangleX[7][0] = x2 + 6*resW; | |
| triangleY[7][0] = y2; | |
| triangleX[7][1] = x2 + 6*resW; | |
| triangleY[7][1] = y2 + 1*resH; | |
| triangleX[7][2] = x2 + 7*resW; | |
| triangleY[7][2] = y2 + 1*resH; | |
| triangleX[8][0] = x2 + 8*resW; | |
| triangleY[8][0] = y2 + 1*resH; | |
| triangleX[8][1] = x2 + 8*resW; | |
| triangleY[8][1] = y2 + 2*resH; | |
| triangleX[8][2] = x2 + 9*resW; | |
| triangleY[8][2] = y2 + 2*resH; | |
| triangleX[9][0] = x2 + 3*resW + resW/4; | |
| triangleY[9][0] = y2 + resH/4; | |
| triangleX[9][1] = x2 + 3*resW + resW/4; | |
| triangleY[9][1] = y2 + 1*resH; | |
| triangleX[9][2] = x2 + 2*resW + resW/2; | |
| triangleY[9][2] = y2 + 1*resH; | |
| triangleX[10][0] = x2 + 6*resW - resW/4; | |
| triangleY[10][0] = y2 + resH/4; | |
| triangleX[10][1] = x2 + 6*resW - resW/4; | |
| triangleY[10][1] = y2 + 1*resH; | |
| triangleX[10][2] = x2 + 7*resW - resW/2; | |
| triangleY[10][2] = y2 + 1*resH; | |
| triangleX[11][0] = x2 + 8*resW + resW/4; | |
| triangleY[11][0] = y2 + 1*resH + resH/4; | |
| triangleX[11][1] = x2 + 8*resW + resW/4; | |
| triangleY[11][1] = y2 + 2*resH - resH/4; | |
| triangleX[11][2] = x2 + 9*resW - resW/4; | |
| triangleY[11][2] = y2 + 2*resH - resH/4; | |
| //Circles | |
| circleX[5] = x2 + 1*resW; | |
| circleY[5] = y2 + 2*resH; | |
| circleW[5] = 2*resW; | |
| circleH[5] = 2*resH; | |
| circleX[6] = x2 + 6*resW; | |
| circleY[6] = y2 + 2*resH; | |
| circleW[6] = 2*resW; | |
| circleH[6] = 2*resH; | |
| circleX[7] = circleX[5] + resW/4; | |
| circleY[7] = circleY[5] + resH/4; | |
| circleW[7] = circleW[5] - resW/2; | |
| circleH[7] = circleH[5] - resH/2; | |
| circleX[8] = circleX[6] + resW/4; | |
| circleY[8] = circleY[6] + resH/4; | |
| circleW[8] = circleW[6] - resW/2; | |
| circleH[8] = circleH[6] - resH/2; | |
| //Lines | |
| lineX1[16] = x2 + 2*resW; | |
| lineY1[16] = y2 + 3*resH; | |
| lineX2[16] = lineX1[16] + (int)(Math.cos((double)t2*Math.PI*angSpeed2)*3*resW/4); | |
| lineY2[16] = lineY1[16] + (int)(Math.sin((double)t2*Math.PI*angSpeed2)*3*resH/4); | |
| lineX1[17] = x2 + 2*resW; | |
| lineY1[17] = y2 + 3*resH; | |
| lineX2[17] = lineX1[16] + (int)(Math.cos((double)t2*Math.PI*angSpeed2 + Math.PI/2)*3*resW/4); | |
| lineY2[17] = lineY1[16] + (int)(Math.sin((double)t2*Math.PI*angSpeed2 + Math.PI/2)*3*resH/4); | |
| lineX1[18] = x2 + 2*resW; | |
| lineY1[18] = y2 + 3*resH; | |
| lineX2[18] = lineX1[16] + (int)(Math.cos((double)t2*Math.PI*angSpeed2 + Math.PI)*3*resW/4); | |
| lineY2[18] = lineY1[16] + (int)(Math.sin((double)t2*Math.PI*angSpeed2 + Math.PI)*3*resH/4); | |
| lineX1[19] = x2 + 2*resW; | |
| lineY1[19] = y2 + 3*resH; | |
| lineX2[19] = lineX1[16] + (int)(Math.cos((double)t2*Math.PI*angSpeed2 + 3*Math.PI/2)*3*resW/4); | |
| lineY2[19] = lineY1[16] + (int)(Math.sin((double)t2*Math.PI*angSpeed2 + 3*Math.PI/2)*3*resH/4); | |
| lineX1[20] = x2 + 2*resW; | |
| lineY1[20] = y2 + 3*resH; | |
| lineX2[20] = lineX1[16] + (int)(Math.cos((double)t2*Math.PI*angSpeed2 + Math.PI/4)*3*resW/4); | |
| lineY2[20] = lineY1[16] + (int)(Math.sin((double)t2*Math.PI*angSpeed2 + Math.PI/4)*3*resH/4); | |
| lineX1[21] = x2 + 2*resW; | |
| lineY1[21] = y2 + 3*resH; | |
| lineX2[21] = lineX1[16] + (int)(Math.cos((double)t2*Math.PI*angSpeed2 + 3*Math.PI/4)*3*resW/4); | |
| lineY2[21] = lineY1[16] + (int)(Math.sin((double)t2*Math.PI*angSpeed2 + 3*Math.PI/4)*3*resH/4); | |
| lineX1[22] = x2 + 2*resW; | |
| lineY1[22] = y2 + 3*resH; | |
| lineX2[22] = lineX1[16] + (int)(Math.cos((double)t2*Math.PI*angSpeed2 + 5*Math.PI/4)*3*resW/4); | |
| lineY2[22] = lineY1[16] + (int)(Math.sin((double)t2*Math.PI*angSpeed2 + 5*Math.PI/4)*3*resH/4); | |
| lineX1[23] = x2 + 2*resW; | |
| lineY1[23] = y2 + 3*resH; | |
| lineX2[23] = lineX1[16] + (int)(Math.cos((double)t2*Math.PI*angSpeed2 + 7*Math.PI/4)*3*resW/4); | |
| lineY2[23] = lineY1[16] + (int)(Math.sin((double)t2*Math.PI*angSpeed2 + 7*Math.PI/4)*3*resH/4); | |
| lineX1[24] = x2 + 7*resW; | |
| lineY1[24] = y2 + 3*resH; | |
| lineX2[24] = lineX1[24] + (int)(Math.cos((double)t2*Math.PI*angSpeed2)*3*resW/4); | |
| lineY2[24] = lineY1[24] + (int)(Math.sin((double)t2*Math.PI*angSpeed2)*3*resH/4); | |
| lineX1[25] = x2 + 7*resW; | |
| lineY1[25] = y2 + 3*resH; | |
| lineX2[25] = lineX1[24] + (int)(Math.cos((double)t2*Math.PI*angSpeed2 + Math.PI/2)*3*resW/4); | |
| lineY2[25] = lineY1[24] + (int)(Math.sin((double)t2*Math.PI*angSpeed2 + Math.PI/2)*3*resH/4); | |
| lineX1[26] = x2 + 7*resW; | |
| lineY1[26] = y2 + 3*resH; | |
| lineX2[26] = lineX1[24] + (int)(Math.cos((double)t2*Math.PI*angSpeed2 + Math.PI)*3*resW/4); | |
| lineY2[26] = lineY1[24] + (int)(Math.sin((double)t2*Math.PI*angSpeed2 + Math.PI)*3*resH/4); | |
| lineX1[27] = x2 + 7*resW; | |
| lineY1[27] = y2 + 3*resH; | |
| lineX2[27] = lineX1[24] + (int)(Math.cos((double)t2*Math.PI*angSpeed2 + 3*Math.PI/2)*3*resW/4); | |
| lineY2[27] = lineY1[24] + (int)(Math.sin((double)t2*Math.PI*angSpeed2 + 3*Math.PI/2)*3*resH/4); | |
| lineX1[28] = x2 + 7*resW; | |
| lineY1[28] = y2 + 3*resH; | |
| lineX2[28] = lineX1[24] + (int)(Math.cos((double)t2*Math.PI*angSpeed2 + Math.PI/4)*3*resW/4); | |
| lineY2[28] = lineY1[24] + (int)(Math.sin((double)t2*Math.PI*angSpeed2 + Math.PI/4)*3*resH/4); | |
| lineX1[29] = x2 + 7*resW; | |
| lineY1[29] = y2 + 3*resH; | |
| lineX2[29] = lineX1[24] + (int)(Math.cos((double)t2*Math.PI*angSpeed2 + 3*Math.PI/4)*3*resW/4); | |
| lineY2[29] = lineY1[24] + (int)(Math.sin((double)t2*Math.PI*angSpeed2 + 3*Math.PI/4)*3*resH/4); | |
| lineX1[30] = x2 + 7*resW; | |
| lineY1[30] = y2 + 3*resH; | |
| lineX2[30] = lineX1[24] + (int)(Math.cos((double)t2*Math.PI*angSpeed2 + 5*Math.PI/4)*3*resW/4); | |
| lineY2[30] = lineY1[24] + (int)(Math.sin((double)t2*Math.PI*angSpeed2 + 5*Math.PI/4)*3*resH/4); | |
| lineX1[31] = x2 + 7*resW; | |
| lineY1[31] = y2 + 3*resH; | |
| lineX2[31] = lineX1[24] + (int)(Math.cos((double)t2*Math.PI*angSpeed2 + 7*Math.PI/4)*3*resW/4); | |
| lineY2[31] = lineY1[24] + (int)(Math.sin((double)t2*Math.PI*angSpeed2 + 7*Math.PI/4)*3*resH/4); | |
| //Shape drawing | |
| //Background | |
| canvas.setColor(new Color(60, 60, 60)); //Dark Gray | |
| canvas.fillRect(rectangleX[7], rectangleY[7], rectangleW[7] , rectangleH[7]); | |
| canvas.setColor(new Color(230, 230, 70)); //Yellow | |
| for (int i = 0; i < 5; i++) | |
| { canvas.fillRect(rectangleX[8] + i*4*resW, rectangleY[8], rectangleW[8], rectangleH[8]); } | |
| canvas.setColor(new Color(90, 60, 20)); //Brown | |
| canvas.fillRect(rectangleX[16], rectangleY[16], rectangleW[16], rectangleH[16]); | |
| canvas.fillRect(rectangleX[16]+12*resW, rectangleY[16], rectangleW[16], rectangleH[16]); | |
| canvas.setColor(new Color(20, 80, 20)); //Dark Green | |
| canvas.fillOval(circleX[4] + 3*resW, circleY[4] + resH, circleW[4], circleH[4]); | |
| canvas.fillOval(circleX[4] + 7*resW/2, circleY[4] + resH, circleW[4]+resW/4, circleH[4]+resH/4); | |
| canvas.fillOval(circleX[4] + 4*resW, circleY[4] + resH, circleW[4], circleH[4]); | |
| ///////////// | |
| //VEHICLE 1// | |
| ///////////// | |
| //Vehicle wheels | |
| canvas.setColor(new Color(30, 30, 30)); //Black | |
| for (int i = 5; i < 7; i++) | |
| { canvas.fillOval(circleX[i], circleY[i], circleW[i], circleH[i]); } | |
| canvas.setColor(new Color(150, 150, 150)); //Gray | |
| for (int i = 7; i < 9; i++) | |
| { canvas.fillOval(circleX[i], circleY[i], circleW[i], circleH[i]); } | |
| Graphics2D g = (Graphics2D)canvas; | |
| g.setColor(new Color(180, 180, 180)); //Light Gray | |
| g.setStroke(new BasicStroke(5)); | |
| for (int i = 16; i < 32; i++) | |
| { g.drawLine(lineX1[i] , lineY1[i], lineX2[i], lineY2[i]); } | |
| g.setColor(new Color(30, 30, 30)); //Black | |
| g.setStroke(new BasicStroke(7)); | |
| g.drawArc(circleX[7], circleY[7], circleW[7], circleH[7], 0, 360); | |
| g.drawArc(circleX[8], circleY[8], circleW[8], circleH[8], 0, 360); | |
| //Vehicle body | |
| canvas.setColor(new Color(170-a, 10-a, 20-a)); //Dark Red | |
| for (int i = 9; i < 12; i++) | |
| { canvas.fillRect(rectangleX[i], rectangleY[i], rectangleW[i] , rectangleH[i]); } | |
| for (int i = 6; i < 9; i++) | |
| { canvas.fillPolygon(triangleX[i], triangleY[i], 3); } | |
| //Vehicle detail | |
| canvas.setColor(new Color(100, 180, 230)); //Light Blue | |
| for (int i = 9; i < 11; i++) | |
| { canvas.fillPolygon(triangleX[i], triangleY[i], 3); } | |
| for (int i = 12; i < 14; i++) | |
| { canvas.fillRect(rectangleX[i], rectangleY[i], rectangleW[i] , rectangleH[i]); } | |
| canvas.setColor(new Color(200, 80, 70)); //Red | |
| canvas.fillRect(rectangleX[14], rectangleY[14], rectangleW[14] , rectangleH[14]); | |
| canvas.setColor(new Color(230, 230, 70)); //Yellow | |
| canvas.fillRect(rectangleX[15], rectangleY[15], rectangleW[15] , rectangleH[15]); | |
| canvas.setColor(new Color(240, 240, 235)); //White | |
| canvas.fillPolygon(triangleX[11], triangleY[11], 3); | |
| //Text | |
| canvas.setColor(Color.black); | |
| canvas.drawString("The Most Boring Video Game Ever", width/4, height - resH); | |
| //Avatar | |
| canvas.setColor(new Color(240, 200, 160)); //Peach | |
| canvas.fillOval(circleX[4], circleY[4], circleW[4], circleH[4]); | |
| canvas.fillRect(circleX[4] - resW/2, circleY[4] + resH, resW/2, resH); | |
| canvas.fillRect(circleX[4] + resW, circleY[4] + resH, resW/2, resH); | |
| canvas.setColor(new Color(60, 190, 70)); //Light Green | |
| canvas.fillRect(circleX[4], circleY[4]+resH, circleW[4], circleH[4]); | |
| canvas.setColor(new Color(20, 50, 120)); //Navy Blue | |
| canvas.fillRect(circleX[4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice