@Grab(group='com.jhlabs', module='filters', version='2.0.235') import java.io.* import java.awt.* import java.awt.geom.* import java.awt.image.* import javax.imageio.* import com.jhlabs.image.* // チェック柄の布の模様を生成する def img = new BufferedImage( 200, 200, BufferedImage.TYPE_INT_ARGB ) def rectsize = 20 Color color1 = new Color((int)0x588F27) Color color1l = color1.darker() Color color2 = new Color((int)0xBF372A) Color color2l = color2.darker() def gr = img.createGraphics() for(int ly=0;ly<img.getHeight();ly+=rectsize){ def cc=((int)ly/rectsize)%2==0?0:1 for(int lx=0;lx<img.getWidth();lx+=rectsize){ if( cc%2 == 0 ){ for(int py=0;py<=rectsize;py+=2){ gr.setColor(color1) gr.drawLine(lx, ly+py, lx+rectsize, ly+py) gr.setColor(color1l) gr.drawLine(lx, ly+py+1, lx+rectsize, ly+py+1) } } else { for(int px=0;px<=rectsize;px+=2){ gr.setColor(color2) gr.drawLine(lx+px, ly, lx+px, ly+rectsize) gr.setColor(color2l) gr.drawLine(lx+px+1, ly, lx+px+1, ly+rectsize) } } cc++ } } def sf = new SmearFilter() sf.setShape(SmearFilter.CROSSES) sf.setDensity(0.9f) sf.setDistance(7) sf.setScatter(0.8f) //sf.setAngle((float)30*ImageMath.PI/180) img = sf.filter(img, null) ImageIO.write(img, "png", new File("checkerfabric.png"))
出力画像
動作環境
groovy 1.8.6, JDK7 update4