Created
February 14, 2015 15:05
-
-
Save benallard/f9339db9d6a2a1b0136e to your computer and use it in GitHub Desktop.
Patch for http://www.cs.cornell.edu/home/chew/Delaunay.html that adds a background image.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This patch displays the background.png image as background of the drawing area | |
If no image can be loaded, the previous behavior is kept. | |
diff -Npru delaunay 2/DelaunayAp.java delaunay/DelaunayAp.java | |
--- delaunay 2/DelaunayAp.java 2007-12-14 14:51:28.000000000 +0100 | |
+++ delaunay/DelaunayAp.java 2015-02-14 16:03:21.000000000 +0100 | |
@@ -22,6 +22,7 @@ package delaunay; | |
import java.awt.*; | |
import java.awt.event.*; | |
+import java.io.*; | |
import java.util.HashMap; | |
import java.util.HashSet; | |
import java.util.List; | |
@@ -29,6 +30,7 @@ import java.util.Map; | |
import java.util.Random; | |
import javax.swing.*; | |
+import javax.imageio.ImageIO; | |
/** | |
* The Delauany applet. | |
@@ -339,13 +341,21 @@ class DelaunayPanel extends JPanel { | |
super.paintComponent(g); | |
this.g = g; | |
- // Flood the drawing area with a "background" color | |
- Color temp = g.getColor(); | |
- if (!controller.isVoronoi()) g.setColor(delaunayColor); | |
- else if (dt.contains(initialTriangle)) g.setColor(this.getBackground()); | |
- else g.setColor(voronoiColor); | |
- g.fillRect(0, 0, this.getWidth(), this.getHeight()); | |
- g.setColor(temp); | |
+ | |
+ try | |
+ { | |
+ // Draw a background image | |
+ Image bgImage = ImageIO.read(new File("delaunay/background.png")); | |
+ g.drawImage(bgImage, 0, 0, null); | |
+ } catch (IOException e) { | |
+ // Flood the drawing area with a "background" color | |
+ Color bgColor = g.getColor(); | |
+ if (!controller.isVoronoi()) g.setColor(delaunayColor); | |
+ else if (dt.contains(initialTriangle)) g.setColor(this.getBackground()); | |
+ else g.setColor(voronoiColor); | |
+ g.fillRect(0, 0, this.getWidth(), this.getHeight()); | |
+ g.setColor(bgColor); | |
+ } | |
// If no colors then we can clear the color table | |
if (!controller.isColorful()) colorTable.clear(); | |
@@ -356,7 +366,7 @@ class DelaunayPanel extends JPanel { | |
else drawAllDelaunay(controller.isColorful()); | |
// Draw any extra info due to the mouse-entry switches | |
- temp = g.getColor(); | |
+ Color temp = g.getColor(); | |
g.setColor(Color.white); | |
if (controller.showingCircles()) drawAllCircles(); | |
if (controller.showingDelaunay()) drawAllDelaunay(false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment