Example usage for com.google.gwt.canvas.dom.client Context2d fillRect

List of usage examples for com.google.gwt.canvas.dom.client Context2d fillRect

Introduction

In this page you can find the example usage for com.google.gwt.canvas.dom.client Context2d fillRect.

Prototype

public final native void fillRect(double x, double y, double w, double h) ;

Source Link

Document

Fills a rectangle.

Usage

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);
    context.save();//  w w  w. j av  a 2s.c  om
    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();
}

From source file:org.thole.hendrik.mandelbrot.gwt.client.impl.MandelBrotImpl.java

License:Open Source License

private final void paintMandel(final Context2d context) {
    final double inx = (xe - xa) / size_x;
    final double iny = (ye - ya) / size_y;

    ix = xa;/*from   ww w  . j  a  va  2 s. c o  m*/
    Scheduler.get().scheduleIncremental(new RepeatingCommand() {

        @Override
        public boolean execute() {
            if (ix <= xe) {
                for (iy = ya; iy <= ye; iy += iny) {
                    it = 0;
                    zr = 0;
                    zi = 0;
                    do {
                        zrq = zr * zr;
                        ziq = zi * zi;
                        it++;
                        zi = 2 * zr * zi + iy;
                        zr = zrq - ziq + ix;
                    } while (zrq + ziq < 4 && it < itmax);

                    context.setFillStyle(it2C(it));
                    context.fillRect((ix - xa) / inx, (iy - ya) / iny, 1, 1);
                }
                ix += inx;
                return true;
            }
            return false;
        }
    });

    //      for (ix = xa; ix <= xe; ix += inx) {
    //         for (iy = ya; iy <= ye; iy += iny) {
    //            it = 0;
    //            zr = 0;
    //            zi = 0;
    //            do {
    //               zrq = zr * zr;
    //               ziq = zi * zi;
    //               it++;
    //               zi = 2 * zr * zi + iy;
    //               zr = zrq - ziq + ix;
    //            } while (zrq + ziq < 4 && it < itmax);
    //
    //            context.setFillStyle(it2C(it));
    //            context.fillRect((ix-xa)/inx, (iy-ya)/iny, 1, 1);
    //         }
    //      }
}

From source file:uk.co.threeonefour.ifictionary.engine.client.pages.level9game.Level9GameActivity.java

License:Apache License

protected void startGame() {

    Context2d context = view.getCanvas().getContext2d();
    int w = context.getCanvas().getWidth();
    int h = context.getCanvas().getHeight();
    context.setFillStyle("#" + Colour.WHITE.toHexString());
    context.fillRect(0, 0, w, h);

    icyVm.startGame();//from   w  w w. ja v a  2s  .c  o m
    processVmOutput();

    view.getTextBox().setFocus(true);
}