U:\NetBeans\PokeBall\src\graphicslab04\MasterBall.java |
1 package graphicslab04; 2 3 import java.awt.Color; 4 import java.awt.Font; 5 import java.awt.Graphics; 6 import java.awt.Graphics2D; 7 import java.awt.font.FontRenderContext; 8 import java.awt.font.GlyphVector; 9 import java.awt.geom.AffineTransform; 10 import java.awt.geom.Area; 11 import java.awt.geom.Ellipse2D; 12 13 public class MasterBall extends PokeBall { 14 15 private static final Area dots; 16 private static final Area capitalM; 17 18 static { 19 Area smallCirc = new Area(new Ellipse2D.Double(75, -50, 100, 100)); 20 AffineTransform rotation = AffineTransform 21 .getRotateInstance(-Math.PI / 4, 125, 125); 22 23 dots = smallCirc.createTransformedArea(rotation); 24 dots.add(dots.createTransformedArea(AffineTransform 25 .getQuadrantRotateInstance(1, 125, 125))); 26 dots.intersect(PokeBall.topHalf); 27 28 Font f = new Font("Gill Sans MT Bold", Font.BOLD, 50); 29 GlyphVector gv = f.createGlyphVector( 30 new FontRenderContext(null, true, true), "M"); 31 Area m = new Area(gv.getGlyphOutline(0)); 32 m.transform(AffineTransform 33 .getTranslateInstance(125 - m.getBounds2D().getCenterX(), 34 60 - m.getBounds2D().getCenterY())); 35 capitalM = new Area(m); 36 } 37 38 private final Area myTopHalf; 39 private final Area myDots; 40 41 public MasterBall(int xp, int yp) { 42 super(xp, yp); 43 myTopHalf = new Area(PokeBall.topHalf); 44 myTopHalf.subtract(capitalM); 45 myTopHalf.transform(shift); 46 myDots = dots.createTransformedArea(shift); 47 } 48 49 @Override 50 protected void drawTopHalf(Graphics g) { 51 g.setColor(new Color(0x800080)); 52 ((Graphics2D) g).fill(myTopHalf); 53 g.setColor(new Color(0xc080c0)); 54 ((Graphics2D) g).fill(myDots); 55 } 56 } 57