I am working on a fractal design known as the dragon curve done with Java recursion and StdDraw. It is made up of a square with two other squares branching off from it, one at 30 degrees clockwise and the other 60 degrees counter-clockwise. My angles appear to be correct, but the amount the square translates each time based on the new x and y coordinates are incorrect consistently.
I've tried multiple different values for the x and y coordinates based on what I know about 30 - 60 - 90 triangles and their side length and angle ratios.
public static void main(String[] args)
{
setUpBackground();
int n = 5;
if(args.length > 0)
{
n = Integer.parseInt(args[0]);
}
double xC = 0.5;
double yC = 0.45;
double sideLength = 0.1;
int degrees = 0;
dragonCurve(n, xC, yC, sideLength, degrees);
}
public static void setUpBackground()
{
StdDraw.setCanvasSize(1000, 1000);
StdDraw.setPenColor(Color.BLACK);
StdDraw.filledSquare(0, 0, 1);
}
public static void dragonCurve(int n, double xC, double yC, double sideLength, int degrees)
{
if(n == 0)
{
return;
}
// just a square
StdDraw.picture(xC, yC, "Square.png", sideLength, sideLength, degrees);
dragonCurve(n - 1, xC - sideLength * Math.sqrt(3), yC - sideLength, sideLength * Math.sqrt(3)/2, degrees + 60);
dragonCurve(n - 1, xC + sideLength/2, yC - sideLength * Math.sqrt(3)/2, sideLength/2, degrees - 30);
}
The expected result is a similar design to this dragon curve: !https://photos.google.com/share/AF1QipMmXut-wZ-TQEE43iIl6o6LBS7DxdHhmp2-1FsyB41jaRznwoZ3m0XOw6Ubn0ZHbA?key=SU5TdDQzYWpfeU1aN0N0UTJzT1VHbHFsUTBhb2NR However, my code draws the triangles completely off.