Some tricks


Here are some examples illustrating a few additional features in Java

Java -> PS
Offscreen images and alpha
Writing images
Importing images
One comment about style

Java -> PS

PostScript programs are typically written by other programs, like dvips.

ToPS docs

ToPS.java, for download

Tiling.java, an example


Offscreen images and alpha

TilingInflation.java

Note:

  • BufferedImage represents an image. We can draw on it and then display it as we want.
  • JButtons can be represented with an image.

	images = new BufferedImage[number];
	outlines = new BufferedImage[number];
	for (int i = 0; i < number; i++) {
	    images[i] = new BufferedImage(2*width, 2*height, 
					  BufferedImage.TYPE_4BYTE_ABGR);
	    outlines[i] = new BufferedImage(2*width, 2*height, 
					  BufferedImage.TYPE_4BYTE_ABGR);
	    Graphics2D g = (Graphics2D) images[i].getGraphics();
	    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			       RenderingHints.VALUE_ANTIALIAS_ON);
	    for (int j = 0; j < rhombs[i].size(); j++) {
		((Rhomb) rhombs[i].elementAt(j)).paint(g, transform);
	    }

	    outlines[i] = new BufferedImage(2*width, 2*height, 
					  BufferedImage.TYPE_4BYTE_ABGR);
	    
	    g = (Graphics2D) outlines[i].getGraphics();
	    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			       RenderingHints.VALUE_ANTIALIAS_ON);
	    for (int j = 0; j < rhombs[i].size(); j++) {
		((Rhomb) rhombs[i].elementAt(j)).paintOutline(g, transform);
	    }

	}

In paintComponent


	    g.drawImage(images[currentNumber], 0, 0, this);
	    g.setComposite
		(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
					    alpha));
	    g.drawImage(images[currentNumber+1], 0, 0, this);

Writing images

ImageWriter.java


Importing images

ReadImage.java


One comment about style

My first applet