Corner class:
public class Corner
{
protected int w;
protected int d;
public Corner(int w, int d)
{
this.w = w;
this.d = d;
}
public Corner mid(Corner that)
{
return new Corner((this.w + that.w) / 2, (this.d + that.d) / 2);
}
public int len(Corner that)
{
return (int) Math.sqrt(Math.pow((this.w - that.w), 2)
+ Math.pow((this.d - that.d), 2));
}
}
Triangle class:
import javax.swing.*;
import java.awt.*;
/**
* Triangle class for fractal pattern generation
*/
public class Triangle
{
// indices for sub-triangles
public static final int CORNER_ONE = 0;
public static final int CORNER_TWO = 1;
public static final int CORNER_THREE = 2;
public static final int EDGE_ONE = 3;
public static final int EDGE_TWO = 4;
public static final int EDGE_THREE = 5;
// smallest perimeter for triangle to be drawn
public static final int SMALLEST = 30;
private Corner x;
private Corner y;
private Corner z;
public Triangle(Corner x, Corner y, Corner z)
{
this.x = x;
this.y = y;
this.z = z;
}
public void draw(Graphics screen)
{
screen.drawLine(x.w, x.d, y.w, y.d);
screen.drawLine(y.w, y.d, z.w, z.d);
screen.drawLine(z.w, z.d, x.w, x.d);
}
public int size()
{
// write your code here
return 0;
}
public Triangle getNextLevel(int index)
{
Triangle t = null;
// write your code here
return t;
}
}
Iterative Class:
import javax.swing.*;
import java.awt.*;
import java.util.*;
/**
* Applet with fractal pattern repetition using
* iterative drawing of triangles within triangles
*/
public class Iterative extends JApplet
{
public void paint(Graphics screen)
{
screen.clearRect(0, 0, this.getWidth(), this.getHeight());
screen.drawString("Your Name", 0 , 10);
Corner x = new Corner(0, this.getHeight());
Corner y = new Corner(this.getWidth(), this.getHeight());
Corner z = new Corner(this.getWidth() / 2, 0);
drawTriangle(screen, new Triangle(x, y, z));
}
private void drawTriangle(Graphics screen, Triangle t)
{
// add your code here
}
}
Recursive class
import javax.swing.*;
import java.awt.*;
import java.util.Stack;
/**
* Applet with fractal pattern repetition using
* recursive drawing of triangles within triangles
*/
public class Recursive extends JApplet
{
public void paint(Graphics screen)
{
screen.clearRect(0, 0, this.getWidth(), this.getHeight());
screen.drawString("Your name", 0 , 10);
Corner x = new Corner(0, this.getHeight());
Corner y = new Corner(this.getWidth(), this.getHeight());
Corner z = new Corner(this.getWidth() / 2, 0);
drawTriangle(screen, new Triangle(x, y, z));
}
/**
* recursive version of drawing
*/
private void drawTriangle(Graphics screen, Triangle t)
{
// Write your code here
}
}
Any help would be much appreciated!

New Topic/Question
Reply



MultiQuote




|