Ex 5 : Use of LookupTable
Draw some colored lines on a buffered image.
Display the image in a JFrame.
Use the LookupTable and LookupOp classes and the filter
method of BufferedImage to quickly change all the colors in the
BufferedImage.
Examples :
Tip: How to draw the lines
int xsize = 400;
int ysize = 400;
BufferedImage bimage = new BufferedImage(xsize,ysize,BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bimage.createGraphics();
g2d.setColor(new Color(0,0,0));
g2d.fill(new Rectangle2D.Double(0,0,xsize,ysize));
int cx1 = 100;
int cy1 = 200;
int cr1x = 40;
int cr1y = 80;
int cx2 = 300;
int cy2 = 200;
int cr2x = 50;
int cr2y = 130;
Random rnd = new Random();
for (int theta=0; theta<360; theta++)
{
int phi = theta + 180;
double xp1 = cx1 + cr1x * Math.cos(Math.toRadians(theta));
double yp1 = cy1 + cr1y * Math.sin(Math.toRadians(theta));
double xp2 = cx2 + cr2x * Math.cos(Math.toRadians(phi));
double yp2 = cy2 + cr2y * Math.sin(Math.toRadians(phi));
g2d.setColor(new Color(rnd.nextInt(255),rnd.nextInt(255),rnd.nextInt(255)));
g2d.drawLine((int)xp1, (int)yp1,
(int)xp2, (int)yp2);
}