001 /** 002 * @author Václav Mikolášek 003 * nicklaus@students.zcu.cz 004 */ 005 006 package animace; 007 008 import java.awt.*; 009 import java.awt.image.*; 010 import java.io.*; 011 import javax.imageio.*; 012 013 /** 014 * Třída ImageSource, zajišťuje, že použité obrázky budou v obou testech shodné - 015 * pro zajištěni jednotného přístupu a objektivity testováni. 016 */ 017 public class ImageSource { 018 public static BufferedImage square1(Color c1,Color c2) { 019 BufferedImage bim = new BufferedImage(5000,5000,BufferedImage.TYPE_BYTE_INDEXED); 020 Graphics g = bim.getGraphics(); 021 g.setClip(0,0,bim.getWidth(),bim.getHeight()); 022 drawSquares(g,c1,c2,0,0); 023 return bim; 024 } 025 026 /** 027 * Vrací obrázek kouřícího šálku (java logo), který je načten ze souboru. 028 */ 029 public static BufferedImage javaLogo() { 030 BufferedImage img = null; 031 try { 032 img = ImageIO.read(new File("images/javalogo.gif")); 033 } 034 catch (IOException e ) { 035 e.printStackTrace(); 036 } 037 return img; 038 } 039 040 /** 041 * Kreslí čtverečky (šachovnici) v barvách c1 a c2 od pozice x,y. 042 * @param x,y urcuji souřadnici horního levého rohu šachovnice, který se umísti do horního rohu (0,0) grafického objektu 043 * jde vlastně o posunutí šachovnice 044 */ 045 public static void drawSquares(Graphics g,Color c1, Color c2, int x, int y) { 046 int width = g.getClipBounds().width; 047 int height = g.getClipBounds().height; 048 g.setColor(c1); 049 g.fillRect(0,0,width, height); 050 051 g.setColor(c2); 052 053 int squareWidth = 30; 054 int squareHeight = 30; 055 for (int i = 0; i * squareWidth < width;i++) { 056 for (int j = 0;j * squareHeight < height;j++) { 057 if ((i+j) % 2 == 0) { 058 g.fillRect(i * squareWidth - x,j * squareHeight - y,squareWidth,squareHeight); 059 } 060 } 061 } 062 } 063 }