This commit is contained in:
2021-07-05 23:30:03 +02:00
parent a73dd7c8f2
commit 32821549bb
4 changed files with 31 additions and 0 deletions

View File

@ -50,6 +50,11 @@ public class Canvas extends JPanel {
g.drawLine(round(x1), round(y1), round(x2), round(y2)); g.drawLine(round(x1), round(y1), round(x2), round(y2));
} }
@Override
public void image(Image image, double x, double y, double w, double h) {
g.drawImage(image, round(x), round(y), round(w), round(h), null);
}
@Override @Override
public void rotated(double theta, double x, double y, Runnable r) { public void rotated(double theta, double x, double y, Runnable r) {
g.rotate(theta, x, y); g.rotate(theta, x, y);

View File

@ -16,6 +16,8 @@ public interface Drawable {
void line(double x1, double y1, double x2, double y2); void line(double x1, double y1, double x2, double y2);
void image(Image image, double x, double y, double w, double h);
void rotated(double theta, double x, double y, Runnable r); void rotated(double theta, double x, double y, Runnable r);
void translated(double x, double y, Runnable r); void translated(double x, double y, Runnable r);

View File

@ -2,15 +2,29 @@ package de.oshgnacknak.gruphi;
import h07.graph.DirectedGraph; import h07.graph.DirectedGraph;
import javax.imageio.ImageIO;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Optional; import java.util.Optional;
class GruphiFrame extends JFrame { class GruphiFrame extends JFrame {
private static final Image NUGGET = loadNugget();
private static Image loadNugget() {
try {
return ImageIO.read(Gruphi.class.getResourceAsStream("/nugget.png"));
} catch (IOException e) {
e.printStackTrace();
}
return new BufferedImage(0, 0, BufferedImage.TYPE_INT_RGB);
}
private final DirectedGraph<Node, Double> graph; private final DirectedGraph<Node, Double> graph;
private final MazeGenerator<Node> mazeGenerator; private final MazeGenerator<Node> mazeGenerator;
@ -23,6 +37,7 @@ class GruphiFrame extends JFrame {
private Node selected = null; private Node selected = null;
private boolean running = true; private boolean running = true;
private boolean nuggets = false;
GruphiFrame(Gruphi gruphi) { GruphiFrame(Gruphi gruphi) {
super("Gruphi - The Graph GUI - By Osh"); super("Gruphi - The Graph GUI - By Osh");
@ -109,6 +124,10 @@ class GruphiFrame extends JFrame {
generateGrid(); generateGrid();
} break; } break;
case KeyEvent.VK_N: {
nuggets = !nuggets;
} break;
default: break; default: break;
} }
} }
@ -240,6 +259,11 @@ class GruphiFrame extends JFrame {
for (var node : graph.getAllNodes()) { for (var node : graph.getAllNodes()) {
d.fill(node.color); d.fill(node.color);
d.ellipse(node.pos.x, node.pos.y, node.radius * 2, node.radius * 2); d.ellipse(node.pos.x, node.pos.y, node.radius * 2, node.radius * 2);
if (nuggets) {
var r = node.radius * 0.9;
d.image(NUGGET, node.pos.x - r, node.pos.y - r, r*2, r*2);
}
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB