import java.awt.Graphics; public class c05_mrcm extends java.applet.Applet { static final int n = 4; static final int left = 30; static final int w = 300; static final int wl = w + left; /*double a[] = {0.5, 0.5, 0.5}; double b[] = {0, 0, 0}; double c[] = {0, 0, 0}; double d[] = {0.5, 0.5, 0.5}; double e[] = {0, 0.5*w, 0.25*w}; double f[] = {0, 0, 0.5*w};*/ double a[] = {0.387, 0.441, -0.468}; double b[] = {0.430, -0.091, 0.020}; double c[] = {0.430, -0.009, -0.113}; double d[] = {-0.387, -0.322, 0.015}; double e[] = {0.2560*w, 0.4219*w, 0.4000*w}; double f[] = {0.5220*w, 0.5059*w, 0.4000*w}; public void paint(Graphics g) { mrcm(g, 0, 0, 0, w, 0, 0.5*w, w); } private void mrcm(Graphics g, int level, double xleft, double yleft, double xright, double yright, double xtop, double ytop) { if (level < n) { for (int i = 0; i < 3; i++) { double xl = a[i]*xleft + b[i]*yleft + e[i]; double yl = c[i]*xleft + d[i]*yleft + f[i]; double xr = a[i]*xright + b[i]*yright + e[i]; double yr = c[i]*xright + d[i]*yright + f[i]; double xt = a[i]*xtop + b[i]*ytop + e[i]; double yt = c[i]*xtop + d[i]*ytop + f[i]; mrcm(g, level+1, xl, yl, xr, yr, xt, yt); } } else { LineTo lt = new LineTo(g); lt.drawLine(left+(int)xleft, wl-(int)yleft, left+(int)xright, wl-(int)yright); lt.lineTo(left+(int)xtop, wl-(int)ytop); lt.lineTo(left+(int)xleft, wl-(int)yleft); } } }