I'm working on a homework to create a program that takes one argument "n" and creates a cantor line of that depth, but it does not seem to be working. I think there's a problem with variable scope and functions. This is the first time I work with functions and recursion, so I'm a little confused still. I have three functions, one to draw the relative left line, the relative right line, and the cantor function which calls itself twice and calls both draw functions.
public class Art
{
public static void drawLeftLine(double x0, double y0, double x1, double y1)
{
double x2 = (1/3.0)*(x1 - x0);
double x3 = x0;
double y2 = y0 - 0.1;
double y3 = y1 - 0.1;
StdDraw.line(x2, y2, x3, y3);
}
public static void drawRightLine(double x0, double y0, double x1, double y1)
{
double x2 = (2/3.0)*(x1 - x0);
double x3 = x1;
double y2 = y0 - 0.1;
double y3 = y1 - 0.1;
StdDraw.line(x2, y2, x3, y3);
}
public static void cantor(int n, double x0, double y0, double x1, double y1)
{
if (n == 0)
return;
drawLeftLine(x0, y0, x1, y1);
drawRightLine(x0, y0, x1, y1);
cantor(n-1, x0, y0, x1, y1); //left
cantor(n-1, x0, y0, x1, y1); //right
}
public static void main(String[] args)
{
int n = Integer.parseInt(args[0]);
double x0 = 0;
double y0 = 0.9;
double x1 = 0.9;
double y1 = 0.9;
StdDraw.line(x0, y0, x1, y1);
cantor(n, x0, y0, x1, y1);
}
}