aeroson

Untitled

Oct 17th, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7. package javaapplication2;
  8.  
  9. /**
  10. *
  11. * @author Nikita
  12. */
  13. public class JavaApplication2 {
  14.  
  15. final static int size = 51;
  16. final static int m_size = 21;
  17. final static int h_size = 15;
  18. /**
  19. * @param args the command line arguments
  20. */
  21. public static void main(String[] args) {
  22. char[][] buffer = new char[size][size];
  23. drawFrame(buffer);
  24. drawLine(buffer, 10, m_size);
  25. drawLine(buffer, 80, m_size);
  26. drawLine(buffer, 100, m_size);
  27. drawLine(buffer, 170, m_size);
  28. drawLine(buffer, 190, m_size);
  29. drawLine(buffer, 260, m_size);
  30. drawLine(buffer, 280, m_size);
  31. drawLine(buffer, 350, m_size);
  32. drawBuffer(buffer);
  33. System.exit(0);
  34.  
  35. }
  36. // magic??
  37. static void drawLine(char[][] buffer, int degrees, int lineSize) {
  38.  
  39. // int targetX = (int) (Math.round(Math.cos(Math.toRadians(degrees)) * lineSize));
  40. // int targetY = (int) (Math.round(Math.sin(Math.toRadians(degrees)) * lineSize));
  41.  
  42. boolean d=false;
  43. if(degrees>0 && degrees<45) d=true;
  44. else if(degrees>45 && degrees<180-45) d=false;
  45. else if(degrees>180-45 && degrees<180+45) d=true;
  46. else if(degrees>180+45 && degrees<360-45) d=false;
  47. else if(degrees>360-45) d=true;
  48.  
  49. degrees = 180 - degrees;
  50.  
  51. float targetX=(float) (Math.cos(Math.toRadians(degrees))*lineSize);
  52. float targetY=(float) (Math.sin(Math.toRadians(degrees))*lineSize);
  53.  
  54.  
  55. if(d) {
  56.  
  57. if(targetX>0) {
  58. for(int x=0; x<Math.round(targetX); x++) {
  59. int y=Math.round(targetY/targetX*x);
  60. buffer[x+25][y+25]='o';
  61. }
  62. } else {
  63. for(int x=0; x>Math.round(targetX); x--) {
  64. int y=Math.round(targetY/targetX*x);
  65. buffer[x+25][y+25]='o';
  66. }
  67. }
  68. } else {
  69.  
  70. if(targetY>0) {
  71. for(int y=0; y<Math.round(targetY); y++) {
  72. int x=Math.round(targetX/targetY*y);
  73. buffer[x+25][y+25]='o';
  74. }
  75. } else {
  76. for(int y=0; y>Math.round(targetY); y--) {
  77. int x=Math.round(targetX/targetY*y);
  78. buffer[x+25][y+25]='o';
  79. }
  80. }
  81.  
  82. }
  83.  
  84.  
  85. writeStar(buffer);
  86. }
  87.  
  88. static void writeStar(char[][] buffer) {
  89. buffer[buffer.length/2][buffer.length/2] = '*';
  90. }
  91.  
  92. static void drawFrame(char[][] buffer) {
  93. for (int x = 0; x < buffer.length; x++)
  94. for (int y = 0; y < buffer.length; y++) {
  95. buffer[x][y] = ' ';
  96. if (x == 0 || x == buffer.length - 1)
  97. if (y%10 == 0)
  98. buffer[x][y] = '@';
  99. else
  100. buffer[x][y] = 'X';
  101. if (y == 0 || y == buffer.length - 1)
  102. if (x%10 == 0)
  103. buffer[x][y] = '@';
  104. else
  105. buffer[x][y] = 'X';
  106. }
  107. buffer[2][24] = '1'; buffer[2][26] = '2'; // UPPER 12
  108. buffer[48][25] = '6'; // BOTTOM 6
  109. buffer[25][2] = '9'; // LEFT 9
  110. buffer[25][48] = '3'; // RIGHT 3
  111. buffer[buffer.length/2][buffer.length/2] = '*';
  112. }
  113.  
  114. static void drawBuffer(char[][] buffer) {
  115. for (char[] buffer_row : buffer) {
  116. System.out.println(buffer_row);
  117. }
  118. }
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment