import java.awt.*; import java.awt.image.*; public class HFDemo extends java.applet.Applet { HFEngine theEngine; int[] destination, pattern; Image pat; int w; int h; Image result; public void init() { Image pat = getImage(getDocumentBase(), "image/pattern.jpg"); MediaTracker mt = new MediaTracker(this); mt.addImage(pat,0); try { mt.waitForID(0); } catch (Exception error) { System.out.println("Error loading image!"); System.out.println(error); System.exit(10); } w = pat.getWidth(this); h = pat.getHeight(this); System.out.println(w+"x"+h); pattern = new int[w*h]; dump(pat, pattern, w, h); pat = null; destination = new int[h*(int)(w*(Math.ceil(h/(float)w)+1))]; } public void start() { if (theEngine == null) { theEngine = new HFEngine(destination, pattern, (int)(w*(Math.ceil(h/(float)w)+1)),w,h); theEngine.start(); } } public boolean mouseDown(Event evt, int x, int y) { repaint(); return true; } public void update(Graphics g) { paint(g); try { Thread.sleep(100); } catch (Exception e) {} } private void dump (Image img, int[] array, int w, int h) { System.out.println("Grabbing pixels"); PixelGrabber pg = new PixelGrabber(img.getSource(), 0, 0, w, h, array, 0, w); try { pg.grabPixels(0); } catch (Exception e) { System.out.println("Error retrieving image!"); } } public void stop() { if (theEngine != null) { theEngine.stop(); theEngine = null; } } public void paint(Graphics g) { System.out.println("Painting"); if (result != null) g.drawImage(result, 0, 0, this); else if (theEngine.yar != null) { result = createImage(theEngine.yar); g.drawImage(result, 0, 0, this); } } }