* default with 60,60,15 labyrinth

* display labyrinth at re-recreation.
* save only labyrinth view ( png without background ).
This commit is contained in:
philippe lhardy
2017-11-18 21:44:01 +01:00
parent 65b9fb31dd
commit 2e5095372a
2 changed files with 30 additions and 20 deletions

View File

@@ -56,7 +56,7 @@ public class Display extends JFrame
LabyModel model; LabyModel model;
JPanel controlPanel; JPanel controlPanel;
boolean autoSize; boolean autoSize;
// MazeParamsFixed fixedParams = null;
MazeParams params = null; MazeParams params = null;
Display(LabyModel model,int W, int H, MazeParams params) Display(LabyModel model,int W, int H, MazeParams params)
@@ -100,8 +100,7 @@ public class Display extends JFrame
void recreateModel() void recreateModel()
{ {
// recreate labyrinth TODO / FIXME // recreate labyrinth
System.out.println("TODO recreateModel");
if (params != null) if (params != null)
{ {
params = controler.getSettings().getParams(); params = controler.getSettings().getParams();
@@ -109,9 +108,14 @@ public class Display extends JFrame
maze.resetWallsProvider(model); maze.resetWallsProvider(model);
model.setMazeListener(maze); model.setMazeListener(maze);
// we are in GUI event thread, need to release it and do it outside.
new Thread() {
public void run() {
model.generateWithEntry(0, 0); model.generateWithEntry(0, 0);
model.addEntryOrExit(-1, 0); model.addEntryOrExit(-1, 0);
model.addEntryOrExit(params.getWidth(), params.getHeight() - 1); model.addEntryOrExit(params.getWidth(), params.getHeight() - 1);
}
}.start();
} }
} }
@@ -158,9 +162,11 @@ public class Display extends JFrame
void savePng() void savePng()
{ {
File file = new File("snapshot.png"); File file = new File("snapshot.png");
BufferedImage bi = new BufferedImage(this.getSize().width, this.getSize().height, BufferedImage.TYPE_INT_ARGB); // BufferedImage bi = new BufferedImage(this.getSize().width, this.getSize().height, BufferedImage.TYPE_INT_ARGB);
BufferedImage bi = new BufferedImage(maze.getSize().width, maze.getSize().height, BufferedImage.TYPE_INT_ARGB);
Graphics g = bi.createGraphics(); Graphics g = bi.createGraphics();
this.paint(g); // this.paint(g);
maze.paint(g);
g.dispose(); g.dispose();
try{ try{
ImageIO.write(bi,"png",file); ImageIO.write(bi,"png",file);
@@ -186,6 +192,8 @@ public class Display extends JFrame
} }
void createSettingsGui() void createSettingsGui()
{
if ( params != null )
{ {
JButton buttonCreate = new JButton(labels.getString("create")); JButton buttonCreate = new JButton(labels.getString("create"));
buttonCreate.addActionListener(new ActionListener() buttonCreate.addActionListener(new ActionListener()
@@ -196,6 +204,7 @@ public class Display extends JFrame
} }
}); });
add(buttonCreate); add(buttonCreate);
}
if ( params != null ) if ( params != null )
{ {
JLabel widthLabel = new JLabel(labels.getString("width")); JLabel widthLabel = new JLabel(labels.getString("width"));
@@ -223,7 +232,7 @@ public class Display extends JFrame
} }
private class MazeParamsFixed implements MazeParams private static class MazeParamsFixed implements MazeParams
{ {
int width; int width;
int height; int height;
@@ -848,9 +857,7 @@ public class Display extends JFrame
} }
else else
{ {
System.out.println("enter width height and maxdepth"); MazeParamsFixed params = new MazeParamsFixed(new File("lab"),60,60,15);
MazeParamEditor params = new MazeParamEditor(new File("lab"));
params.read(new Scanner(System.in));
model = new LabyModel(params, new java.util.Random()); model = new LabyModel(params, new java.util.Random());
setupDisplay(model,W,H,params); setupDisplay(model,W,H,params);

View File

@@ -123,6 +123,9 @@ public class Wall3d
} }
/**
write triangles as stl text
**/
public String toString() public String toString()
{ {
String s = ""; String s = "";