List of usage examples for com.google.gwt.canvas.dom.client Context2d setStrokeStyle
public final void setStrokeStyle(String strokeStyleColor)
From source file:examples.geometry.containment.AbstractPolygonContainmentExample.java
License:Open Source License
@Override protected AbstractControllableShape createControllableShape1(final Canvas canvas) { return new AbstractControllableShape(canvas) { @Override/*from w w w . ja v a2s.c o m*/ public void createControlPoints() { // no control points => user cannot change it } @Override public Polygon createGeometry() { double w = canvas.getCoordinateSpaceWidth(), wg = w / 6, h = canvas.getCoordinateSpaceHeight(), hg = h / 6; return new Polygon(new Point[] { new Point(wg, hg), new Point(w - wg, h - hg), new Point(wg, h - hg), new Point(w - wg, hg) }); } @Override public void drawShape() { Context2d context2d = canvas.getContext2d(); Polygon polygon = createGeometry(); context2d.setStrokeStyle("black"); for (Line segment : polygon.getOutlineSegments()) { context2d.beginPath(); context2d.moveTo(segment.getX1(), segment.getY1()); context2d.lineTo(segment.getX2(), segment.getY2()); context2d.stroke(); } } }; }
From source file:examples.geometry.containment.PolygonCubicCurveContainment.java
License:Open Source License
@Override protected AbstractControllableShape createControllableShape2(final Canvas canvas) { return new AbstractControllableShape(canvas) { @Override/*from w ww. java2 s.c o m*/ public void createControlPoints() { addControlPoint(new Point(200, 100)); addControlPoint(new Point(190, 310)); addControlPoint(new Point(410, 90)); addControlPoint(new Point(400, 300)); } @Override public CubicCurve createGeometry() { return new CubicCurve(getControlPoints()); } @Override public void drawShape() { CubicCurve c = createGeometry(); Path path = c.toPath(); CanvasDrawer.strokePath(path, canvas.getContext2d()); // gc.drawPath(new org.eclipse.swt.graphics.Path(Display // .getCurrent(), Geometry2SWT.toSWTPathData(c.toPath()))); } @Override public void fillShape(CssColor color) { // int lineWidth = gc.getLineWidth(); // Color fg = gc.getForeground(); Context2d context2d = canvas.getContext2d(); FillStrokeStyle fillStyle = context2d.getFillStyle(); context2d.setLineWidth(3); context2d.setStrokeStyle(color.value()); // gc.setLineWidth(3); // gc.setForeground(gc.getBackground()); drawShape(); context2d.setLineWidth(1); context2d.setStrokeStyle(fillStyle); // gc.setForeground(fg); // gc.setLineWidth(lineWidth); } }; }
From source file:examples.geometry.containment.PolygonLineContainment.java
License:Open Source License
@Override protected AbstractControllableShape createControllableShape2(final Canvas canvas) { return new AbstractControllableShape(canvas) { @Override//from w w w .j a va2 s. c om public void createControlPoints() { addControlPoint(new Point(100, 100)); addControlPoint(new Point(300, 300)); } @Override public Line createGeometry() { Point[] points = getControlPoints(); return new Line(points[0], points[1]); } @Override public void drawShape() { Line line = createGeometry(); Context2d c = canvas.getContext2d(); c.beginPath(); c.moveTo(line.getX1(), line.getY1()); c.lineTo(line.getX2(), line.getY2()); c.closePath(); c.stroke(); } @Override public void fillShape(CssColor color) { Context2d context2d = canvas.getContext2d(); FillStrokeStyle style = context2d.getFillStyle(); context2d.setLineWidth(3); context2d.setStrokeStyle(color.value()); drawShape(); context2d.setLineWidth(1); // context2d.setStrokeStyle(CssColor.make(0, 0, 0).value()); context2d.setStrokeStyle(style); } }; }
From source file:examples.geometry.containment.PolygonPolylineContainment.java
License:Open Source License
@Override protected AbstractControllableShape createControllableShape2(final Canvas canvas) { return new AbstractControllableShape(canvas) { @Override/*from w w w.ja v a 2 s . c om*/ public void createControlPoints() { addControlPoint(new Point(100, 100)); addControlPoint(new Point(100, 300)); addControlPoint(new Point(300, 300)); addControlPoint(new Point(300, 100)); } @Override public Polyline createGeometry() { Point[] points = getControlPoints(); Polyline polyline = new Polyline(points); return polyline; } @Override public void drawShape() { Polyline polyline = createGeometry(); CanvasDrawer.strokePath(polyline.toPath(), canvas.getContext2d()); } @Override public void fillShape(CssColor color) { Context2d context2d = canvas.getContext2d(); FillStrokeStyle style = context2d.getStrokeStyle(); context2d.setLineWidth(3); context2d.setStrokeStyle(color.value()); drawShape(); context2d.setLineWidth(1); // context2d.setStrokeStyle(CssColor.make(0, 0, 0).value()); context2d.setStrokeStyle(style); } }; }
From source file:examples.geometry.demos.CubicCurveDeCasteljauExample.java
License:Open Source License
@Override protected ControllableShape[] createShapes(Canvas canvas, EventBus eventBus) { return new ControllableShape[] { new ControllableShape(canvas, eventBus) { {/*from w w w . j a v a2 s .c o m*/ /* * These are the control points used to construct the CubicCurve * later. */ addControlPoints(new Point(100, 200), new Point(200, 100), new Point(300, 300), new Point(400, 200)); } @Override public CubicCurve getShape() { /* * Constructs the CubicCurve of the defined control points. */ return new CubicCurve(getPoints()); } @Override public void onDraw(Canvas canvas) { Context2d context = canvas.getContext2d(); /* * Draws the CubicCurve and the de Casteljau construction for * the current parameter value. */ // Construct the CubicCurve from the defined control points. CubicCurve curve = getShape(); CanvasDrawer.strokePath(curve.toPath(), context); /* * Retrieve control points to compute the linear interpolations * of the de Casteljau algorithm. */ Point[] points = getPoints(); /* * Define the colors for the intermediate lines. We have three * stages and therefore three different colors for a cubic * Bezier curve. This is the case, because the de Casteljau * algorithm reduces the number of control points in each * iteration until it reaches the actual point on the curve. */ String[] colors = new String[] { "green", "blue", "red" }; for (int ci = 0; ci < colors.length; ci++) { for (int i = 0; i < 3 - ci; i++) { context.beginPath(); context.moveTo(points[i].x, points[i].y); context.lineTo(points[i + 1].x, points[i + 1].y); context.setStrokeStyle(colors[ci]); context.stroke(); context.closePath(); // interpolate point for the next iteration points[i] = new Line(points[i], points[i + 1]).get(parameterValue); // draw point context.beginPath(); context.arc(points[i].x, points[i].y, 2, 0, 180); context.setStrokeStyle("black"); context.stroke(); context.closePath(); } } } } }; }
From source file:examples.geometry.demos.RingOutlineExample.java
License:Open Source License
@Override protected ControllableShape[] createShapes(Canvas canvas, EventBus eventBus) { return new ControllableShape[] { new ControllableShape(canvas, eventBus) { {//www . ja v a 2 s .co m addControlPoints(new Point(100, 100), new Point(400, 100), new Point(400, 200)); addControlPoints(new Point(400, 100), new Point(400, 400), new Point(300, 400)); addControlPoints(new Point(400, 400), new Point(100, 400), new Point(100, 300)); addControlPoints(new Point(100, 400), new Point(100, 100), new Point(200, 100)); } @Override public Ring getShape() { Point[] cp = getPoints(); Polygon[] polygons = new Polygon[cp.length / 3]; for (int i = 0; i < polygons.length; i++) { polygons[i] = new Polygon(cp[3 * i], cp[3 * i + 1], cp[3 * i + 2]); } return new Ring(polygons); } @Override public void onDraw(Canvas canvas) { Context2d context = canvas.getContext2d(); Ring ring = getShape(); context.setStrokeStyle("black"); double lineWidth = context.getLineWidth(); context.setLineWidth(1); for (Polyline outline : ring.getOutlines()) { context.beginPath(); for (Line l : outline.getCurves()) { Point p1 = l.getP1(); Point p2 = l.getP2(); context.moveTo(p1.x, p1.y); context.lineTo(p2.x, p2.y); context.setLineWidth(lineWidth + 1); context.stroke(); } context.closePath(); } context.setLineWidth(lineWidth); } } }; }
From source file:examples.geometry.demos.TriangulationExample.java
License:Open Source License
@Override protected ControllableShape[] createShapes(Canvas canvas, EventBus eventBus) { return new ControllableShape[] { new ControllableShape(canvas, eventBus) { {//from ww w. j a v a 2s. co m addControlPoints(new Point(300 / 2, 100 / 2), new Point(100 / 2, 200 / 2), new Point(200 / 2, 300 / 2), new Point(100 / 2, 500 / 2), new Point(300 / 2, 400 / 2), new Point(500 / 2, 600 / 2), new Point(600 / 2, 300 / 2), new Point(500 / 2, 400 / 2), new Point(500 / 2, 200 / 2), new Point(300 / 2, 200 / 2)); } @Override public Polygon getShape() { Polygon p = new Polygon(getPoints()); return p; } @Override public void onDraw(Canvas canvas) { Context2d context = canvas.getContext2d(); Polygon p = getShape(); Polygon[] triangulation; try { triangulation = p.getTriangulation(); } catch (NonSimplePolygonException x) { triangulation = new Polygon[] { p }; } for (Polygon triangle : triangulation) { context.beginPath(); context.setStrokeStyle("red"); for (Line s : triangle.getOutlineSegments()) { Point p1 = s.getP1(); Point p2 = s.getP2(); context.moveTo(p1.x, p1.y); context.lineTo(p2.x, p2.y); context.stroke(); } context.closePath(); } double lineWidth = context.getLineWidth(); context.setLineWidth(lineWidth + 2); context.setStrokeStyle("black"); context.beginPath(); for (Line s : p.getOutlineSegments()) { Point p1 = s.getP1(); Point p2 = s.getP2(); context.moveTo(p1.x, p1.y); context.lineTo(p2.x, p2.y); context.stroke(); } context.closePath(); context.setLineWidth(lineWidth); } } }; }
From source file:gwtcog.examples.client.neural.neat.boxes.DisplayBoxesPanel.java
License:Apache License
public void paint() {//(Graphics g) { Context2d g = canvas.getContext2d(); NEATGenome genome = (NEATGenome) this.pop.getBestGenome(); Substrate substrate = SubstrateFactory.factorSandwichSubstrate(resolution, resolution); HyperNEATCODEC codec = new HyperNEATCODEC(); NEATNetwork phenotype = (NEATNetwork) codec.decode(this.pop, substrate, genome); TrialEvaluation trial = new TrialEvaluation(phenotype, this.testCase); IntPair actualPos = trial.query(resolution); // clear what was there before //g.setColor(Color.white); g.setFillStyle("white"); g.fillRect(0, 0, 400, 400);/*from w ww . j av a2s .c om*/ // int boxWidth = 400 / resolution; int boxHeight = 400 / resolution; double delta = 2.0 / resolution; int index = 0; for (int row = 0; row < resolution; row++) { double y = -1 + (row * delta); int boxY = row * boxHeight; for (int col = 0; col < resolution; col++) { double x = -1 + (col * delta); int boxX = col * boxWidth; if (this.testCase.getPixel(x, y) > 0) { //g.setColor(Color.blue); g.setFillStyle("blue"); g.fillRect(boxX, boxY, boxWidth, boxHeight); } else { double d = trial.getOutput().getData(index); int c = trial.normalize(d, 255); String hex = Integer.toHexString(c); if (hex.length() == 1) { hex = "0" + hex; } String color = "#ff" + hex + "ff"; g.setFillStyle(color); g.fillRect(boxX, boxY, boxWidth, boxHeight); g.setStrokeStyle("black"); g.strokeRect(boxX, boxY, boxWidth, boxHeight); g.strokeRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2); } index++; } } g.setFillStyle("red"); g.fillRect(actualPos.getX() * boxWidth, actualPos.getY() * boxHeight, boxWidth, boxHeight); }
From source file:org.cesiumjs.cs.scene.interaction.MarkerGroup.java
License:Apache License
public static BillboardOptions createBillboard(DrawInteractionOptions options) { Canvas canvas = Canvas.createIfSupported(); Context2d context = canvas.getContext2d(); context.setFillStyle(options.color.toCssColorString()); context.setStrokeStyle(options.outlineColor.toCssColorString()); context.setLineWidth(options.outlineWidth); context.translate(canvas.getCoordinateSpaceWidth() / 2, canvas.getCoordinateSpaceHeight() / 2); context.beginPath();// ww w . ja v a 2s . c o m context.arc(0, 0, options.pixelSize, 0, Math.PI * 2, true); context.closePath(); context.stroke(); context.fill(); BillboardOptions billboard = new BillboardOptions(); billboard.horizontalOrigin = HorizontalOrigin.CENTER(); billboard.verticalOrigin = VerticalOrigin.CENTER(); billboard.imageCanvas = canvas.getCanvasElement(); return billboard; }
From source file:org.openstreetmap.beboj.client.actions.mapmode.edit.DrawWay.java
License:GNU General Public License
@Override public void paint(Graphics2D g, MapView mv, Bounds bbox) { Context2d c = ((CanvasGraphics2D) g).getContext2d(); // don't draw line if we don't know where to if (lastMousePos == null) return;/*w w w.j a v a2 s. c om*/ // don't draw line if mouse is outside window if (!Main.map.mapView.view.getBounds().contains(lastMousePos)) return; Point p1 = mv.getPoint(lastNode); Point p2 = lastMousePos; c.setStrokeStyle("#ffff00"); c.beginPath(); c.moveTo(p1.x, p1.y); c.lineTo(p2.x, p2.y); c.stroke(); }