Nuggets
This commit is contained in:
		
							parent
							
								
									a73dd7c8f2
								
							
						
					
					
						commit
						32821549bb
					
				
					 4 changed files with 31 additions and 0 deletions
				
			
		|  | @ -50,6 +50,11 @@ public class Canvas extends JPanel { | |||
|                 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 | ||||
|             public void rotated(double theta, double x, double y, Runnable r) { | ||||
|                 g.rotate(theta, x, y); | ||||
|  |  | |||
|  | @ -16,6 +16,8 @@ public interface Drawable { | |||
| 
 | ||||
|     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 translated(double x, double y, Runnable r); | ||||
|  |  | |||
|  | @ -2,15 +2,29 @@ package de.oshgnacknak.gruphi; | |||
| 
 | ||||
| import h07.graph.DirectedGraph; | ||||
| 
 | ||||
| import javax.imageio.ImageIO; | ||||
| import javax.swing.*; | ||||
| import java.awt.*; | ||||
| import java.awt.event.KeyAdapter; | ||||
| import java.awt.event.KeyEvent; | ||||
| import java.awt.event.MouseEvent; | ||||
| import java.awt.image.BufferedImage; | ||||
| import java.io.IOException; | ||||
| import java.util.Optional; | ||||
| 
 | ||||
| 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 MazeGenerator<Node> mazeGenerator; | ||||
|  | @ -23,6 +37,7 @@ class GruphiFrame extends JFrame { | |||
| 
 | ||||
|     private Node selected = null; | ||||
|     private boolean running = true; | ||||
|     private boolean nuggets = false; | ||||
| 
 | ||||
|     GruphiFrame(Gruphi gruphi) { | ||||
|         super("Gruphi - The Graph GUI - By Osh"); | ||||
|  | @ -109,6 +124,10 @@ class GruphiFrame extends JFrame { | |||
|                         generateGrid(); | ||||
|                     } break; | ||||
| 
 | ||||
|                     case KeyEvent.VK_N: { | ||||
|                         nuggets = !nuggets; | ||||
|                     } break; | ||||
| 
 | ||||
|                     default: break; | ||||
|                 } | ||||
|             } | ||||
|  | @ -240,6 +259,11 @@ class GruphiFrame extends JFrame { | |||
|         for (var node : graph.getAllNodes()) { | ||||
|             d.fill(node.color); | ||||
|             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); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										
											BIN
										
									
								
								src/main/resources/nugget.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/main/resources/nugget.png
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 110 KiB | 
		Reference in a new issue