import java.awt.*; import java.awt.Graphics; import javax.swing.*; public class rectri extends JFrame { public int width; public int height; public Graphics brush; // object that enables drawing // constructor public rectri(int w, int h) { width =w; height = h; setBounds(0,0,width,height); setVisible(true); // displaying the window setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); brush = getGraphics(); brush.setColor(Color.white); try { Thread.sleep(500); } catch (Exception e) {} // delays program for 500ms brush.fillRect(0,0,width,height); // draws solid rectangle brush.setColor(Color.blue); triangle(width/2,50,24,height-24,width-24,height-24); } public void triangle(int x1, int y1, int x2, int y2, int x3, int y3) { brush.drawLine(x1,y1,x2,y2); brush.drawLine(x2,y2,x3,y3); brush.drawLine(x1,y1,x3,y3); int lx = (x1+x2)/2; int ly = (y1+y2)/2; int rx = (x1+x3)/2; int ry = (y1+y3)/2; int bx = (x2+x3)/2; int by = (y2+y3)/2; if (Math.abs(x2-x3)>=4) { triangle(x1,y1,lx,ly,rx,ry); triangle(lx,ly,x2,y2,bx,by); triangle(rx,ry,bx,by,x3,y3); } } public static void main(String[] args) { rectri T = new rectri(800,600); } }