/** Copyright 2002 Henry Bottomley (henry.bottomley@btinternet.com) * Published for information and comment purposes */ import java.awt.*; import java.awt.image.*; import java.applet.*; import java.lang.*; public class Halfarea extends Applet { protected int x1, x4, x5, y1, y4, y5; protected final static int x2=100; protected final static int x3=400; protected final static int y2=310; protected final static int y3=310; /////////////////////////////////////////////////////////////////////////// public void init() { x1=100; y1=10; } /////////////////////////////////////////////////////////////////////////// public void paint (Graphics g) { g.setColor(Color.white);//blank the applet g.fillRect(0, 0, size().width, size().height); g.setColor(Color.green);// other area bisectors g.drawLine((x1+x2*9)/10,(y1+y2*9)/10,(x1*4+x3*5)/9,(y1*4+y3*5)/9); g.drawLine((x2+x3*9)/10,(y2+y3*9)/10,(x2*4+x1*5)/9,(y2*4+y1*5)/9); g.drawLine((x3+x1*9)/10,(y3+y1*9)/10,(x3*4+x2*5)/9,(y3*4+y2*5)/9); g.drawLine((x1+x3*9)/10,(y1+y3*9)/10,(x1*4+x2*5)/9,(y1*4+y2*5)/9); g.drawLine((x3+x2*9)/10,(y3+y2*9)/10,(x3*4+x1*5)/9,(y3*4+y1*5)/9); g.drawLine((x2+x1*9)/10,(y2+y1*9)/10,(x2*4+x3*5)/9,(y2*4+y3*5)/9); g.drawLine((x1+x2*4)/5,(y1+y2*4)/5,(x1*3+x3*5)/8,(y1*3+y3*5)/8); g.drawLine((x2+x3*4)/5,(y2+y3*4)/5,(x2*3+x1*5)/8,(y2*3+y1*5)/8); g.drawLine((x3+x1*4)/5,(y3+y1*4)/5,(x3*3+x2*5)/8,(y3*3+y2*5)/8); g.drawLine((x1+x3*4)/5,(y1+y3*4)/5,(x1*3+x2*5)/8,(y1*3+y2*5)/8); g.drawLine((x3+x2*4)/5,(y3+y2*4)/5,(x3*3+x1*5)/8,(y3*3+y1*5)/8); g.drawLine((x2+x1*4)/5,(y2+y1*4)/5,(x2*3+x3*5)/8,(y2*3+y3*5)/8); g.drawLine((x1*2929+x2*7071)/10000,(y1*2929+y2*7071)/10000,(x1*2929+x3*7071)/10000,(y1*2929+y3*7071)/10000); g.drawLine((x2*2929+x3*7071)/10000,(y2*2929+y3*7071)/10000,(x2*2929+x1*7071)/10000,(y2*2929+y1*7071)/10000); g.drawLine((x3*2929+x1*7071)/10000,(y3*2929+y1*7071)/10000,(x3*2929+x2*7071)/10000,(y3*2929+y2*7071)/10000); g.setColor(Color.blue);// medians g.drawLine(x1,y1,(x2+x3)/2,(y2+y3)/2); g.drawLine(x2,y2,(x3+x1)/2,(y3+y1)/2); g.drawLine(x3,y3,(x1+x2)/2,(y1+y2)/2); g.setColor(Color.red);// the deltoid x5=(x1+x2+2*x3)/4; y5=(y1+y2+2*y3)/4; for (int i=26; i<=50; i++) { x4=(x2*i*i+1250*x3+(100*i-i*i-1250)*x1)/(100*i); y4=(y2*i*i+1250*y3+(100*i-i*i-1250)*y1)/(100*i); g.drawLine(x4,y4,x5,y5); x5=x4; y5=y4; } x5=(x2+x3+2*x1)/4; y5=(y2+y3+2*y1)/4; for (int i=26; i<=50; i++) { x4=(x3*i*i+1250*x1+(100*i-i*i-1250)*x2)/(100*i); y4=(y3*i*i+1250*y1+(100*i-i*i-1250)*y2)/(100*i); g.drawLine(x4,y4,x5,y5); x5=x4; y5=y4; } x5=(x3+x1+2*x2)/4; y5=(y3+y1+2*y2)/4; for (int i=26; i<=50; i++) { x4=(x1*i*i+1250*x2+(100*i-i*i-1250)*x3)/(100*i); y4=(y1*i*i+1250*y2+(100*i-i*i-1250)*y3)/(100*i); g.drawLine(x4,y4,x5,y5); x5=x4; y5=y4; } g.setColor(Color.black); // edges of the original triangle g.drawLine(x1,y1,x2,y2); g.drawLine(x2,y2,x3,y3); g.drawLine(x3,y3,x1,y1); } /////////////////////////////////////////////////////////////////////////// //taken from comp.lang.java FAQ private Image offScreenImage; private Dimension offScreenSize; private Graphics offScreenGraphics; public final synchronized void update (Graphics g) { Dimension d = size(); if((offScreenImage == null) || (d.width != offScreenSize.width) || (d.height != offScreenSize.height)) { offScreenImage = createImage(d.width, d.height); offScreenSize = d; offScreenGraphics = offScreenImage.getGraphics(); } offScreenGraphics.clearRect(0, 0, d.width, d.height); paint(offScreenGraphics); g.drawImage(offScreenImage, 0, 0, null); } /////////////////////////////////////////////////////////////////////////// public boolean mouseDown (Event evt, int x, int y) // identify point chosen for start { x1 = x; y1 = y; repaint(); return true; } /////////////////////////////////////////////////////////////////////////// public boolean mouseDrag (Event evt, int x, int y) { x1 = x; y1 = y; repaint(); return true; } /////////////////////////////////////////////////////////////////////////// } // end of class