import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.net.URL; import javax.swing.*; import java.awt.Point; import java.awt.geom.*; import java.lang.Boolean; import java.lang.Math.*; import java.util.*; import java.lang.Integer; public class Tile extends JApplet implements ActionListener { protected static int [][] sides = new int [2000][8]; protected static int [][] oldSides = new int [2000][8]; protected static int [][] change = new int [4000][8]; protected static int [][] match = new int [4000][2]; protected static int [] used = new int [4000]; protected static int [] howMany = new int [4000]; protected static int translatemx; protected static int translatemy; protected static int translatenx; protected static int translateny; protected static int minm; protected static int maxm; protected static int minn; protected static int maxn; protected static int numberSides; protected static int oldNumberSides; protected static int zoomFactor=100; protected static String commandList; protected static int inBoxDivisor; protected static int numberSummed; protected static int vertsumx; protected static int vertsumy; protected static int numberChanges; protected static int xadd; protected static int yadd; protected static int undid; protected static int minPoly=3; protected static int maxPoly=99; protected JButton b1, b2, b3, b4, b5, b6, b7, b8; protected static final String DUAL = "dual"; protected static final String TRI = "tri"; protected static final String QUAD = "quad"; protected static final String PENTA = "penta"; protected static final String INSET = "inset"; protected static final String SQUARE = "square"; protected static final String HEXAGON = "hexagon"; protected String dualButtonFilename = "images/dual.gif"; protected String triButtonFilename = "images/tri.gif"; protected String quadButtonFilename = "images/quad.gif"; protected String pentaButtonFilename = "images/penta.gif"; protected String insetButtonFilename = "images/inset.gif"; protected String squareButtonFilename = "images/square.gif"; protected String hexagonButtonFilename = "images/hexagon.gif"; protected JTextField minTextField, maxTextField, zoomTextField; URL codeBase; DPanel drawPane; JPanel mainPane, buttonPane; //Hack to avoid ugly message about system event access check. (java 1) public Tile() { getRootPane().putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE); } public void actionPerformed(ActionEvent e) { minPoly = Integer.parseInt(minTextField.getText()); maxPoly = Integer.parseInt(maxTextField.getText()); zoomFactor = Integer.parseInt(zoomTextField.getText()); if (e.getActionCommand().equals(DUAL)) { dual(); } else { if (e.getActionCommand().equals(TRI)) { tri(); minPoly = 3; maxPoly = 99; minTextField.setText("3"); maxTextField.setText("99"); } else { if (e.getActionCommand().equals(QUAD)) { quad(); minPoly = 3; maxPoly = 99; minTextField.setText("3"); maxTextField.setText("99"); } else { if (e.getActionCommand().equals(PENTA)) { penta(); minPoly = 3; maxPoly = 99; minTextField.setText("3"); maxTextField.setText("99"); } else { if (e.getActionCommand().equals(INSET)) { inset(); minPoly = 3; maxPoly = 99; minTextField.setText("3"); maxTextField.setText("99"); } else { if (e.getActionCommand().equals(SQUARE)) { square(); minPoly = 3; maxPoly = 99; minTextField.setText("3"); maxTextField.setText("99"); zoomTextField.setText("100"); } else { if (e.getActionCommand().equals(HEXAGON)) { hexagon(); minPoly = 3; maxPoly = 99; minTextField.setText("3"); maxTextField.setText("99"); zoomTextField.setText("100"); } else { if (e.getActionCommand().equals("undo")) { restoreOldSides(); minPoly = 3; maxPoly = 99; minTextField.setText("3"); maxTextField.setText("99"); } } } } } } } } repaint(); /* for (int i = 0; i<numberSides; i++) { System.out.print(""+sides[i][0]+" "); System.out.print(""+sides[i][1]+" "); System.out.print(""+sides[i][2]+" "); System.out.print(""+sides[i][3]+" "); System.out.print(""+sides[i][4]+" "); System.out.print(""+sides[i][5]+" "); System.out.print(""+sides[i][6]+" "); System.out.print(""+sides[i][7]+"*"); } System.out.println(); */ } // end actionPerformed private void sideToChange() { // this loop splits sides array and puts in change array for (int i = 0;i<numberSides;i++) { change [2*i][0] = sides [i][0]; change [2*i][1] = sides [i][1]; change [2*i][2] = sides [i][2]; change [2*i][3] = sides [i][3]; change [2*i][6] = sides [i][6]; change [2*i][7] = sides [i][7]; change [2*i+1][0] = sides [i][4]; change [2*i+1][1] = sides [i][5]; change [2*i+1][2] = sides [i][6]; change [2*i+1][3] = sides [i][7]; change [2*i+1][6] = sides [i][2]; change [2*i+1][7] = sides [i][3]; change [2*i][4] = (int) Math.floor( (change [2*i][2]+change[2*i][6])/2.0); change [2*i][5] = (int) Math.floor( (change [2*i][3]+change[2*i][7])/2.0); change [2*i+1][4] = (int) Math.floor( (change [2*i+1][2]+change[2*i+1][6])/2.0); change [2*i+1][5] = (int) Math.floor( (change [2*i+1][3]+change[2*i+1][7])/2.0); } numberChanges = 2 * numberSides; } // end sideToChange() private void storeOldSides() { // this loop stores sides array in oldSides array oldNumberSides = numberSides; for (int i = 0;i<numberSides;i++) { oldSides [i][0] = sides [i][0]; oldSides [i][1] = sides [i][1]; oldSides [i][2] = sides [i][2]; oldSides [i][3] = sides [i][3]; oldSides [i][4] = sides [i][4]; oldSides [i][5] = sides [i][5]; oldSides [i][6] = sides [i][6]; oldSides [i][7] = sides [i][7]; } // end for loop undid = 0; } // end storeOldSides() private void recenter() { // this loop moves the halves to have their center in the box for (int i = 0;i<numberChanges;i++) { used [i] = 0; latticePlace(change [i][0], change[i][1]); change[i][0] += xadd; change[i][1] += yadd; change[i][2] += xadd; change[i][3] += yadd; change[i][4] += xadd; change[i][5] += yadd; change[i][6] += xadd; change[i][7] += yadd; } // end half moving to box loop // this loop moves the centers only for (int i = 0; i< numberChanges; i++) { if (used [i] == 0) { int currentx = change [i][0]; int currenty = change [i][1]; vertsumx = change [i][2] + change [i][6]; vertsumy = change [i][3] + change [i][7]; numberSummed = 1; for (int j = i+1;j <numberChanges;j++) { if ((currentx == change [j][0]) && (currenty == change [j][1])) { vertsumx += change[j][2] + change[j][6]; vertsumy += change[j][3] + change[j][7]; used [j] = 1; numberSummed++; } // end if } // end for j loop int newCurrentx = (int) Math.floor(vertsumx / 2.0/ numberSummed); int newCurrenty = (int) Math.floor(vertsumy / 2.0/ numberSummed); change [i][0] = newCurrentx; change [i][1] = newCurrenty; for (int j = i;j<numberChanges;j++) { if ((currentx == change [j][0]) && (currenty == change [j][1])) { change [j][0] = newCurrentx; change [j][1] = newCurrenty; } // end if } // end for j loop } // end if } // end center moving loop // this loop moves the midpoints back to the box if needed. for (int k = 0; k<numberChanges;k++) { latticePlace(change [k][4], change[k][5]); change[k][0] += xadd; change[k][1] += yadd; change[k][2] += xadd; change[k][3] += yadd; change[k][4] += xadd; change[k][5] += yadd; change[k][6] += xadd; change[k][7] += yadd; } // end move midpoints back loop } // recenter() private void matchCenter() { // this loop copies centers to match after translating to the box for (int i = 0;i < numberChanges;i++) { used [i] = 0; latticePlace(change [i][0], change[i][1]); match[i][0] = change [i][0] + xadd; match[i][1] = change [i][1] + yadd; } // end copy centers to match // this loop counts how many of each center for (int i = 0; i < numberChanges; i++) { if (used [i] == 0) { int currentx = match [i][0]; int currenty = match [i][1]; numberSummed = 1; for (int j = i+1;j < numberChanges;j++) { if ((currentx == match [j][0]) && (currenty == match [j][1])) { used [j] = 1; numberSummed++; } // end if } // end for j loop howMany [i] = numberSummed; for (int j = i;j < numberChanges;j++) { if ((currentx == match [j][0]) && (currenty == match [j][1])) { howMany [j] = numberSummed; } // end if } // end for j loop } // end if } // end center counting loop } // matchCenter() private void changeToSide() { // this loop puts the change array values back in the sides array. numberSides = 0; appendChangeToSide(); } private void appendChangeToSide() { for (int i = 0; i< numberChanges;i++){ used [i] = 0; } for (int i = 0; i<numberChanges;i++) { if (used [i] != 1) { for (int j = i+1; j<numberChanges; j++) { if ((change [i][4] == change [j][4]) && (change [i][5] == change [j][5])) { sides [numberSides][0] = change [i][0]; sides [numberSides][1] = change [i][1]; sides [numberSides][2] = change [i][2]; sides [numberSides][3] = change [i][3]; sides [numberSides][4] = change [j][0]; sides [numberSides][5] = change [j][1]; sides [numberSides][6] = change [i][6]; sides [numberSides][7] = change [i][7]; numberSides++; used [j] = 1; j = numberChanges+1; // to stop the loop } // end if } // end for j loop } // end if } // end loop to put change [][] into sides [][] } // end appendChangeToSide() private void restoreOldSides() { if (commandList.endsWith("d")) { dual(); } else { if (undid == 0) { numberSides = oldNumberSides; for (int i = 0;i<numberSides;i++) { sides [i][0] = oldSides [i][0]; sides [i][1] = oldSides [i][1]; sides [i][2] = oldSides [i][2]; sides [i][3] = oldSides [i][3]; sides [i][4] = oldSides [i][4]; sides [i][5] = oldSides [i][5]; sides [i][6] = oldSides [i][6]; sides [i][7] = oldSides [i][7]; } // end loop if (commandList.length() >1) { commandList = commandList.substring(0,commandList.length()-1); if (commandList.endsWith(")")) { while (! (commandList.endsWith("("))) { commandList = commandList.substring(0,commandList.length()-1); } commandList = commandList.substring(0,commandList.length()-1); } } undid = 1; } // end undid loop } // end not end in "d" } // end restoreOldSides() private void dual() { sideToChange(); recenter(); changeToSide(); // this actually does the dual for (int i = 0; i<numberSides;i++) { int first = sides [i][0]; int second = sides [i][1]; for (int j = 0;j<6;j++) { sides [i][j] = sides [i][j+2]; } sides [i][6] = first; sides [i][7] = second; latticePlace(((sides[i][2] + sides [i][6])/2.0), ((sides[i][3] + sides [i][7])/2.0)); for (int j = 0; j <4; j++) { sides [i][2*j] += xadd; sides [i][2*j+1] += yadd; } } // end actual dual loop if (commandList.endsWith("d")) { commandList = commandList.substring(0,commandList.length()-1); } else { commandList = commandList + "d"; } } // end dual() private void tri() { storeOldSides(); sideToChange(); // like recenter but with tri thrown in. // this loop moves the halves to have their center in the box for (int i = 0;i<numberChanges;i++) { used [i] = 0; latticePlace(change [i][0], change[i][1]); change[i][0] += xadd; change[i][1] += yadd; change[i][2] += xadd; change[i][3] += yadd; change[i][4] += xadd; change[i][5] += yadd; change[i][6] += xadd; change[i][7] += yadd; } // end half moving to box loop int addedNumberChanges = numberChanges; // this loop moves the centers only for (int i = 0; i< numberChanges; i++) { if (used [i] == 0) { int currentx = change [i][0]; int currenty = change [i][1]; vertsumx = change [i][2] + change [i][6]; vertsumy = change [i][3] + change [i][7]; numberSummed = 1; for (int j = i+1;j <numberChanges;j++) { if ((currentx == change [j][0]) && (currenty == change [j][1])) { vertsumx += change[j][2] + change[j][6]; vertsumy += change[j][3] + change[j][7]; used [j] = 1; numberSummed++; } // end if } // end for j loop int newCurrentx = (int) Math.floor(vertsumx / 2.0/ numberSummed); int newCurrenty = (int) Math.floor(vertsumy / 2.0/ numberSummed); change [i][0] = newCurrentx; change [i][1] = newCurrenty; for (int j = i+1;j<numberChanges;j++) { if ((currentx == change [j][0]) && (currenty == change [j][1])) { change [j][0] = newCurrentx; change [j][1] = newCurrenty; } // end if } // end for j loop (this was the recentering...) // this will triangulate only the ones we should. if ((numberSummed >= minPoly) && (numberSummed <= maxPoly)) { for (int j = i;j<numberChanges;j++) { if ((newCurrentx == change [j][0]) && (newCurrenty == change [j][1])) { int topcenterx = (int) Math.floor((change[j][0]+change[j][2]+change[j][6])/3.0); int topcentery = (int) Math.floor((change[j][1]+change[j][3]+change[j][7])/3.0); // first int oldx = (int) Math.floor((change[j][0]+change[j][2])/2.0); int oldy = (int) Math.floor((change[j][1]+change[j][3])/2.0); latticePlace((double) oldx, (double) oldy); change [addedNumberChanges][0] = topcenterx + xadd; change [addedNumberChanges][1] = topcentery + yadd; change [addedNumberChanges][2] = change [j][0] + xadd; change [addedNumberChanges][3] = change [j][1] + yadd; change [addedNumberChanges][4] = oldx + xadd; change [addedNumberChanges][5] = oldy + yadd; change [addedNumberChanges][6] = change[j][2] + xadd; change [addedNumberChanges][7] = change[j][3] + yadd; addedNumberChanges++; //second oldx = (int) Math.floor((change[j][0] + change [j][6])/2.0); oldy = (int) Math.floor((change[j][1] + change [j][7])/2.0); latticePlace((double) oldx, (double) oldy); change [addedNumberChanges][0] = topcenterx + xadd; change [addedNumberChanges][1] = topcentery + yadd; change [addedNumberChanges][2] = change [j][6] + xadd; change [addedNumberChanges][3] = change [j][7] + yadd; change [addedNumberChanges][4] = oldx + xadd; change [addedNumberChanges][5] = oldy + yadd; change [addedNumberChanges][6] = change[j][0] + xadd; change [addedNumberChanges][7] = change[j][1] + yadd; addedNumberChanges++; //third change [j][0]=topcenterx; change [j][1]=topcentery; } // end if (only change the right ones } // end for j loop } // end if to triangulate } // end if not used } // end center moving loop numberChanges = addedNumberChanges; // this loop moves the midpoints back to the box if needed. for (int k = 0; k<numberChanges;k++) { latticePlace(change [k][4], change[k][5]); change[k][0] += xadd; change[k][1] += yadd; change[k][2] += xadd; change[k][3] += yadd; change[k][4] += xadd; change[k][5] += yadd; change[k][6] += xadd; change[k][7] += yadd; } // end move midpoints back loop changeToSide(); if ((minPoly !=3) || (maxPoly != 99)) { commandList = commandList + "("+minPoly+"-"+maxPoly+")t"; } else { commandList = commandList + "t"; } } // end tri() private void quad() { storeOldSides(); sideToChange(); recenter(); matchCenter(); int addedNumberChanges = numberChanges; for (int i = 0; i < numberChanges; i +=2) { if ((howMany[i] >= minPoly) && (howMany[i] <= maxPoly)) { // this is if the first vertex is right. if ((howMany[i+1]>= minPoly) && (howMany[i+1] <= maxPoly)) { // this is if both vertices are right.. change[i][6] = change[i][2]; change[i][7] = change[i][3]; change[i][2] = change[i][0]; change[i][3] = change[i][1]; change[i][0] = change[i][4]; change[i][1] = change[i][5]; change[i][4] = (int) Math.floor( (change [i][2]+change[i][6])/2.0); change[i][5] = (int) Math.floor( (change [i][3]+change[i][7])/2.0); change[i+1][6] = change[i+1][2]; change[i+1][7] = change[i+1][3]; change[i+1][2] = change[i+1][0]; change[i+1][3] = change[i+1][1]; change[i+1][0] = change[i+1][4]; change[i+1][1] = change[i+1][5]; change[i+1][4] = (int) Math.floor( (change [i+1][2]+change[i+1][6])/2.0); change[i+1][5] = (int) Math.floor( (change [i+1][3]+change[i+1][7])/2.0); change[addedNumberChanges][0] = change[i][0]; change[addedNumberChanges][1] = change[i][1]; change[addedNumberChanges][2] = change[i+1][6]; change[addedNumberChanges][3] = change[i+1][7]; change[addedNumberChanges][6] = change[i][2]; change[addedNumberChanges][7] = change[i][3]; change[addedNumberChanges][4] = (int) Math.floor( (change [addedNumberChanges][2]+ change[addedNumberChanges][6])/2.0); change[addedNumberChanges][5] = (int) Math.floor( (change [addedNumberChanges][3]+ change[addedNumberChanges][7])/2.0); addedNumberChanges++; change[addedNumberChanges][0] = change[i][0]; change[addedNumberChanges][1] = change[i][1]; change[addedNumberChanges][2] = change[i][6]; change[addedNumberChanges][3] = change[i][7]; change[addedNumberChanges][6] = change[i+1][2]; change[addedNumberChanges][7] = change[i+1][3]; change[addedNumberChanges][4] = (int) Math.floor( (change [addedNumberChanges][2]+ change[addedNumberChanges][6])/2.0); change[addedNumberChanges][5] = (int) Math.floor( (change [addedNumberChanges][3]+ change[addedNumberChanges][7])/2.0); addedNumberChanges++; } // end both vertices right else { // this is if only the first vertex is right.. change[i][6] = change[i][2]; change[i][7] = change[i][3]; change[i][2] = change[i][0]; change[i][3] = change[i][1]; change[i][0] = change[i+1][0]; change[i][1] = change[i+1][1]; change[i][4] = (int) Math.floor( (change [i][2]+change[i][6])/2.0); change[i][5] = (int) Math.floor( (change [i][3]+change[i][7])/2.0); // change[i+1][0 - 3] don't change; change[i+1][6] = change[i][2]; change[i+1][7] = change[i][3]; change[i+1][4] = (int) Math.floor( (change [i+1][2]+change[i+1][6])/2.0); change[i+1][5] = (int) Math.floor( (change [i+1][3]+change[i+1][7])/2.0); } // end first vertex only right } // end first vertex right else { // this is if the first vertex is wrong if ((howMany[i+1]>= minPoly) && (howMany[i+1] <= maxPoly)) { // this is if only second vertex is right.. change[i+1][6] = change[i+1][2]; change[i+1][7] = change[i+1][3]; change[i+1][2] = change[i+1][0]; change[i+1][3] = change[i+1][1]; change[i+1][0] = change[i][0]; change[i+1][1] = change[i][1]; change[i+1][4] = (int) Math.floor( (change [i+1][2]+change[i+1][6])/2.0); change[i+1][5] = (int) Math.floor( (change [i+1][3]+change[i+1][7])/2.0); // change[i][0 - 3] don't change; change[i][6] = change[i+1][2]; change[i][7] = change[i+1][3]; change[i][4] = (int) Math.floor( (change [i][2]+change[i][6])/2.0); change[i][5] = (int) Math.floor( (change [i][3]+change[i][7])/2.0); } // end second vertex only right // if both wrong - do nothing } // end first vertex wrong } // end i loop through numberChanges numberChanges = addedNumberChanges; // this loop moves the midpoints back to the box if needed. for (int k = 0; k < numberChanges;k++) { latticePlace(change [k][4], change[k][5]); change[k][0] += xadd; change[k][1] += yadd; change[k][2] += xadd; change[k][3] += yadd; change[k][4] += xadd; change[k][5] += yadd; change[k][6] += xadd; change[k][7] += yadd; } // end move midpoints back loop changeToSide(); if ((minPoly !=3) || (maxPoly != 99)) { commandList = commandList + "("+minPoly+"-"+maxPoly+")q"; } else { commandList = commandList + "q"; } } // end quad() private void penta() { storeOldSides(); sideToChange(); recenter(); matchCenter(); numberSides = 0; for (int i = 0; i < numberChanges;i += 2) { if ((howMany[i] >= minPoly) && (howMany[i] <= maxPoly)) { // this is if the first vertex is right. if ((howMany[i+1]>= minPoly) && (howMany[i+1] <= maxPoly)) { // this is if both vertices are right.. int topvertexx = (int) Math.floor((change[i][0]+ 2*change[i][2]+change[i][6])/4.0); int topvertexy = (int) Math.floor((change[i][1]+ 2*change[i][3]+change[i][7])/4.0); int botvertexx = (int) Math.floor((change[i+1][0]+ change[i][2]+2*change[i][6])/4.0); int botvertexy = (int) Math.floor((change[i+1][1]+ change[i][3]+2*change[i][7])/4.0); int acenterx = (int) Math.floor((change[i][0]+change[i][2])/2.0); int acentery = (int) Math.floor((change[i][1]+change[i][3])/2.0); int bcenterx = (int) Math.floor((change[i+1][0]+change[i][2])/2.0); int bcentery = (int) Math.floor((change[i+1][1]+change[i][3])/2.0); int ccenterx = (int) Math.floor((change[i+1][0]+change[i][6])/2.0); int ccentery = (int) Math.floor((change[i+1][1]+change[i][7])/2.0); int dcenterx = (int) Math.floor((change[i][0]+change[i][6])/2.0); int dcentery = (int) Math.floor((change[i][1]+change[i][7])/2.0); // first latticePlace(((change[i][0] + topvertexx)/2.0), ((change[i][1] + topvertexy)/2.0)); sides [numberSides][0] = dcenterx + xadd; sides [numberSides][1] = dcentery + yadd; sides [numberSides][2] = change [i][0] + xadd; sides [numberSides][3] = change [i][1] + yadd; sides [numberSides][4] = acenterx + xadd; sides [numberSides][5] = acentery + yadd; sides [numberSides][6] = topvertexx + xadd; sides [numberSides][7] = topvertexy + yadd; numberSides++; // second latticePlace(((change[i][2] + topvertexx)/2.0), ((change[i][3] + topvertexy)/2.0)); sides [numberSides][0] = acenterx + xadd; sides [numberSides][1] = acentery + yadd; sides [numberSides][2] = change [i][2] + xadd; sides [numberSides][3] = change [i][3] + yadd; sides [numberSides][4] = bcenterx + xadd; sides [numberSides][5] = bcentery + yadd; sides [numberSides][6] = topvertexx + xadd; sides [numberSides][7] = topvertexy + yadd; numberSides++; // third latticePlace(((botvertexx + topvertexx)/2.0), ((botvertexy + topvertexy)/2.0)); sides [numberSides][0] = dcenterx + xadd; sides [numberSides][1] = dcentery + yadd; sides [numberSides][2] = topvertexx + xadd; sides [numberSides][3] = topvertexy + yadd; sides [numberSides][4] = bcenterx + xadd; sides [numberSides][5] = bcentery + yadd; sides [numberSides][6] = botvertexx + xadd; sides [numberSides][7] = botvertexy + yadd; numberSides++; // fourth latticePlace(((change[i+1][0] + botvertexx)/2.0), ((change[i+1][1] + botvertexy)/2.0)); sides [numberSides][0] = bcenterx + xadd; sides [numberSides][1] = bcentery + yadd; sides [numberSides][2] = change [i+1][0] + xadd; sides [numberSides][3] = change [i+1][1] + yadd; sides [numberSides][4] = ccenterx + xadd; sides [numberSides][5] = ccentery + yadd; sides [numberSides][6] = botvertexx + xadd; sides [numberSides][7] = botvertexy + yadd; numberSides++; // fifth latticePlace(((change[i][6] + botvertexx)/2.0), ((change[i][7] + botvertexy)/2.0)); sides [numberSides][0] = ccenterx + xadd; sides [numberSides][1] = ccentery + yadd; sides [numberSides][2] = change [i][6] + xadd; sides [numberSides][3] = change [i][7] + yadd; sides [numberSides][4] = dcenterx + xadd; sides [numberSides][5] = dcentery + yadd; sides [numberSides][6] = botvertexx + xadd; sides [numberSides][7] = botvertexy + yadd; numberSides++; } // end both vertices right else { // this is if only the first vertex is right.. int midvertexx = (int) Math.floor((change[i][2]+ change[i][6])/2.0); int midvertexy = (int) Math.floor((change[i][3]+ change[i][7])/2.0); int acenterx = (int) Math.floor((change[i][0]+change[i][2])/2.0); int acentery = (int) Math.floor((change[i][1]+change[i][3])/2.0); int dcenterx = (int) Math.floor((change[i][0]+change[i][6])/2.0); int dcentery = (int) Math.floor((change[i][1]+change[i][7])/2.0); // first latticePlace(((change[i][0] + midvertexx)/2.0), ((change[i][1] + midvertexy)/2.0)); sides [numberSides][0] = dcenterx + xadd; sides [numberSides][1] = dcentery + yadd; sides [numberSides][2] = change [i][0] + xadd; sides [numberSides][3] = change [i][1] + yadd; sides [numberSides][4] = acenterx + xadd; sides [numberSides][5] = acentery + yadd; sides [numberSides][6] = midvertexx + xadd; sides [numberSides][7] = midvertexy + yadd; numberSides++; // second latticePlace(((change[i][2] + midvertexx)/2.0), ((change[i][3] + midvertexy)/2.0)); sides [numberSides][0] = acenterx + xadd; sides [numberSides][1] = acentery + yadd; sides [numberSides][2] = change [i][2] + xadd; sides [numberSides][3] = change [i][3] + yadd; sides [numberSides][4] = change [i+1][0] + xadd; sides [numberSides][5] = change [i+1][1] + yadd; sides [numberSides][6] = midvertexx + xadd; sides [numberSides][7] = midvertexy + yadd; numberSides++; // third latticePlace(((change[i][6] + midvertexx)/2.0), ((change[i][7] + midvertexy)/2.0)); sides [numberSides][0] = dcenterx + xadd; sides [numberSides][1] = dcentery + yadd; sides [numberSides][2] = midvertexx + xadd; sides [numberSides][3] = midvertexy + yadd; sides [numberSides][4] = change [i+1][0] + xadd; sides [numberSides][5] = change [i+1][1] + yadd; sides [numberSides][6] = change [i][6] + xadd; sides [numberSides][7] = change [i][7] + yadd; numberSides++; } // end first vertex only right } // end first vertex right else { // this is if the first vertex is wrong if ((howMany[i+1]>= minPoly) && (howMany[i+1] <= maxPoly)) { // this is if only second vertex is right.. int midvertexx = (int) Math.floor((change[i][2]+ change[i][6])/2.0); int midvertexy = (int) Math.floor((change[i][3]+ change[i][7])/2.0); int bcenterx = (int) Math.floor((change[i+1][0]+change[i][2])/2.0); int bcentery = (int) Math.floor((change[i+1][1]+change[i][3])/2.0); int ccenterx = (int) Math.floor((change[i+1][0]+change[i][6])/2.0); int ccentery = (int) Math.floor((change[i+1][1]+change[i][7])/2.0); // first latticePlace(((change[i+1][0] + midvertexx)/2.0), ((change[i+1][1] + midvertexy)/2.0)); sides [numberSides][0] = bcenterx + xadd; sides [numberSides][1] = bcentery + yadd; sides [numberSides][2] = change [i+1][0] + xadd; sides [numberSides][3] = change [i+1][1] + yadd; sides [numberSides][4] = ccenterx + xadd; sides [numberSides][5] = ccentery + yadd; sides [numberSides][6] = midvertexx + xadd; sides [numberSides][7] = midvertexy + yadd; numberSides++; // second latticePlace(((change[i][6] + midvertexx)/2.0), ((change[i][7] + midvertexy)/2.0)); sides [numberSides][0] = ccenterx + xadd; sides [numberSides][1] = ccentery + yadd; sides [numberSides][2] = change [i][6] + xadd; sides [numberSides][3] = change [i][7] + yadd; sides [numberSides][4] = change [i][0] + xadd; sides [numberSides][5] = change [i][1] + yadd; sides [numberSides][6] = midvertexx + xadd; sides [numberSides][7] = midvertexy + yadd; numberSides++; // third latticePlace(((change[i][2] + midvertexx)/2.0), ((change[i][3] + midvertexy)/2.0)); sides [numberSides][0] = bcenterx + xadd; sides [numberSides][1] = bcentery + yadd; sides [numberSides][2] = midvertexx + xadd; sides [numberSides][3] = midvertexy + yadd; sides [numberSides][4] = change [i][0] + xadd; sides [numberSides][5] = change [i][1] + yadd; sides [numberSides][6] = change [i][2] + xadd; sides [numberSides][7] = change [i][3] + yadd; numberSides++; } // end second vertex only right else { // this is if both are wrong latticePlace(((change[i][6] + change[i][2])/2.0), ((change[i][7] + change[i][3])/2.0)); sides [numberSides][0] = change[i][0] + xadd; sides [numberSides][1] = change[i][1] + yadd; sides [numberSides][2] = change[i][2] + xadd; sides [numberSides][3] = change[i][3] + yadd; sides [numberSides][4] = change [i+1][0] + xadd; sides [numberSides][5] = change [i+1][1] + yadd; sides [numberSides][6] = change [i][6] + xadd; sides [numberSides][7] = change [i][7] + yadd; numberSides++; } // end both wrong } // end first vertex wrong } // end i loop through numberChanges if ((minPoly !=3) || (maxPoly != 99)) { commandList = commandList + "("+minPoly+"-"+maxPoly+")p"; } else { commandList = commandList + "p"; } } // end penta private void inset() { storeOldSides(); sideToChange(); recenter(); matchCenter(); int addedNumberChanges = numberChanges; for (int i = 0; i < numberChanges; i +=2) { if ((howMany[i] >= minPoly) && (howMany[i] <= maxPoly)) { // this is if the first vertex is right. if ((howMany[i+1]>= minPoly) && (howMany[i+1] <= maxPoly)) { // this is if both vertices are right.. int acenterx = (int) Math.floor((change[i][0]+change[i][2])/2.0); int acentery = (int) Math.floor((change[i][1]+change[i][3])/2.0); int bcenterx = (int) Math.floor((change[i+1][0]+change[i][2])/2.0); int bcentery = (int) Math.floor((change[i+1][1]+change[i][3])/2.0); int ccenterx = (int) Math.floor((change[i+1][0]+change[i][6])/2.0); int ccentery = (int) Math.floor((change[i+1][1]+change[i][7])/2.0); int dcenterx = (int) Math.floor((change[i][0]+change[i][6])/2.0); int dcentery = (int) Math.floor((change[i][1]+change[i][7])/2.0); // first change[addedNumberChanges][0] = change[i][2]; change[addedNumberChanges][1] = change[i][3]; change[addedNumberChanges][2] = bcenterx; change[addedNumberChanges][3] = bcentery; change[addedNumberChanges][6] = acenterx; change[addedNumberChanges][7] = acentery; change[addedNumberChanges][4] = (int) Math.floor( (change [addedNumberChanges][2]+ change[addedNumberChanges][6])/2.0); change[addedNumberChanges][5] = (int) Math.floor( (change [addedNumberChanges][3]+ change[addedNumberChanges][7])/2.0); addedNumberChanges++; // second change[addedNumberChanges][0] = change[i][4]; change[addedNumberChanges][1] = change[i][5]; change[addedNumberChanges][2] = acenterx; change[addedNumberChanges][3] = acentery; change[addedNumberChanges][6] = bcenterx; change[addedNumberChanges][7] = bcentery; change[addedNumberChanges][4] = (int) Math.floor( (change [addedNumberChanges][2]+ change[addedNumberChanges][6])/2.0); change[addedNumberChanges][5] = (int) Math.floor( (change [addedNumberChanges][3]+ change[addedNumberChanges][7])/2.0); addedNumberChanges++; // third change[addedNumberChanges][0] = change[i][6]; change[addedNumberChanges][1] = change[i][7]; change[addedNumberChanges][2] = dcenterx; change[addedNumberChanges][3] = dcentery; change[addedNumberChanges][6] = ccenterx; change[addedNumberChanges][7] = ccentery; change[addedNumberChanges][4] = (int) Math.floor( (change [addedNumberChanges][2]+ change[addedNumberChanges][6])/2.0); change[addedNumberChanges][5] = (int) Math.floor( (change [addedNumberChanges][3]+ change[addedNumberChanges][7])/2.0); addedNumberChanges++; // fourth change[addedNumberChanges][0] = change[i][4]; change[addedNumberChanges][1] = change[i][5]; change[addedNumberChanges][2] = ccenterx; change[addedNumberChanges][3] = ccentery; change[addedNumberChanges][6] = dcenterx; change[addedNumberChanges][7] = dcentery; change[addedNumberChanges][4] = (int) Math.floor( (change [addedNumberChanges][2]+ change[addedNumberChanges][6])/2.0); change[addedNumberChanges][5] = (int) Math.floor( (change [addedNumberChanges][3]+ change[addedNumberChanges][7])/2.0); addedNumberChanges++; // fifth change[addedNumberChanges][0] = change[i][4]; change[addedNumberChanges][1] = change[i][5]; change[addedNumberChanges][2] = dcenterx; change[addedNumberChanges][3] = dcentery; change[addedNumberChanges][6] = change[i][0]; change[addedNumberChanges][7] = change[i][1]; change[addedNumberChanges][4] = (int) Math.floor( (change [addedNumberChanges][2]+ change[addedNumberChanges][6])/2.0); change[addedNumberChanges][5] = (int) Math.floor( (change [addedNumberChanges][3]+ change[addedNumberChanges][7])/2.0); addedNumberChanges++; // sixth change[addedNumberChanges][0] = change[i][4]; change[addedNumberChanges][1] = change[i][5]; change[addedNumberChanges][2] = change[i+1][0]; change[addedNumberChanges][3] = change[i+1][1]; change[addedNumberChanges][6] = ccenterx; change[addedNumberChanges][7] = ccentery; change[addedNumberChanges][4] = (int) Math.floor( (change [addedNumberChanges][2]+ change[addedNumberChanges][6])/2.0); change[addedNumberChanges][5] = (int) Math.floor( (change [addedNumberChanges][3]+ change[addedNumberChanges][7])/2.0); addedNumberChanges++; // seventh change[i][6] = acenterx; change[i][7] = acentery; change[i][2] = change[i][0]; change[i][3] = change[i][1]; change[i][0] = change[i][4]; change[i][1] = change[i][5]; change[i][4] = (int) Math.floor( (change [i][2]+change[i][6])/2.0); change[i][5] = (int) Math.floor( (change [i][3]+change[i][7])/2.0); // eighth change[i+1][6] = change[i+1][0]; change[i+1][7] = change[i+1][1]; change[i+1][2] = bcenterx; change[i+1][3] = bcentery; change[i+1][0] = change[i+1][4]; change[i+1][1] = change[i+1][5]; change[i+1][4] = (int) Math.floor( (change [i+1][2]+change[i+1][6])/2.0); change[i+1][5] = (int) Math.floor( (change [i+1][3]+change[i+1][7])/2.0); } // end both vertices right else { // this is if only the first vertex is right.. int acenterx = (int) Math.floor((change[i][0]+change[i][2])/2.0); int acentery = (int) Math.floor((change[i][1]+change[i][3])/2.0); int dcenterx = (int) Math.floor((change[i][0]+change[i][6])/2.0); int dcentery = (int) Math.floor((change[i][1]+change[i][7])/2.0); // first change[addedNumberChanges][0] = change[i][4]; change[addedNumberChanges][1] = change[i][5]; change[addedNumberChanges][2] = change[i][0]; change[addedNumberChanges][3] = change[i][1]; change[addedNumberChanges][6] = acenterx; change[addedNumberChanges][7] = acentery; change[addedNumberChanges][4] = (int) Math.floor( (change [addedNumberChanges][2]+ change[addedNumberChanges][6])/2.0); change[addedNumberChanges][5] = (int) Math.floor( (change [addedNumberChanges][3]+ change[addedNumberChanges][7])/2.0); addedNumberChanges++; // second change[addedNumberChanges][0] = change[i][4]; change[addedNumberChanges][1] = change[i][5]; change[addedNumberChanges][2] = dcenterx; change[addedNumberChanges][3] = dcentery; change[addedNumberChanges][6] = change[i][0]; change[addedNumberChanges][7] = change[i][1]; change[addedNumberChanges][4] = (int) Math.floor( (change [addedNumberChanges][2]+ change[addedNumberChanges][6])/2.0); change[addedNumberChanges][5] = (int) Math.floor( (change [addedNumberChanges][3]+ change[addedNumberChanges][7])/2.0); addedNumberChanges++; // third change[addedNumberChanges][0] = change[i][4]; change[addedNumberChanges][1] = change[i][5]; change[addedNumberChanges][2] = acenterx; change[addedNumberChanges][3] = acentery; change[addedNumberChanges][6] = change[i+1][0]; change[addedNumberChanges][7] = change[i+1][1]; change[addedNumberChanges][4] = (int) Math.floor( (change [addedNumberChanges][2]+ change[addedNumberChanges][6])/2.0); change[addedNumberChanges][5] = (int) Math.floor( (change [addedNumberChanges][3]+ change[addedNumberChanges][7])/2.0); addedNumberChanges++; // fourth change[addedNumberChanges][0] = change[i][4]; change[addedNumberChanges][1] = change[i][5]; change[addedNumberChanges][2] = change[i+1][0]; change[addedNumberChanges][3] = change[i+1][1]; change[addedNumberChanges][6] = dcenterx; change[addedNumberChanges][7] = dcentery; change[addedNumberChanges][4] = (int) Math.floor( (change [addedNumberChanges][2]+ change[addedNumberChanges][6])/2.0); change[addedNumberChanges][5] = (int) Math.floor( (change [addedNumberChanges][3]+ change[addedNumberChanges][7])/2.0); addedNumberChanges++; // fifth change[i][0] = change[i][6]; change[i][1] = change[i][7]; change[i][2] = dcenterx; change[i][3] = dcentery; change[i][6] = change[i+1][0]; change[i][7] = change[i+1][1]; change[i][4] = (int) Math.floor( (change [i][2]+change[i][6])/2.0); change[i][5] = (int) Math.floor( (change [i][3]+change[i][7])/2.0); // sixth change[i+1][2] = change[i+1][0]; change[i+1][3] = change[i+1][1]; change[i+1][0] = change[i+1][6]; change[i+1][1] = change[i+1][7]; change[i+1][6] = acenterx; change[i+1][7] = acentery; change[i+1][4] = (int) Math.floor( (change [i+1][2]+change[i+1][6])/2.0); change[i+1][5] = (int) Math.floor( (change [i+1][3]+change[i+1][7])/2.0); } // end first vertex only right } // end first vertex right else { // this is if the first vertex is wrong if ((howMany[i+1]>= minPoly) && (howMany[i+1] <= maxPoly)) { // this is if only second vertex is right.. int bcenterx = (int) Math.floor((change[i+1][0]+change[i][2])/2.0); int bcentery = (int) Math.floor((change[i+1][1]+change[i][3])/2.0); int ccenterx = (int) Math.floor((change[i+1][0]+change[i][6])/2.0); int ccentery = (int) Math.floor((change[i+1][1]+change[i][7])/2.0); // first change[addedNumberChanges][0] = change[i][4]; change[addedNumberChanges][1] = change[i][5]; change[addedNumberChanges][2] = change[i][0]; change[addedNumberChanges][3] = change[i][1]; change[addedNumberChanges][6] = bcenterx; change[addedNumberChanges][7] = bcentery; change[addedNumberChanges][4] = (int) Math.floor( (change [addedNumberChanges][2]+ change[addedNumberChanges][6])/2.0); change[addedNumberChanges][5] = (int) Math.floor( (change [addedNumberChanges][3]+ change[addedNumberChanges][7])/2.0); addedNumberChanges++; // second change[addedNumberChanges][0] = change[i][4]; change[addedNumberChanges][1] = change[i][5]; change[addedNumberChanges][2] = ccenterx; change[addedNumberChanges][3] = ccentery; change[addedNumberChanges][6] = change[i][0]; change[addedNumberChanges][7] = change[i][1]; change[addedNumberChanges][4] = (int) Math.floor( (change [addedNumberChanges][2]+ change[addedNumberChanges][6])/2.0); change[addedNumberChanges][5] = (int) Math.floor( (change [addedNumberChanges][3]+ change[addedNumberChanges][7])/2.0); addedNumberChanges++; // third change[addedNumberChanges][0] = change[i][4]; change[addedNumberChanges][1] = change[i][5]; change[addedNumberChanges][2] = bcenterx; change[addedNumberChanges][3] = bcentery; change[addedNumberChanges][6] = change[i+1][0]; change[addedNumberChanges][7] = change[i+1][1]; change[addedNumberChanges][4] = (int) Math.floor( (change [addedNumberChanges][2]+ change[addedNumberChanges][6])/2.0); change[addedNumberChanges][5] = (int) Math.floor( (change [addedNumberChanges][3]+ change[addedNumberChanges][7])/2.0); addedNumberChanges++; // fourth change[addedNumberChanges][0] = change[i][4]; change[addedNumberChanges][1] = change[i][5]; change[addedNumberChanges][2] = change[i+1][0]; change[addedNumberChanges][3] = change[i+1][1]; change[addedNumberChanges][6] = ccenterx; change[addedNumberChanges][7] = ccentery; change[addedNumberChanges][4] = (int) Math.floor( (change [addedNumberChanges][2]+ change[addedNumberChanges][6])/2.0); change[addedNumberChanges][5] = (int) Math.floor( (change [addedNumberChanges][3]+ change[addedNumberChanges][7])/2.0); addedNumberChanges++; // fifth change[i+1][0] = change[i][6]; change[i+1][1] = change[i][7]; change[i+1][2] = change[i][0]; change[i+1][3] = change[i][1]; change[i+1][6] = ccenterx; change[i+1][7] = ccentery; change[i+1][4] = (int) Math.floor( (change [i+1][2]+change[i+1][6])/2.0); change[i+1][5] = (int) Math.floor( (change [i+1][3]+change[i+1][7])/2.0); // sixth change[i][6] = change[i][0]; change[i][7] = change[i][1]; change[i][0] = change[i][2]; change[i][1] = change[i][3]; change[i][2] = bcenterx; change[i][3] = bcentery; change[i][4] = (int) Math.floor( (change [i][2]+change[i][6])/2.0); change[i][5] = (int) Math.floor( (change [i][3]+change[i][7])/2.0); } // end second vertex only right else { // if both wrong - make dual change[i][6] = change[i][0]; change[i][7] = change[i][1]; change[i][0] = change[i][2]; change[i][1] = change[i][3]; change[i][2] = change[i+1][0]; change[i][3] = change[i+1][1]; change[i][4] = (int) Math.floor( (change [i][2]+change[i][6])/2.0); change[i][5] = (int) Math.floor( (change [i][3]+change[i][7])/2.0); change[i+1][6] = change[i+1][0]; change[i+1][7] = change[i+1][1]; change[i+1][0] = change[i+1][2]; change[i+1][1] = change[i+1][3]; change[i+1][2] = change[i][6]; change[i+1][3] = change[i][7]; change[i+1][4] = (int) Math.floor( (change [i+1][2]+change[i+1][6])/2.0); change[i+1][5] = (int) Math.floor( (change [i+1][3]+change[i+1][7])/2.0); } // end both wrong } // end first vertex wrong } // end i loop through numberChanges numberChanges = addedNumberChanges; // this loop moves the midpoints back to the box if needed. for (int k = 0; k < numberChanges;k++) { latticePlace(change [k][4], change[k][5]); change[k][0] += xadd; change[k][1] += yadd; change[k][2] += xadd; change[k][3] += yadd; change[k][4] += xadd; change[k][5] += yadd; change[k][6] += xadd; change[k][7] += yadd; } // end move midpoints back loop recenter(); changeToSide(); // dual loop for (int i = 0; i<numberSides;i++) { int first = sides [i][0]; int second = sides [i][1]; for (int j = 0;j<6;j++) { sides [i][j] = sides [i][j+2]; } sides [i][6] = first; sides [i][7] = second; latticePlace(((sides[i][2] + sides [i][6])/2.0), ((sides[i][3] + sides [i][7])/2.0)); for (int j = 0; j <4; j++) { sides [i][2*j] += xadd; sides [i][2*j+1] += yadd; } } // end dual loop sideToChange(); recenter(); changeToSide(); if ((minPoly !=3) || (maxPoly != 99)) { commandList = commandList + "("+minPoly+"-"+maxPoly+")i"; } else { commandList = commandList + "i"; } } // end inset public void square() { translatemx = 200; translatemy = 0; translatenx = 0; translateny = 200; minm = -2; maxm = 3; minn = -1; maxn = 4; numberSides = 2; zoomFactor = 100; commandList = new String("s"); inBoxDivisor = (translatenx * translatemy) - (translatemx * translateny); sides [0][0] = 101; sides [0][1] = 121; sides [0][2] = 1; sides [0][3] = 221; sides [0][4] = -99; sides [0][5] = 121; sides [0][6] = 1; sides [0][7] = 21; sides [1][0] = 101; sides [1][1] = 121; sides [1][2] = 1; sides [1][3] = 21; sides [1][4] = 101; sides [1][5] = -79; sides [1][6] = 201; sides [1][7] = 21; storeOldSides(); } // end square public void hexagon() { translatemx = 200; translatemy = 0; translatenx = 100; translateny = 174; minm = -3; maxm = 4; minn = -1; maxn = 3; numberSides = 3; zoomFactor = 100; commandList = new String("h"); inBoxDivisor = (translatenx * translatemy) - (translatemx * translateny); sides [0][0] = 101; sides [0][1] = 195; sides [0][2] = 1; sides [0][3] = 135; sides [0][4] = 1; sides [0][5] = 21; sides [0][6] = 101; sides [0][7] = 79; sides [1][0] = 1; sides [1][1] = 21; sides [1][2] = 101; sides [1][3] = -39; sides [1][4] = 201; sides [1][5] = 21; sides [1][6] = 101; sides [1][7] = 79; sides [2][0] = 201; sides [2][1] = 21; sides [2][2] = 201; sides [2][3] = 135; sides [2][4] = 101; sides [2][5] = 195; sides [2][6] = 101; sides [2][7] = 79; storeOldSides(); } // end hexagon public void init() { square(); setContentPane(makeContentPane()); } public Container makeContentPane() { ImageIcon dualButtonIcon; ImageIcon triButtonIcon; ImageIcon quadButtonIcon; ImageIcon pentaButtonIcon; ImageIcon insetButtonIcon; ImageIcon squareButtonIcon; ImageIcon hexagonButtonIcon; URL dualButtonURL = getURL(dualButtonFilename); URL triButtonURL = getURL(triButtonFilename); URL quadButtonURL = getURL(quadButtonFilename); URL pentaButtonURL = getURL(pentaButtonFilename); URL insetButtonURL = getURL(insetButtonFilename); URL squareButtonURL = getURL(squareButtonFilename); URL hexagonButtonURL = getURL(hexagonButtonFilename); dualButtonIcon = new ImageIcon(dualButtonURL); triButtonIcon = new ImageIcon(triButtonURL); quadButtonIcon = new ImageIcon(quadButtonURL); pentaButtonIcon = new ImageIcon(pentaButtonURL); insetButtonIcon = new ImageIcon(insetButtonURL); squareButtonIcon = new ImageIcon(squareButtonURL); hexagonButtonIcon = new ImageIcon(hexagonButtonURL); b1 = new JButton("Dual", dualButtonIcon); b1.setPreferredSize(new Dimension(120,40)); b1.setVerticalTextPosition(AbstractButton.CENTER); b1.setHorizontalTextPosition(AbstractButton.LEFT); b1.setHorizontalAlignment(AbstractButton.RIGHT); b1.setMnemonic(KeyEvent.VK_D); b1.setActionCommand(DUAL); b1.addActionListener(this); b1.setToolTipText("This will make the dual of the tiling."); b2 = new JButton("Tri", triButtonIcon); b2.setPreferredSize(new Dimension(120,40)); b2.setVerticalTextPosition(AbstractButton.CENTER); b2.setHorizontalTextPosition(AbstractButton.LEFT); b2.setHorizontalAlignment(AbstractButton.RIGHT); b2.setMnemonic(KeyEvent.VK_T); b2.setActionCommand(TRI); b2.addActionListener(this); b2.setToolTipText("This will triangulate the tiling."); minTextField = new JTextField(Integer.toString(minPoly),3); maxTextField = new JTextField(Integer.toString(maxPoly),3); minTextField.addActionListener(this); maxTextField.addActionListener(this); b3 = new JButton("Quad", quadButtonIcon); b3.setPreferredSize(new Dimension(120,40)); b3.setVerticalTextPosition(AbstractButton.CENTER); b3.setHorizontalTextPosition(AbstractButton.LEFT); b3.setHorizontalAlignment(AbstractButton.RIGHT); b3.setMnemonic(KeyEvent.VK_Q); b3.setActionCommand(QUAD); b3.addActionListener(this); b3.setToolTipText("This will make quadrilaterals of the tiling."); b4 = new JButton("Penta", pentaButtonIcon); b4.setPreferredSize(new Dimension(120,40)); b4.setVerticalTextPosition(AbstractButton.CENTER); b4.setHorizontalTextPosition(AbstractButton.LEFT); b4.setHorizontalAlignment(AbstractButton.RIGHT); b4.setMnemonic(KeyEvent.VK_P); b4.setActionCommand(PENTA); b4.addActionListener(this); b4.setToolTipText("This will make pentagons of the tiling."); JLabel restartLabel = new JLabel("Restart"); b5 = new JButton("Square", squareButtonIcon); b5.setPreferredSize(new Dimension(120,40)); b5.setVerticalTextPosition(AbstractButton.CENTER); b5.setHorizontalTextPosition(AbstractButton.LEFT); b5.setHorizontalAlignment(AbstractButton.RIGHT); b5.setMnemonic(KeyEvent.VK_S); b5.setActionCommand(SQUARE); b5.addActionListener(this); b5.setToolTipText("Start over with squares."); b6 = new JButton("Hexagon", hexagonButtonIcon); b6.setPreferredSize(new Dimension(120,40)); b6.setVerticalTextPosition(AbstractButton.CENTER); b6.setHorizontalTextPosition(AbstractButton.LEFT); b6.setHorizontalAlignment(AbstractButton.RIGHT); b6.setMnemonic(KeyEvent.VK_H); b6.setActionCommand(HEXAGON); b6.addActionListener(this); b6.setToolTipText("Start over with hexagons."); b7 = new JButton("Inset", insetButtonIcon); b7.setPreferredSize(new Dimension(120,40)); b7.setVerticalTextPosition(AbstractButton.CENTER); b7.setHorizontalTextPosition(AbstractButton.LEFT); b7.setHorizontalAlignment(AbstractButton.RIGHT); b7.setMnemonic(KeyEvent.VK_I); b7.setActionCommand(INSET); b7.addActionListener(this); b7.setToolTipText("This will make insets in the tiling."); b8 = new JButton("Undo"); b8.setMnemonic(KeyEvent.VK_U); b8.setActionCommand("undo"); b8.addActionListener(this); b8.setToolTipText("This will undo one step."); JLabel zoomLabel = new JLabel("Zoom %"); zoomTextField = new JTextField(Integer.toString(zoomFactor),3); zoomTextField.addActionListener(this); //Add Components to a JPanel, using the default FlowLayout. buttonPane = new JPanel(); buttonPane.setPreferredSize(new Dimension(130,470)); buttonPane.add(zoomLabel); buttonPane.add(zoomTextField); buttonPane.add(b1); buttonPane.add(minTextField); buttonPane.add(maxTextField); buttonPane.add(b2); buttonPane.add(b3); buttonPane.add(b4); buttonPane.add(b7); buttonPane.add(b8); buttonPane.add(restartLabel); buttonPane.add(b5); buttonPane.add(b6); buttonPane.setBackground(new Color(230,220,180)); buttonPane.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.black)); drawPane = new DPanel(); drawPane.setPreferredSize(new Dimension(500, 470)); drawPane.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.black)); mainPane = new JPanel(); mainPane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); mainPane.add(buttonPane, BorderLayout.LINE_START); mainPane.add(drawPane, BorderLayout.CENTER); mainPane.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.black)); return mainPane; } protected URL getURL(String filename) { URL url = null; if (codeBase == null) { codeBase = getCodeBase(); } try { url = new URL(codeBase, filename); } catch (java.net.MalformedURLException e) { System.out.println("Couldn't create image: badly specified URL"); return null; } return url; } // end getURL // this sets xadd and yadd to move whatever into the first lattice place protected void latticePlace(double px, double py) { px = Math.floor(px); py = Math.floor(py); int n = (int) Math.floor((px * translatemy - py * translatemx) / (double) inBoxDivisor); int m; if (translatemx == 0) {m = (int) Math.floor((py - (n * translateny)) / (double) translatemy);} else {m = (int) Math.floor((px - (n * translatenx)) / (double) translatemx);} xadd = -m * translatemx - n * translatenx; yadd = -m * translatemy - n * translateny; } // end latticePlace } // end Tile class DPanel extends JPanel { public DPanel(){ setBackground(Color.red); } public void paintComponent(Graphics g){ super.paintComponent(g); // Graphics2D g2 = (Graphics2D)g; // g2.setStroke(new BasicStroke(8.0f)); // Dimension dim = getSize(); // int w = (int)dim.getWidth(); // int h = (int)dim.getHeight(); // draw a black border and a white background g.setColor(Color.white); g.fillRect(0,0,getSize().width-1, getSize().height - 1); g.setColor(Color.black); g.drawRect(0,0,getSize().width-1, getSize().height - 1); // draw the sides for (int i = 0; i < Tile.numberSides; i++) { int point1x = Tile.sides [i][2]; int point1y = Tile.sides [i][3]; int point2x = Tile.sides [i][6]; int point2y = Tile.sides [i][7]; for (int j = (int) Math.floor(Tile.minm*100/Tile.zoomFactor); j <= (int) Math.floor(Tile.maxm*100/Tile.zoomFactor);j++) { int move1x = j * Tile.translatemx; int move1y = j * Tile.translatemy; for (int k = (int) Math.floor(Tile.minn*100/Tile.zoomFactor); k <= (int) Math.floor(Tile.maxn*100/Tile.zoomFactor);k++) { int move2x = move1x + k*Tile.translatenx; int move2y = move1y + k*Tile.translateny; int firstx = (int) ((point1x + move2x)*Tile.zoomFactor/100); int firsty = (int) ((point1y + move2y)*Tile.zoomFactor/100); int secondx = (int) ((point2x + move2x)*Tile.zoomFactor/100); int secondy = (int) ((point2y + move2y)*Tile.zoomFactor/100); g.drawLine(firstx, firsty, secondx, secondy); } // end k loop } // end j loop } // end i loop g.setColor(Color.white); g.fillRect(1,1,getSize().width-2, 19); g.setColor(Color.black); g.drawLine(1,19,getSize().width-1, 19); g.drawString(Tile.commandList,10,15); } // end paint component } // end Dpanel