List of usage examples for com.google.gwt.canvas.dom.client Context2d rotate
public final native void rotate(double angle) ;
From source file:anagram.client.Logo.java
License:Apache License
void draw(Context2d context) { context.save();/*w ww . ja va2 s . co m*/ context.translate(this.pos.x, this.pos.y); context.rotate(rot); context.drawImage(image, 0, 0); context.restore(); }
From source file:com.google.gwt.maeglin89273.game.ashinyballonthecross.client.tutorial.component.BlueMark.java
@Override public void draw(Context2d context) { if (enabled) { context.save();//w w w . ja v a 2s .c o m context.translate(getX(), getY()); context.rotate(getAngle()); context.drawImage(spriteBlock.getSheetImage(), spriteBlock.getX(), spriteBlock.getY(), spriteBlock.getWidth(), spriteBlock.getHeight(), -getWidth() / 2, -getHeight() / 2, getWidth(), getHeight()); context.restore(); } }
From source file:com.philbeaudoin.quebec.shared.utils.ArcTransform.java
License:Apache License
@Override public void applies(double time, Context2d context) { Vector2d translation = getTranslation(time); double scaling = getScaling(time); context.translate(translation.x, translation.y); context.scale(scaling, scaling);// www. ja v a 2s .c o m context.rotate(getRotation(time)); }
From source file:com.philbeaudoin.quebec.shared.utils.ConstantTransform.java
License:Apache License
@Override public void applies(double time, Context2d context) { context.translate(translation.x, translation.y); context.scale(scaling, scaling);/*from w ww . j a v a 2 s. c o m*/ context.rotate(rotation); }
From source file:org.catrobat.html5player.client.Scene.java
License:Open Source License
/** * * @param imageElement//w w w.j a va 2 s . c o m * @param translateX * @param translateY * @param x * @param y * @param width * @param height * @param degrees * @param xSize * @param ySize */ public void drawImageElement(ImageElement imageElement, double translateX, double translateY, double x, double y, double width, double height, double degrees, double xSize, double ySize, double alpha) { long start = System.currentTimeMillis(); Context2d context = sceneCanvas.getContext2d(); context.save(); context.setGlobalAlpha(alpha); context.translate(translateX, translateY); context.rotate(Math.toRadians(degrees)); context.scale(xSize, ySize); context.drawImage(imageElement, x, y, width, height); //for testing - draws a rectangular around the sprite // context.strokeRect(x, y, width, height); // context.restore(); CatrobatDebug.debug("drawImageElement-execution took " + (System.currentTimeMillis() - start) + " ms"); }
From source file:org.catrobat.html5player.client.Scene.java
License:Open Source License
/** * * @param imageElement/*w w w . ja va 2 s . co m*/ * @param translateX * @param translateY * @param x * @param y * @param width * @param height * @param degrees * @param xSize * @param ySize */ public void drawImageElementBrightness(ImageElement imageElement, double translateX, double translateY, double x, double y, double width, double height, double degrees, double alpha, double brightness) throws JavaScriptException { Context2d context = sceneCanvas.getContext2d(); context.save(); context.setGlobalAlpha(alpha); context.translate(translateX, translateY); context.rotate(degrees * Math.PI / 180); try { Canvas adjustedImage = adjustImageBrightness(imageElement, brightness); context.drawImage(adjustedImage.getCanvasElement(), x, y, width, height); context.restore(); } catch (JavaScriptException exception) { context.restore(); throw exception; } }
From source file:org.catrobat.html5player.client.Sprite.java
License:Open Source License
/** * * @param relativeX/* www. j a va 2 s.c o m*/ * @param relativeY * @return */ public boolean processOnTouch(int relativeX, int relativeY) { //Create temp canvas with the current look only to determine click (alpha) Canvas temp = Canvas.createIfSupported(); temp.setWidth(Scene.get().getCanvas().getCoordinateSpaceWidth() + "px"); temp.setHeight(Scene.get().getCanvas().getCoordinateSpaceHeight() + "px"); temp.setCoordinateSpaceWidth(Scene.get().getCanvas().getCoordinateSpaceWidth()); temp.setCoordinateSpaceHeight(Scene.get().getCanvas().getCoordinateSpaceHeight()); LookData lookData = look.getLookData(); if (lookData == null) return false; double size = look.getSize(); double width = (double) lookData.getWidth() * size; double height = (double) lookData.getHeight() * size; double x = -width / 2; double y = -height / 2; Context2d context = temp.getContext2d(); context.translate(look.getXPosition(), look.getYPosition()); context.rotate((-look.getRotation()) * Math.PI / 180); context.drawImage((ImageElement) currentLook.getElement().cast(), x, y, width, height); if (context.getImageData(relativeX, relativeY, 1, 1).getAlphaAt(0, 0) == 0) { return false; } if (currentLook == null || !look.isVisible()) return false; double xPosition = look.getXPosition(); double yPosition = look.getYPosition(); double newSize = look.getSize(); LookData newLookData = look.getLookData(); double widthHalf = ((double) newLookData.getWidth() * newSize) / 2; double heightHalf = ((double) newLookData.getHeight() * newSize) / 2; if (xPosition + widthHalf > relativeX && xPosition - widthHalf < relativeX && yPosition + heightHalf > relativeY && yPosition - heightHalf < relativeY) { CatrobatDebug.info("Sprite " + this.name + " got touched"); return true; } return false; }
From source file:org.primordion.xholon.io.GridPanel.java
License:Open Source License
/** * Draw a regular polygon./*from www . j ava2s . c o m*/ * Example: <code> context.beginPath(); polygon(context,350,125,100,6,-Math.PI/2); context.fillStyle="rgba(51,128,255,0.75)"; context.fill(); context.stroke(); </code> * @param ctx A GWT Context2d object. * @param x X coordinate of the grid cell. * @param y Y coordinate of the grid cell. * @param radius * @param sides The number of sides in the polygon. This value must be >= 3. * @param startAngle Angle in radians. * @param anticlockwise Draw clockwise (false) or anticlockwise (true). * @see http://www.storminthecastle.com/2013/07/24/how-you-can-draw-regular-polygons-with-the-html5-canvas-api/ */ protected void drawPolygon(Context2d ctx, int x, int y, double radius, int sides, double startAngle, boolean anticlockwise) { if (sides < 3) return; double a = (Math.PI * 2) / sides; a = anticlockwise ? -a : a; ctx.save(); ctx.translate(x, y); ctx.rotate(startAngle); ctx.moveTo(radius, 0); for (int i = 1; i < sides; i++) { //double xcoor = radius * Math.cos(a * i); //double ycoor = radius * Math.sin(a * i); //System.out.println("i:" + i + " xcoor:" + xcoor + " ycoor:" + ycoor); //ctx.lineTo(xcoor, ycoor); ctx.lineTo(radius * Math.cos(a * i), radius * Math.sin(a * i)); } ctx.closePath(); ctx.restore(); }
From source file:org.teavm.samples.benchmark.gwt.BenchmarkStarter.java
License:Apache License
private void render() { Context2d context = canvas.getContext2d(); context.setFillStyle("white"); context.setStrokeStyle("grey"); context.fillRect(0, 0, 600, 600);//from w w w . j av a2 s . c o m context.save(); context.translate(0, 600); context.scale(1, -1); context.scale(100, 100); context.setLineWidth(0.01); for (Body body = scene.getWorld().getBodyList(); body != null; body = body.getNext()) { Vec2 center = body.getPosition(); context.save(); context.translate(center.x, center.y); context.rotate(body.getAngle()); for (Fixture fixture = body.getFixtureList(); fixture != null; fixture = fixture.getNext()) { Shape shape = fixture.getShape(); if (shape.getType() == ShapeType.CIRCLE) { CircleShape circle = (CircleShape) shape; context.beginPath(); context.arc(circle.m_p.x, circle.m_p.y, circle.getRadius(), 0, Math.PI * 2, true); context.closePath(); context.stroke(); } else if (shape.getType() == ShapeType.POLYGON) { PolygonShape poly = (PolygonShape) shape; Vec2[] vertices = poly.getVertices(); context.beginPath(); context.moveTo(vertices[0].x, vertices[0].y); for (int i = 1; i < poly.getVertexCount(); ++i) { context.lineTo(vertices[i].x, vertices[i].y); } context.closePath(); context.stroke(); } } context.restore(); } context.restore(); }