Write a program in JAVA in your own original code because i
Write a program in JAVA in your own original code, because i know this is already on chegg which draws (yes it actually makes a picture) a triangular fractal using recursion. This is best if done using a java applet. Also please include comments.
Suggested Methodology
The idea for it is this
First draw a filled equilateral triangle
Next draw another filled equilateral triangle of a different color that’s upside down in the middle of that triangle
Using the other triangles formed repeat step 2 until a pixel limit of 4 is reached
HINTS:
It may be a good idea to look at the examples I gave 02/12/2015
The method fillPolygon(int[] xPoints, int[] yPoint, numberOfPoints) as called by the graphics device is important
The method setColor(Color aColor) is important for picking different colors to draw things.
Solution
package chegg;
import java.awt.*;
 import java.applet.Applet;
 import java.awt.Color;
 import java.awt.Graphics;
 import java.awt.Point;
 public class DrawTraingle extends Applet
 {
  
 Graphics g;
 Point a1,b1,c1, a2,b2,c2, a3,b3,c3;
int depth = 0;
public void init()
 {
 setBackground(new Color(255,255,255));
 setBackground( Color.white );
 }
public boolean mouseDown(Event click, int x, int y)
 {
 if (!click.metaDown()) depth += 1;
 else if (depth>0) depth -= 1;
 repaint();
 return true;
 }
 public void paint(Graphics tri)
 {
 tri.setColor( Color.black );
 //setBackground(Color.black);
   
 int xCoords[] = {10, 390, 200};
 int yCoords[] = {390, 390, 10};
 // Polygon p = new Polygon(xCoords, yCoords, 3);
 //tri.fillPolygon(p);
 tri.drawPolygon(xCoords, yCoords, 3);
 //Polygon p = new Polygon(xCoords, yCoords, 3);
 // tri.fillPolygon(p);
 // drawTriangle(tri, new Point(10,390),new Point(390,390),new Point(200,10), depth);
 }
 public void paint1(Graphics tri)
 {
 tri.setColor( Color.black );
 //setBackground(Color.black);
   
 int xCoords[] = {10, 390, 200};
 int yCoords[] = {390, 390, 10};
 // Polygon p = new Polygon(xCoords, yCoords, 3);
 // tri.fillPolygon(p);
 tri.drawPolygon(xCoords, yCoords, 3);
 //Polygon p = new Polygon(xCoords, yCoords, 3);
 // tri.fillPolygon(p);
 drawTriangle(tri, new Point(10,390),new Point(390,390),new Point(200,10), depth);
 }
   
public void drawTriangle(Graphics g, Point a, Point b, Point c, int depth)
 {
 //   setBackground(Color.black);
 if (depth==0) return;
depth -= 1;
 int xCoords[] = {c.x, (c.x+b.x)/2, (a.x+c.x)/2};
 int yCoords[] = {b.y, (c.y+a.y)/2, (c.y+a.y)/2};
g.drawPolygon(xCoords, yCoords, 3);
a1 = a;
 b1 = new Point(c.x, b.y);
 c1 = new Point((a.x+c.x)/2, (c.y+a.y)/2);
 drawTriangle(g, a1, b1, c1, depth);
a2 = new Point(c.x, b.y);
 b2 = b;
 c2 = new Point((c.x+b.x)/2, (c.y+a.y)/2);
 drawTriangle(g, a2, b2, c2, depth);
a3 = new Point((a.x+c.x)/2, (c.y+a.y)/2);
 b3 = new Point((c.x+b.x)/2, (c.y+a.y)/2);
 c3 = c;
 drawTriangle(g, a3, b3, c3, depth);
 }
 }


