Updated some broken things
This commit is contained in:
22
map.json
22
map.json
@@ -105,7 +105,7 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"end": {"x": 1, "y": 2}
|
"end": {"x": 2, "y": 0}
|
||||||
},
|
},
|
||||||
"E": {
|
"E": {
|
||||||
"start": {"x": 0, "y": 0},
|
"start": {"x": 0, "y": 0},
|
||||||
@@ -235,7 +235,7 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"end": {"x": 1, "y": 0}
|
"end": {"x": 0, "y": 2}
|
||||||
},
|
},
|
||||||
"J": {
|
"J": {
|
||||||
"start": {"x": 0, "y": 0},
|
"start": {"x": 0, "y": 0},
|
||||||
@@ -542,7 +542,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"x": 0,
|
"x": 0,
|
||||||
"y": 1
|
"y": 2
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -740,5 +740,21 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"end": {"x": 1, "y": 1}
|
"end": {"x": 1, "y": 1}
|
||||||
|
},
|
||||||
|
" ": {
|
||||||
|
"start": {"x": 0, "y": 0},
|
||||||
|
"parts": [
|
||||||
|
{
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"links": [
|
||||||
|
{
|
||||||
|
"x": 1,
|
||||||
|
"y": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"end": {"x": 1, "y": 1}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,12 +2,11 @@ package me.zacharias.star.map;
|
|||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.BufferedReader;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.FileReader;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
|
|
||||||
public class Main extends JPanel {
|
public class Main extends JPanel {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
@@ -21,7 +20,7 @@ public class Main extends JPanel {
|
|||||||
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
|
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
|
||||||
System.out.println("Input word:");
|
System.out.println("Input word:");
|
||||||
//word = in.readLine();
|
//word = in.readLine();
|
||||||
word = "ABCD";
|
word = "This is a long test message that might break. let's hope it don't!";
|
||||||
|
|
||||||
BufferedReader starMapIn = new BufferedReader(new FileReader("./map.json"));
|
BufferedReader starMapIn = new BufferedReader(new FileReader("./map.json"));
|
||||||
String tmp = "";
|
String tmp = "";
|
||||||
@@ -31,6 +30,8 @@ public class Main extends JPanel {
|
|||||||
}
|
}
|
||||||
starMap = new JSONObject(builder.toString());
|
starMap = new JSONObject(builder.toString());
|
||||||
|
|
||||||
|
word = word.toUpperCase().replaceAll("[^A-Z\\ ]", "").trim();
|
||||||
|
|
||||||
JFrame frame = new JFrame();
|
JFrame frame = new JFrame();
|
||||||
frame.add(this);
|
frame.add(this);
|
||||||
frame.setSize(600,400);
|
frame.setSize(600,400);
|
||||||
@@ -43,6 +44,8 @@ public class Main extends JPanel {
|
|||||||
int starSize = 6;
|
int starSize = 6;
|
||||||
int starOffset = starSize/2;
|
int starOffset = starSize/2;
|
||||||
int size = 20;
|
int size = 20;
|
||||||
|
int endX;
|
||||||
|
int endY;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintComponent(Graphics g) {
|
protected void paintComponent(Graphics g) {
|
||||||
@@ -55,22 +58,82 @@ public class Main extends JPanel {
|
|||||||
JSONObject constellation = starMap.getJSONObject(String.valueOf(Character.toUpperCase(c)));
|
JSONObject constellation = starMap.getJSONObject(String.valueOf(Character.toUpperCase(c)));
|
||||||
for(Object part : constellation.getJSONArray("parts")){
|
for(Object part : constellation.getJSONArray("parts")){
|
||||||
if(part instanceof JSONObject jsonObject){
|
if(part instanceof JSONObject jsonObject){
|
||||||
g2d.fillOval(x+size*jsonObject.getInt("x")-starOffset, y+size*jsonObject.getInt("y")-starOffset,starSize,starSize);
|
int x1 = x + size * jsonObject.getInt("x");
|
||||||
|
int y1 = y + size * jsonObject.getInt("y");
|
||||||
|
g2d.fillOval(x1 -starOffset, y1 -starOffset,starSize,starSize);
|
||||||
for(Object lineObj : jsonObject.getJSONArray("links")){
|
for(Object lineObj : jsonObject.getJSONArray("links")){
|
||||||
if(lineObj instanceof JSONObject line){
|
if(lineObj instanceof JSONObject line){
|
||||||
g2d.setStroke(big);
|
g2d.setStroke(big);
|
||||||
g2d.drawLine(x+size*jsonObject.getInt("x"), y+size*jsonObject.getInt("y"), x+size*line.getInt("x"), y+size*line.getInt("y"));
|
int x2 = x + size * line.getInt("x");
|
||||||
|
int y2 = y + size * line.getInt("y");
|
||||||
|
g2d.drawLine(x1, y1, x2, y2);
|
||||||
g2d.setStroke(normal);
|
g2d.setStroke(normal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
g2d.setColor(new Color(178, 164, 0));
|
g2d.setColor(new Color(178, 164, 0));
|
||||||
g2d.fillOval((x+size*constellation.getJSONObject("start").getInt("x"))-starOffset, (y+size*constellation.getJSONObject("start").getInt("y"))-starOffset,starSize,starSize);
|
int startX = x + size * constellation.getJSONObject("start").getInt("x");
|
||||||
g2d.fillOval((x+size*constellation.getJSONObject("end").getInt("x"))-starOffset, (y+size*constellation.getJSONObject("end").getInt("y"))-starOffset,starSize,starSize);
|
int startY = y + size * constellation.getJSONObject("start").getInt("y");
|
||||||
|
g2d.fillOval(startX-starOffset, startY-starOffset,starSize,starSize);
|
||||||
|
int endX = x + size * constellation.getJSONObject("end").getInt("x");
|
||||||
|
int endY = y + size * constellation.getJSONObject("end").getInt("y");
|
||||||
|
g2d.fillOval(endX-starOffset, endY-starOffset,starSize,starSize);
|
||||||
g2d.setColor(new Color(0,0,0));
|
g2d.setColor(new Color(0,0,0));
|
||||||
x = x+size*constellation.getJSONObject("end").getInt("x");
|
x = (((int)(Math.random()*100)%2==0)?endX:startX);
|
||||||
y = y+size*constellation.getJSONObject("end").getInt("y");
|
y = (((int)(Math.random()*100)%2==0)?endY:startY);
|
||||||
|
}
|
||||||
|
|
||||||
|
endX = x;
|
||||||
|
endY = y;
|
||||||
|
|
||||||
|
//createImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createImage(){
|
||||||
|
BufferedImage image = new BufferedImage(endX, endY, BufferedImage.TYPE_INT_ARGB);
|
||||||
|
|
||||||
|
Graphics2D g2d = image.createGraphics();
|
||||||
|
|
||||||
|
g2d.setColor(new Color(0,0,0));
|
||||||
|
|
||||||
|
int x = 40, y = 40;
|
||||||
|
|
||||||
|
for(char c : word.toCharArray()){
|
||||||
|
JSONObject constellation = starMap.getJSONObject(String.valueOf(Character.toUpperCase(c)));
|
||||||
|
for(Object part : constellation.getJSONArray("parts")){
|
||||||
|
if(part instanceof JSONObject jsonObject){
|
||||||
|
int x1 = x + size * jsonObject.getInt("x");
|
||||||
|
int y1 = y + size * jsonObject.getInt("y");
|
||||||
|
g2d.fillOval(x1 -starOffset, y1 -starOffset,starSize,starSize);
|
||||||
|
for(Object lineObj : jsonObject.getJSONArray("links")){
|
||||||
|
if(lineObj instanceof JSONObject line){
|
||||||
|
g2d.setStroke(big);
|
||||||
|
int x2 = x + size * line.getInt("x");
|
||||||
|
int y2 = y + size * line.getInt("y");
|
||||||
|
g2d.drawLine(x1, y1, x2, y2);
|
||||||
|
g2d.setStroke(normal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
g2d.setColor(new Color(178, 164, 0));
|
||||||
|
int startX = x + size * constellation.getJSONObject("start").getInt("x");
|
||||||
|
int startY = y + size * constellation.getJSONObject("start").getInt("y");
|
||||||
|
g2d.fillOval(startX-starOffset, startY-starOffset,starSize,starSize);
|
||||||
|
int endX = x + size * constellation.getJSONObject("end").getInt("x");
|
||||||
|
int endY = y + size * constellation.getJSONObject("end").getInt("y");
|
||||||
|
g2d.fillOval(endX-starOffset, endY-starOffset,starSize,starSize);
|
||||||
|
g2d.setColor(new Color(0,0,0));
|
||||||
|
x = (((int)(Math.random()*0)%2==0)?endX:startX);
|
||||||
|
y = (((int)(Math.random()*0)%2==0)?endY:startY);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
ImageIO.write(image, "png", new File("./starMap.png"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user