public class Pythagoras2 extends Actor
{
/**
* Act - do whatever the Pythagoras2 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
final int depth = 7;
public Pythagoras2()
{
GreenfootImage gfim = new GreenfootImage(900,600);
drawTree(gfim, 275, 500, 375, 500, 0);
setImage(gfim);
}
private void drawTree(GreenfootImage gfim, float x1, float y1, float x2, float y2,
int depth)
{
if (depth == 0)
return;
float dx = x2 - x1;
float dy = y1 - y2;
float x3 = x2 - dy;
float y3 = y2 - dx;
float x4 = x1 - dy;
float y4 = y1 - dx;
float x5 = x4 + 0.5F * (dx - dy);
float y5 = y4 - 0.5F * (dx + dy);
gfim.setColor(Color.BLUE);
gfim.drawLine ((int)x1, (int)y1, (int)x2, (int)y2);
gfim.drawLine ((int)x2, (int)y2, (int)x4, (int)y4);
gfim.drawLine ((int)x4, (int)y4, (int)x3, (int)y3);
gfim.drawLine ((int)x1, (int)y1, (int)x3, (int)y3);
gfim.setColor(Color.GREEN);
gfim.fillPolygon(new int {(int)x1,(int)x2,(int)x4,(int)x3},
new int {(int)y1,(int)y2,(int)y4,(int)y3}, 4);
drawTree(gfim, x4, y4, x5, y5, depth + 1);
drawTree(gfim, x5, y5, x3, y3, depth + 1);
}
}
I started to make a Pythagorean tree from various source codes, it does not work but does not indicate any error, I think I'm on the right track, I hope I did not do anything
Thank you for your help