Skip to content

Commit 0af2de6

Browse files
committed
working on TortoiseMaze w/ @mballin
1 parent f3bb7fa commit 0af2de6

4 files changed

Lines changed: 62 additions & 8 deletions

File tree

src/main/java/org/teachingextensions/logo/utils/MazeUtils/CoolMaze.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public static void main(String[] args)
99
int mazeComplexityScale = 10;
1010
CoolMaze maze = new CoolMaze(mazeComplexityScale);
1111
StdDraw.show(0);
12-
maze.drawWallsAndStartAndEndPoints();
13-
maze.solveThisMaze();
12+
maze.drawWallsAndEndPoint();
13+
// maze.solveThisMaze();
1414
}
1515
public CoolMaze(int mazeComplexity)
1616
{
@@ -20,11 +20,10 @@ public CoolMaze(int mazeComplexity)
2020
createMazeStructure();
2121
generateStartLocation(1, 1);
2222
}
23-
public void drawWallsAndStartAndEndPoints()
23+
public void drawWallsAndEndPoint()
2424
{
25-
Color colorOfStartAndEndPoints = StdDrawColors.GREEN;
26-
StdDraw.setPenColor(colorOfStartAndEndPoints);
27-
createAndSizeStartPoint();
25+
StdDraw.setPenColor(StdDrawColors.GREEN);
26+
// createAndSizeStartPoint();
2827
createAndSizeEndPoint();
2928
drawAndColorMazeWalls();
3029
StdDraw.show(1000);
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.teachingextensions.logo.utils.MazeUtils;
2+
3+
import java.awt.Component;
4+
import java.awt.event.WindowAdapter;
5+
import java.awt.event.WindowEvent;
6+
import java.awt.image.BufferedImage;
7+
import java.io.File;
8+
9+
import javax.imageio.ImageIO;
10+
11+
import org.teachingextensions.approvals.lite.util.MySystem;
12+
import org.teachingextensions.approvals.lite.util.TestUtils;
13+
import org.teachingextensions.approvals.lite.writers.ComponentApprovalWriter;
14+
import org.teachingextensions.virtualproctor.ScreenCapture;
15+
16+
/*****in progress****/
17+
public class CreateMazeBackgroundFile extends WindowAdapter
18+
{
19+
public static void main(String[] args)
20+
{
21+
CoolMaze maze1 = new CoolMaze(8);
22+
maze1.drawWallsAndEndPoint();
23+
StdDraw.frame.dispatchEvent(new WindowEvent(StdDraw.frame, WindowEvent.WINDOW_CLOSING));
24+
}
25+
@Override
26+
// TODO Verify the event firing and image creation
27+
public void windowClosing(WindowEvent event)
28+
{
29+
BufferedImage scaled = ScreenCapture.getScaledImageOf(event.getComponent(), 350, 350);
30+
System.out.println("did it?");
31+
sendImageToDisk(scaled);
32+
}
33+
public static BufferedImage getImageOf(Component component, int width, int height)
34+
{
35+
BufferedImage image = ComponentApprovalWriter.drawComponent(component);
36+
return image;
37+
}
38+
public void sendImageToDisk(BufferedImage image)
39+
{
40+
try
41+
{
42+
//String filename = "C:\\temp\\CoolMazeBackground.png";
43+
String filename = "./CoolMazeBackground.png";
44+
ImageIO.write(image, "png", new File(filename));
45+
TestUtils.displayFile(filename);
46+
}
47+
catch (Exception e)
48+
{
49+
MySystem.warning(e);
50+
}
51+
}
52+
// TODO: set this image as a background image for the TortoiseMaze recipe
53+
}

src/main/java/org/teachingextensions/logo/utils/MazeUtils/StdDraw.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
public final class StdDraw implements ActionListener, KeyListener
4444
{
45-
private static final int DEFAULT_SIZE = 512;
45+
private static final int DEFAULT_SIZE = 350;
4646
private static int width = DEFAULT_SIZE;
4747
private static int height = DEFAULT_SIZE;
4848
private static final double DEFAULT_PEN_RADIUS = 0.0175;
@@ -59,7 +59,7 @@ public final class StdDraw implements ActionListener, KeyListener
5959
private static BufferedImage offscreenImage, onscreenImage;
6060
private static Graphics2D offscreen, onscreen;
6161
private static StdDraw stdDraw = new StdDraw();
62-
private static JFrame frame;
62+
public static JFrame frame;
6363
private static Object keyLock = new Object();
6464
private static LinkedList<Character> keysTyped = new LinkedList<Character>();
6565
private static TreeSet<Integer> keysDown = new TreeSet<Integer>();

src/main/java/org/teachingkidsprogramming/recipes/completed/section08events/TortoiseMaze.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ private void setUpTortoise()
8282
Tortoise.setSpeed(10);
8383
Tortoise.setPenColor(PenColors.Greens.Green);
8484
Tortoise.setPenWidth(4);
85+
// TODO: Generate a unique maze png and set as background for this maze instance
86+
//call tortoiseMaze.setupBackground
8587
}
8688
private void addButtonToWindow(JButton button)
8789
{

0 commit comments

Comments
 (0)