Skip to content

Commit 26fafbe

Browse files
committed
working on HelloBrazil recipe
1 parent a280f7c commit 26fafbe

5 files changed

Lines changed: 107 additions & 7 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package org.teachingextensions.logo.utils.LineAndShapeUtils;
2+
3+
import java.awt.Color;
4+
import java.awt.Graphics2D;
5+
6+
import javax.swing.JPanel;
7+
8+
import org.teachingextensions.WindowUtils.ProgramWindow;
9+
import org.teachingextensions.logo.utils.ColorUtils.PenColors;
10+
11+
/**
12+
* The Diamond allows you to draw diamonds on the window
13+
*/
14+
public class Diamond implements Paintable
15+
{
16+
private final int radius;
17+
private final Color mainColor;
18+
private int x;
19+
private int y;
20+
private int percentTransparent;
21+
public Diamond(int radius, Color color)
22+
{
23+
this.radius = radius;
24+
this.mainColor = color;
25+
}
26+
/**
27+
* Sets the corners of the diamond
28+
* <div><b>Example:</b> {@code diamond.setCorners(8,10)}</div>
29+
*
30+
* @param x
31+
* The x value
32+
* @param y
33+
* The y value
34+
*/
35+
public void setCorners(int x, int y)
36+
{
37+
this.x = x;
38+
this.y = y;
39+
}
40+
public int getRadius()
41+
{
42+
return this.radius;
43+
}
44+
/**
45+
* Adds a diamond to the window
46+
* <div><b>Example:</b> {@code diamond.addTo(panel)}</div>
47+
*
48+
* @param panel
49+
* the ProgramWindow or panel
50+
*/
51+
public void addTo(ProgramWindow panel)
52+
{
53+
panel.getCanvas().add(this);
54+
}
55+
/**
56+
* Paints a diamond
57+
* <div><b>Example:</b> {@code diamond.paint(g,caller)}</div>
58+
*
59+
* @param g
60+
* the graphics object
61+
* @param caller
62+
* the Program Window or panel
63+
*/
64+
@Override
65+
public void paint(Graphics2D g, JPanel caller)
66+
{
67+
Color color2 = PenColors.getTransparentVersion(mainColor, percentTransparent);
68+
g.setColor(color2);
69+
int width = 400;
70+
int height = 300;
71+
g.rotate(50);
72+
g.fillRect(x, y, width, height);
73+
}
74+
/**
75+
* Sets the transparency of the diamond
76+
* <div><b>Example:</b> {@code diamond.setTransparency(80)}</div>
77+
*
78+
* @param percentTransparent
79+
* The percentage of transparency of the diamond
80+
*/
81+
public void setTransparency(int percentTransparent)
82+
{
83+
this.percentTransparent = percentTransparent;
84+
}
85+
public void removeFrom(ProgramWindow panel)
86+
{
87+
panel.remove(this);
88+
}
89+
public int getX()
90+
{
91+
return this.x;
92+
}
93+
public int getY()
94+
{
95+
return this.y;
96+
}
97+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static void main(String[] args)
1010
CoolMaze maze = new CoolMaze(mazeComplexityScale);
1111
StdDraw.show(0);
1212
maze.drawWallsAndEndPoint();
13-
// maze.solveThisMaze();
13+
maze.solveThisMaze();
1414
}
1515
public CoolMaze(int mazeComplexity)
1616
{
@@ -117,6 +117,7 @@ private void createAndSizeEndPoint()
117117
{
118118
StdDraw.filledCircle(mazeComplexity / 2.0 + 0.5, mazeComplexity / 2.0 + 0.5, 0.35);
119119
}
120+
@SuppressWarnings("unused")
120121
private void createAndSizeStartPoint()
121122
{
122123
StdDraw.filledCircle(1.5, 1.5, 0.35);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import javax.imageio.ImageIO;
1313

1414
import org.teachingextensions.approvals.lite.util.MySystem;
15+
import org.teachingextensions.approvals.lite.util.TestUtils;
1516
import org.teachingextensions.approvals.lite.writers.ComponentApprovalWriter;
1617
import org.teachingextensions.virtualproctor.ScreenCapture;
1718

@@ -79,7 +80,7 @@ public static void sendImageToDisk(BufferedImage scaledMazeBackground)
7980
String filename = "./src/main/resources/mazeBackground/CoolMazeBackground.png";
8081
ImageIO.write(scaledMazeBackground, "png", new File(filename));
8182
//TODO If you want to see the file that will be saved, uncomment the line below
82-
//TestUtils.displayFile(filename);
83+
TestUtils.displayFile(filename);
8384
}
8485
catch (Exception e)
8586
{

src/main/java/org/teachingkidsprogramming/recipes/completed/section00demos/BrazilDemo.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.teachingextensions.logo.utils.ColorUtils.PenColors;
55
import org.teachingextensions.logo.utils.EventUtils.MouseLeftClickListener;
66
import org.teachingextensions.logo.utils.LineAndShapeUtils.Circle;
7+
import org.teachingextensions.logo.utils.LineAndShapeUtils.Diamond;
78
import org.teachingextensions.logo.utils.LineAndShapeUtils.Text;
89

910
public class BrazilDemo implements MouseLeftClickListener
@@ -24,13 +25,13 @@ public void onLeftMouseClick(int x, int y)
2425
private void createFlag(int x, int y)
2526
{
2627
programWindow.clearWindow();
28+
Diamond diamond = new Diamond(200, PenColors.Yellows.Yellow);
29+
diamond.setCorners(x, y);
30+
diamond.addTo(programWindow);
31+
new Text("Olá São Paulo").setTopLeft(x, y).addTo(programWindow);
2732
Circle circle = new Circle(100, PenColors.Blues.DarkBlue);
28-
circle.setCenter(x, y);
33+
circle.setCenter(x + 200, y + 150);
2934
circle.addTo(programWindow);
30-
Circle circle1 = new Circle(150, PenColors.Yellows.Yellow);
31-
circle1.setCenter(x + 150, y + 120);
32-
circle1.addTo(programWindow);
33-
new Text("Olá São Paulo").setTopLeft(100, 100).addTo(programWindow);
3435
}
3536
public static void main(String[] args)
3637
{
20 Bytes
Loading

0 commit comments

Comments
 (0)