Advertisement
Guest User

Untitled

a guest
May 13th, 2014
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. import java.awt.geom.Path2D;
  2. import java.io.BufferedWriter;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.io.OutputStreamWriter;
  6. import java.io.Writer;
  7. import java.util.Scanner;
  8.  
  9. public class _10_PaintHouseAsSVG {
  10. public static void main(String[] args) throws IOException {
  11. //the house painting
  12. double[] xCoordinates = new double[]{12.5,17.5,17.5,20,20,22.5,22.5,17.5,12.5};
  13. double[] yCoordinates = new double[]{13.5,13.5,8.5,8.5,13.5,13.5,8.5,3.5,8.5};
  14. Path2D poli = new Path2D.Double();
  15. poli.moveTo(10*xCoordinates[0], 10*yCoordinates[0]);
  16. for (int i=1; i<xCoordinates.length; i++){
  17. poli.lineTo(10*xCoordinates[i], 10*yCoordinates[i]);
  18. }
  19. Scanner input = new Scanner(System.in);
  20. String dots ="";
  21. for ( int i = 0; i<1; ){
  22. System.out.print("enter X coo: ");
  23. String inputX = input.nextLine();
  24.  
  25. if (inputX.equals("")){
  26. i++;
  27. input.close();
  28. }else{
  29. System.out.print("enter Y coo: ");
  30. String inputY = input.nextLine();
  31. double x = 10*Double.parseDouble(inputX);
  32. double y = 10*Double.parseDouble(inputY);
  33.  
  34. if (poli.contains(x, y)){
  35. dots += "<circle cx=\""+x+"\" cy=\""+y+"\" r=\"1\" stroke=\"black\" stroke-width=\"1\" fill=\"black\" />";
  36. }else{
  37. dots += "<circle cx=\""+x+"\" cy=\""+y+"\" r=\"1\" stroke=\"red\" stroke-width=\"1\" fill=\"red\" />";
  38. }
  39. }
  40. }
  41.  
  42. Writer writer = null;
  43. try {
  44. writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("document.html"), "utf-8"));
  45. String triangle = "<polygon points=\"125,85 225,85 175,35\"style=\"stroke:#330099; fill:#00FFFF;\"/>";
  46. String rect1 = "<polygon points=\"125,85 175,85 175,135 125,135\"style=\"stroke:#330099; fill:#00FFFF;\"/>";
  47. String rect2 = "<polygon points=\"200,135 225,135 225,85 200,85\"style=\"stroke:#330099; fill:#00FFFF;\"/>";
  48. writer.write("<div>\n<svg>\n"+triangle+rect1+rect2+dots+"</svg></div>");
  49. } catch (IOException ex) {
  50. } finally {
  51. try {writer.close();} catch (Exception ex) {}
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement