Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication2;
- /**
- *
- * @author Nikita
- */
- public class JavaApplication2 {
- final static int size = 51;
- final static int m_size = 21;
- final static int h_size = 15;
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- char[][] buffer = new char[size][size];
- drawFrame(buffer);
- drawLine(buffer, 10, m_size);
- drawLine(buffer, 80, m_size);
- drawLine(buffer, 100, m_size);
- drawLine(buffer, 170, m_size);
- drawLine(buffer, 190, m_size);
- drawLine(buffer, 260, m_size);
- drawLine(buffer, 280, m_size);
- drawLine(buffer, 350, m_size);
- drawBuffer(buffer);
- System.exit(0);
- }
- // magic??
- static void drawLine(char[][] buffer, int degrees, int lineSize) {
- // int targetX = (int) (Math.round(Math.cos(Math.toRadians(degrees)) * lineSize));
- // int targetY = (int) (Math.round(Math.sin(Math.toRadians(degrees)) * lineSize));
- boolean d=false;
- if(degrees>0 && degrees<45) d=true;
- else if(degrees>45 && degrees<180-45) d=false;
- else if(degrees>180-45 && degrees<180+45) d=true;
- else if(degrees>180+45 && degrees<360-45) d=false;
- else if(degrees>360-45) d=true;
- degrees = 180 - degrees;
- float targetX=(float) (Math.cos(Math.toRadians(degrees))*lineSize);
- float targetY=(float) (Math.sin(Math.toRadians(degrees))*lineSize);
- if(d) {
- if(targetX>0) {
- for(int x=0; x<Math.round(targetX); x++) {
- int y=Math.round(targetY/targetX*x);
- buffer[x+25][y+25]='o';
- }
- } else {
- for(int x=0; x>Math.round(targetX); x--) {
- int y=Math.round(targetY/targetX*x);
- buffer[x+25][y+25]='o';
- }
- }
- } else {
- if(targetY>0) {
- for(int y=0; y<Math.round(targetY); y++) {
- int x=Math.round(targetX/targetY*y);
- buffer[x+25][y+25]='o';
- }
- } else {
- for(int y=0; y>Math.round(targetY); y--) {
- int x=Math.round(targetX/targetY*y);
- buffer[x+25][y+25]='o';
- }
- }
- }
- writeStar(buffer);
- }
- static void writeStar(char[][] buffer) {
- buffer[buffer.length/2][buffer.length/2] = '*';
- }
- static void drawFrame(char[][] buffer) {
- for (int x = 0; x < buffer.length; x++)
- for (int y = 0; y < buffer.length; y++) {
- buffer[x][y] = ' ';
- if (x == 0 || x == buffer.length - 1)
- if (y%10 == 0)
- buffer[x][y] = '@';
- else
- buffer[x][y] = 'X';
- if (y == 0 || y == buffer.length - 1)
- if (x%10 == 0)
- buffer[x][y] = '@';
- else
- buffer[x][y] = 'X';
- }
- buffer[2][24] = '1'; buffer[2][26] = '2'; // UPPER 12
- buffer[48][25] = '6'; // BOTTOM 6
- buffer[25][2] = '9'; // LEFT 9
- buffer[25][48] = '3'; // RIGHT 3
- buffer[buffer.length/2][buffer.length/2] = '*';
- }
- static void drawBuffer(char[][] buffer) {
- for (char[] buffer_row : buffer) {
- System.out.println(buffer_row);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment