Venciity

[SoftUni Java] Syntax - 10.PainHouseSVG

May 19th, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.88 KB | None | 0 0
  1. import java.io.PrintWriter;
  2. import java.util.Scanner;
  3.  
  4. public class PainHouseSVG {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         Scanner input = new Scanner(System.in);
  9.        
  10.         String inputStr = input.nextLine();
  11.         String inp[] = inputStr.split(" ");
  12.        
  13.         double data[] = new double[2];
  14.         data[0] = Double.parseDouble(inp[0]);
  15.         data[1] = Double.parseDouble(inp[1]);
  16.        
  17.         double coordsX[] = {10, 12.5, 15, 17.5, 20, 22.5};
  18.         double coordsY[] = {3.5, 6, 8.5, 11, 13.5, 16};
  19.        
  20.         // fix point position
  21.         if(data[0] < 8) {
  22.             data[0] = 8;
  23.         } else if(data[0] > 23) {
  24.             data[0] = 23;
  25.         }
  26.         if(data[1] < 2) {
  27.             data[1] = 2;
  28.         } else if(data[1] > 17) {
  29.             data[1] = 17;
  30.         }
  31.        
  32.         double pixelsX = 70 + (70 * ((data[0] - 10) / 2.5));
  33.         double pixelsY = 60 + (70 * ((data[1] - 3.5) / 2.5));
  34.        
  35.         // check if inside the house
  36.         double leftSide = ( (12.5 - 17.5)*(data[1] - 3.5) - (8.5 - 3.5)*(data[0] - 17.5) );
  37.         double rightSide = ( (22.5 - 17.5)*(data[1] - 3.5) - (8.5 - 3.5)*(data[0] - 17.5) );
  38.        
  39.         boolean leftRoof = leftSide <= 0.0;
  40.         boolean rightRoof = rightSide >= 0.0;
  41.         boolean roof = leftRoof == true && rightRoof == true && data[1] <= 8.5;
  42.        
  43.         boolean leftWall = data[1] >= 8.5 && data[1] <= 13.5 && data[0] >= 12.5 && data[0] <= 17.5;
  44.         boolean rightWall = data[1] >= 8.5 && data[1] <= 13.5 && data[0] >= 20 && data[0] <= 22.5;
  45.         boolean walls = leftWall == true || rightWall == true;
  46.        
  47.         // build html code
  48.         String content = "<!DOCTYPE html>\n"
  49.                 + "<html>\n"
  50.                 + "<body>\n"
  51.                 + "\n"
  52.                 + "<svg width=\"1000\" height=\"1000\">\n"
  53.                 + "  <text x=\"55\" y=\"20\" font-size=\"27\">10</text>\n"
  54.                 + "  <text x=\"115\" y=\"20\" font-size=\"27\">12.5</text>\n"
  55.                 + "  <text x=\"195\" y=\"20\" font-size=\"27\">15</text>\n"
  56.                 + "  <text x=\"255\" y=\"20\" font-size=\"27\">17.5</text>\n"
  57.                 + "  <text x=\"335\" y=\"20\" font-size=\"27\">20</text>\n"
  58.                 + "  <text x=\"395\" y=\"20\" font-size=\"27\">22.5</text>\n"
  59.                 + "\n"
  60.                 + "  <text x=\"13\" y=\"70\" font-size=\"27\">3.5</text>\n"
  61.                 + "  <text x=\"33\" y=\"140\" font-size=\"27\">6</text>\n"
  62.                 + "  <text x=\"13\" y=\"210\" font-size=\"27\">8.5</text>\n"
  63.                 + "  <text x=\"20\" y=\"280\" font-size=\"27\">11</text>\n"
  64.                 + "  <text x=\"0\" y=\"350\" font-size=\"27\">13.5</text>\n"
  65.                 + "  <text x=\"20\" y=\"420\" font-size=\"27\">16</text>\n"
  66.                 + "\n"
  67.                 + "  <line x1=\"53\" y1=\"60\" x2=\"440\" y2=\"60\" stroke-dasharray=\"2, 2\" style=\"stroke:rgb(211,228,244);stroke-width:2\" />\n"
  68.                 + "  <line x1=\"53\" y1=\"130\" x2=\"440\" y2=\"130\" stroke-dasharray=\"2, 2\" style=\"stroke:rgb(211,228,244);stroke-width:2\" />\n"
  69.                 + "  <line x1=\"53\" y1=\"200\" x2=\"440\" y2=\"200\" stroke-dasharray=\"2, 2\" style=\"stroke:rgb(211,228,244);stroke-width:2\" />\n"
  70.                 + "  <line x1=\"53\" y1=\"270\" x2=\"440\" y2=\"270\" stroke-dasharray=\"2, 2\" style=\"stroke:rgb(211,228,244);stroke-width:2\" />\n"
  71.                 + "  <line x1=\"53\" y1=\"340\" x2=\"440\" y2=\"340\" stroke-dasharray=\"2, 2\" style=\"stroke:rgb(211,228,244);stroke-width:2\" />\n"
  72.                 + "  <line x1=\"53\" y1=\"410\" x2=\"440\" y2=\"410\" stroke-dasharray=\"2, 2\" style=\"stroke:rgb(211,228,244);stroke-width:2\" />\n"
  73.                 + "\n"
  74.                 + "  <line x1=\"70\" y1=\"30\" x2=\"70\" y2=\"440\" stroke-dasharray=\"2, 2\" style=\"stroke:rgb(211,228,244);stroke-width:2\" />\n"
  75.                 + "  <line x1=\"140\" y1=\"30\" x2=\"140\" y2=\"440\" stroke-dasharray=\"2, 2\" style=\"stroke:rgb(211,228,244);stroke-width:2\" />\n"
  76.                 + "  <line x1=\"210\" y1=\"30\" x2=\"210\" y2=\"440\" stroke-dasharray=\"2, 2\" style=\"stroke:rgb(211,228,244);stroke-width:2\" />\n"
  77.                 + "  <line x1=\"280\" y1=\"30\" x2=\"280\" y2=\"440\" stroke-dasharray=\"2, 2\" style=\"stroke:rgb(211,228,244);stroke-width:2\" />\n"
  78.                 + "  <line x1=\"350\" y1=\"30\" x2=\"350\" y2=\"440\" stroke-dasharray=\"2, 2\" style=\"stroke:rgb(211,228,244);stroke-width:2\" />\n"
  79.                 + "  <line x1=\"420\" y1=\"30\" x2=\"420\" y2=\"440\" stroke-dasharray=\"2, 2\" style=\"stroke:rgb(211,228,244);stroke-width:2\" />\n"
  80.                 + "\n";
  81.        
  82.         // add circle
  83.         if(roof == true || walls == true) {
  84.             content += "<circle cx=\""+pixelsX+"\" cy=\""+pixelsY+"\" r=\"5\" fill=\"black\" />\n";
  85.         } else {
  86.             content += "<circle cx=\""+pixelsX+"\" cy=\""+pixelsY+"\" r=\"5\" stroke=\"black\" stroke-width=\"1\" fill=\"#bfbfbf\" />\n";
  87.         }
  88.        
  89.         content += "  <polygon points=\"280,60 420,200 140,200\" style=\"fill:blue;stroke:#002065;stroke-width:2;fill-opacity:0.3;stroke-opacity:0.8\" />\n"
  90.                 + "  <rect x=\"140\" y=\"200\" width=\"140\" height=\"140\" style=\"fill:blue;stroke:#002065;stroke-width:2;fill-opacity:0.3;stroke-opacity:0.8\" />\n"
  91.                 + "  <rect x=\"350\" y=\"200\" width=\"70\" height=\"140\" style=\"fill:blue;stroke:#002065;stroke-width:2;fill-opacity:0.3;stroke-opacity:0.8\" />\n"
  92.                 + "</svg>\n"
  93.                 + " \n"
  94.                 + "</body>\n"
  95.                 + "</html>\n";
  96.        
  97.         try {
  98.            
  99.             // create html file and fill with the html content
  100.             PrintWriter writer = new PrintWriter("house.html", "UTF-8");
  101.             writer.println(content);
  102.             writer.close();
  103.  
  104.         } catch (Exception e) {
  105.         }
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment