/** * Create a new fill for a radial gradient * * @param shape The shape being filled * @param trans The transform given for the shape in the SVG * @param gradient The gradient to apply across the shape */ public RadialGradientFill(Shape shape, Transform trans, Gradient gradient) { this.gradient = gradient; radius = gradient.getR(); float x = gradient.getX1(); float y = gradient.getY1(); float[] c = new float[] {x,y}; gradient.getTransform().transform(c, 0, c, 0, 1); trans.transform(c, 0, c, 0, 1); float[] rt = new float[] {x,y-radius}; gradient.getTransform().transform(rt, 0, rt, 0, 1); trans.transform(rt, 0, rt, 0, 1); centre = new Vector2f(c[0],c[1]); Vector2f dis = new Vector2f(rt[0],rt[1]); radius = dis.distance(centre); }
/** * @see org.newdawn.slick.svg.inkscape.ElementProcessor#process(org.newdawn.slick.svg.Loader, org.w3c.dom.Element, org.newdawn.slick.svg.Diagram, org.newdawn.slick.geom.Transform) */ public void process(Loader loader, Element element, Diagram diagram, Transform transform) throws ParsingException { String ref = element.getAttributeNS("http://www.w3.org/1999/xlink", "href"); String href = Util.getAsReference(ref); Figure referenced = diagram.getFigureByID(href); if (referenced == null) { throw new ParsingException(element, "Unable to locate referenced element: "+href); } Transform local = Util.getTransform(element); Transform trans = local.concatenate(referenced.getTransform()); NonGeometricData data = Util.getNonGeometricData(element); Shape shape = referenced.getShape().transform(trans); data.addAttribute(NonGeometricData.FILL, referenced.getData().getAttribute(NonGeometricData.FILL)); data.addAttribute(NonGeometricData.STROKE, referenced.getData().getAttribute(NonGeometricData.STROKE)); data.addAttribute(NonGeometricData.OPACITY, referenced.getData().getAttribute(NonGeometricData.OPACITY)); data.addAttribute(NonGeometricData.STROKE_WIDTH, referenced.getData().getAttribute(NonGeometricData.STROKE_WIDTH)); Figure figure = new Figure(referenced.getType(), shape, data, trans); diagram.addFigure(figure); }
/** * Create a new fill for gradients * * @param shape The shape being filled * @param trans The transform given for the shape * @param gradient The gradient to apply */ public LinearGradientFill(Shape shape, Transform trans, Gradient gradient) { this.gradient = gradient; float x = gradient.getX1(); float y = gradient.getY1(); float mx = gradient.getX2(); float my = gradient.getY2(); float h = my - y; float w = mx - x; float[] s = new float[] {x,y+(h/2)}; gradient.getTransform().transform(s, 0, s, 0, 1); trans.transform(s, 0, s, 0, 1); float[] e = new float[] {x+w,y+(h/2)}; gradient.getTransform().transform(e, 0, e, 0, 1); trans.transform(e, 0, e, 0, 1); start = new Vector2f(s[0],s[1]); end = new Vector2f(e[0],e[1]); line = new Line(start, end); }
public Ship(ShipFires fires) { this.speed = 0.5f; this.fires = fires; this.size = 0.4f; Transform t = Transform.createScaleTransform(size, size); this.shipPoly = AnimShip.getPolygon(); this.shipPoly = (Polygon) shipPoly.transform(t); this.shipRec = new Rectangle(0, 0, 170, 343); Shape p = shipRec.transform(t); this.shipRec = new Rectangle(p.getX(), p.getY(), p.getWidth(), p.getHeight()); this.shipPoly.setCenterX(shipRec.getCenterX()); this.shipPoly.setCenterY(shipRec.getCenterY()); this.anim_ship = new AnimShip(); }
public void set(String input, float scale, Color color) { children.clear(); Transform transform = Transform.createScaleTransform(scale, scale); float totalLength = (input.length() + (input.length()-1)*0.2f)*scale; float currentPos = -totalLength/2.0f + 0.5f*scale; for(char c : input.toCharArray()) { Shape glyph = GlyphManager.getGlyph(c); if(glyph != null) { Entity child = new Entity(glyph.transform(transform), color); child.setPosX(currentPos); addChild(child); } currentPos += 1.2*scale; } }
/** * @see org.newdawn.slick.svg.Loader#loadChildren(org.w3c.dom.Element, * org.newdawn.slick.geom.Transform) */ public void loadChildren(Element element, Transform t) throws ParsingException { NodeList list = element.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { if (list.item(i) instanceof Element) { loadElement((Element) list.item(i), t); } } }
/** * Load a single element into the diagram * * @param element * The element ot be loaded * @param t * The transform to apply to the loaded element from the parent * @throws ParsingException * Indicates a failure to parse the element */ private void loadElement(Element element, Transform t) throws ParsingException { for (int i = 0; i < processors.size(); i++) { ElementProcessor processor = (ElementProcessor) processors.get(i); if (processor.handles(element)) { processor.process(this, element, diagram, t); } } }
/** * @see BasicGame#init(GameContainer) */ public void init(GameContainer container) throws SlickException { a = new Rectangle(100,100,50,200); a = a.transform(Transform.createRotateTransform(0.1f,100,100)); b = new Rectangle(200,100,50,200); b = b.transform(Transform.createRotateTransform(-0.6f,100,100)); c = new Rectangle(300,100,50,200); c = c.transform(Transform.createRotateTransform(-0.2f,100,100)); morph = new MorphShape(a); morph.addShape(b); morph.addShape(c); container.setVSync(true); }
public void mouseWheelMoved(int change) { if (dynamic) { if (change < 0) { cut = cut.transform(Transform.createRotateTransform((float) Math.toRadians(10), cut.getCenterX(), cut.getCenterY())); } else { cut = cut.transform(Transform.createRotateTransform((float) Math.toRadians(-10), cut.getCenterX(), cut.getCenterY())); } } }
public static boolean checkCollision(CollisionObject obj1, Rectangle obj2, Float radianAngle) { Shape s1 = obj1.getShape(); Shape s2 = obj2.transform(Transform.createRotateTransform(radianAngle, obj2.getX(), obj2.getY())); if (s1.intersects(s2)) { return true; } else if (s1.contains(s2)) { return true; } else { return false; } }