📄 intro.java
字号:
Rectangle2D b2 = shape.getBounds2D(); double xx = (b1.getX()+b1.getWidth()/2) - (b2.getX()+b2.getWidth()/2); double yy = (b1.getY()+b1.getHeight()/2) - (b2.getY()+b2.getHeight()/2); AffineTransform toCenterAT = new AffineTransform(); toCenterAT.translate(xx, yy); toCenterAT.concatenate(at); txShapes[i] = toCenterAT.createTransformedShape(shapes[i]); } // avoid over rotation if (Math.abs(rotate) <= numRev * 360) { rotate += rIncr; if ((type & SCX) != 0) { sx += sIncr; } else if ((type & SCY) != 0) { sy += sIncr; } else { sx += sIncr; sy += sIncr; } } } public void render(int w, int h, Graphics2D g2) { Composite saveAC = null; if ((type & AC) != 0 && sx > 0 && sx < 1) { saveAC = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) sx)); } GeneralPath path = null; if ((type & CLIP) != 0) { path = new GeneralPath(); } if (paint != null) { g2.setPaint(paint); } for (int i = 0; i < txShapes.length; i++) { if ((type & CLIP) != 0) { path.append(txShapes[i], false); } else { g2.fill(txShapes[i]); } } if ((type & CLIP) != 0) { g2.clip(path); } if (saveAC != null) { g2.setComposite(saveAC); } } public int getBegin() { return beginning; } public int getEnd() { return ending; } } // End TxE class /** * GradientPaint Effect. Burst, split, horizontal and * vertical gradient fill effects. */ static class GpE implements Part { static final int INC = 1; // increasing static final int DEC = 2; // decreasing static final int CNT = 4; // center static final int WID = 8; // width static final int WI = WID | INC; static final int WD = WID | DEC; static final int HEI = 16; // height static final int HI = HEI | INC; static final int HD = HEI | DEC; static final int SPL = 32 | CNT; // split static final int SIW = SPL | INC | WID; static final int SDW = SPL | DEC | WID; static final int SIH = SPL | INC | HEI; static final int SDH = SPL | DEC | HEI; static final int BUR = 64 | CNT; // burst static final int BURI = BUR | INC; static final int BURD = BUR | DEC; static final int NF = 128; // no fill private Color c1, c2; private int beginning, ending; private float incr, index; private Vector rect = new Vector(); private Vector grad = new Vector(); private int type; public GpE(int type, Color c1, Color c2, int beg, int end) { this.type = type; this.c1 = c1; this.c2 = c2; this.beginning = beg; this.ending = end; } public void reset(int w, int h) { incr = 1.0f / (ending - beginning); if ((type & CNT) != 0) { incr /= 2.3f; } if ((type & CNT) != 0 && (type & INC) != 0) { index = 0.5f; } else if ((type & DEC) != 0) { index = 1.0f; incr = -incr; } else { index = 0.0f; } index += incr; } public void step(int w, int h) { rect.clear(); grad.clear(); if ((type & WID) != 0) { float w2 = 0, x1 = 0, x2 = 0; if ((type & SPL) != 0) { w2 = w * 0.5f; x1 = w * (1.0f - index); x2 = w * index; } else { w2 = w * index; x1 = x2 = w2; } rect.addElement(new Rectangle2D.Float(0, 0, w2, h)); rect.addElement(new Rectangle2D.Float(w2, 0, w-w2, h)); grad.addElement(new GradientPaint(0,0,c1,x1,0,c2)); grad.addElement(new GradientPaint(x2,0,c2,w,0,c1)); } else if ((type & HEI) != 0) { float h2 = 0, y1 = 0, y2 = 0; if ((type & SPL) != 0) { h2 = h * 0.5f; y1 = h * (1.0f - index); y2 = h * index; } else { h2 = h * index; y1 = y2 = h2; } rect.addElement(new Rectangle2D.Float(0, 0, w, h2)); rect.addElement(new Rectangle2D.Float(0, h2, w, h-h2)); grad.addElement(new GradientPaint(0,0,c1,0,y1,c2)); grad.addElement(new GradientPaint(0,y2,c2,0,h,c1)); } else if ((type & BUR) != 0) { float w2 = w/2; float h2 = h/2; rect.addElement(new Rectangle2D.Float(0, 0, w2, h2)); rect.addElement(new Rectangle2D.Float(w2, 0, w2, h2)); rect.addElement(new Rectangle2D.Float(0, h2, w2, h2)); rect.addElement(new Rectangle2D.Float(w2, h2, w2, h2)); float x1 = w * (1.0f - index); float x2 = w * index; float y1 = h * (1.0f - index); float y2 = h * index; grad.addElement(new GradientPaint(0,0,c1,x1,y1,c2)); grad.addElement(new GradientPaint(w,0,c1,x2,y1,c2)); grad.addElement(new GradientPaint(0,h,c1,x1,y2,c2)); grad.addElement(new GradientPaint(w,h,c1,x2,y2,c2)); } else if ((type & NF) != 0) { float x = w * index; float y = h * index; grad.addElement(new GradientPaint(0,0,c1,0,y,c2)); } if ((type & INC) != 0 || (type & DEC) != 0) { index += incr; } } public void render(int w, int h, Graphics2D g2) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); for (int i = 0; i < grad.size(); i++) { g2.setPaint((GradientPaint) grad.get(i)); if ((type & NF) == 0) { g2.fill((Rectangle2D) rect.get(i)); } } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } public int getBegin() { return beginning; } public int getEnd() { return ending; } } // End GpE class /** * TexturePaint Effect. Expand and collapse a texture. */ static class TpE implements Part { static final int INC = 1; // increasing static final int DEC = 2; // decreasing static final int OVAL = 4; // oval static final int RECT = 8; // rectangle static final int HAF = 16; // half oval or rect size static final int OI = OVAL | INC; static final int OD = OVAL | DEC; static final int RI = RECT | INC; static final int RD = RECT | DEC; static final int NF = 32; // no fill private Paint p1, p2; private int beginning, ending; private float incr, index; private TexturePaint texture; private int type; private int size; private BufferedImage bimg; private Rectangle rect; public TpE(int type, Paint p1, Paint p2, int size, int beg, int end) { this.type = type; this.p1 = p1; this.p2 = p2; this.beginning = beg; this.ending = end; setTextureSize(size); } public void setTextureSize(int size) { this.size = size; bimg = new BufferedImage(size,size,BufferedImage.TYPE_INT_RGB); rect = new Rectangle(0,0,size,size); } public void reset(int w, int h) { incr = (float) (size) / (float) (ending - beginning); if ((type & HAF) != 0) { incr /= 2; } if ((type & DEC) != 0) { index = size; if ((type & HAF) != 0) { index /= 2; } incr = -incr; } else { index = 0.0f; } index += incr; } public void step(int w, int h) { Graphics2D g2 = bimg.createGraphics(); g2.setPaint(p1); g2.fillRect(0,0,size,size); g2.setPaint(p2); if ((type & OVAL) != 0) { g2.fill(new Ellipse2D.Float(0,0,index,index)); } else if ((type & RECT) != 0) { g2.fill(new Rectangle2D.Float(0,0,index,index)); } texture = new TexturePaint(bimg, rect); g2.dispose(); index += incr; } public void render(int w, int h, Graphics2D g2) { g2.setPaint(texture); if ((type & NF) == 0) { g2.fillRect(0, 0, w, h); } } public int getBegin() { return beginning; } public int getEnd() { return ending; } } // End TpE class /** * Close out effect. Close out the buffered image with different * geometry shapes. */ static class CoE implements Part { static final int WID = 1; static final int HEI = 2; static final int OVAL = 4; static final int RECT = 8; static final int RAND = 16; static final int ARC = 32; private int type; private int beginning, ending; private BufferedImage bimg; private Shape shape; private double zoom, extent; private double zIncr, eIncr; private boolean doRandom; public CoE(int type, int beg, int end) { this.type = type; this.beginning = beg; this.ending = end; zIncr = -(2.0 / (ending - beginning)); eIncr = 360.0 / (ending - beginning);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -