List of usage examples for com.google.gwt.canvas.dom.client Context2d fillRect
public final native void fillRect(double x, double y, double w, double h) ;
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 o m 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:nl.mpi.tg.eg.experiment.client.view.ColourPickerCanvasView.java
License:Open Source License
private void sizeAndPaintCanvases(final int canvasHeight, final int canvasWidth, final int barWidth) { this.canvasHeight = canvasHeight; this.canvasWidth = canvasWidth; mainCanvas.setCoordinateSpaceHeight(canvasHeight); mainCanvas.setCoordinateSpaceWidth(canvasWidth); mainCanvas.setSize(canvasWidth + "px", canvasHeight + "px"); hueCanvas.setCoordinateSpaceHeight(canvasHeight); hueCanvas.setCoordinateSpaceWidth(barWidth); hueCanvas.setSize(barWidth + "px", canvasHeight + "px"); final Context2d hueContext2d = hueCanvas.getContext2d(); CanvasGradient hueGradient = hueContext2d.createLinearGradient(0, 0, 0, canvasHeight); for (double stop = 0; stop <= 10; stop += 0.005) { hueGradient.addColorStop(stop * 0.1f, "hsl(" + 36 * stop + ",100%,50%)"); }// ww w . ja v a2s . co m hueContext2d.setFillStyle(hueGradient); hueContext2d.fillRect(0, 0, barWidth, canvasHeight); }
From source file:nl.mpi.tg.eg.experiment.client.view.ColourPickerCanvasView.java
License:Open Source License
synchronized private void setHue(String colourCss) { currentHueCss = colourCss;/* w w w . j av a2 s . c om*/ // " Android clearRect / fillRect bug" ??? // GWT documentation: JavaScript interpreters are single-threaded, so while GWT silently accepts the synchronized keyword, it has no real effect. // So we are using a simple boolean which should be adequate most of the time. We could use a timer call back, but we want to keep this simple. // However the browser is probably only single threaded anyway. if (hueChangeInProgress) { return; } hueChangeInProgress = true; final Context2d mainContext2dA = mainCanvas.getContext2d(); CanvasGradient linearColour = mainContext2dA.createLinearGradient(0, 0, canvasWidth, 0); linearColour.addColorStop(1f, "white"); linearColour.addColorStop(0f, colourCss); mainContext2dA.setFillStyle(linearColour); mainContext2dA.fillRect(0, 0, canvasWidth, canvasHeight); // todo: remove the second context get if it proves unhelpful witht the samsung 4.2.2 issue final Context2d mainContext2dB = mainCanvas.getContext2d(); CanvasGradient linearGrey = mainContext2dB.createLinearGradient(0, 0, 0, canvasHeight); linearGrey.addColorStop(1f, "black"); linearGrey.addColorStop(0f, "rgba(0,0,0,0)"); mainContext2dB.setFillStyle(linearGrey); mainContext2dB.fillRect(0, 0, canvasWidth, canvasHeight); hueChangeInProgress = false; }
From source file:nl.ru.languageininteraction.synaesthesia.client.view.ColourPickerCanvasView.java
License:Open Source License
private void sizeAndPaintCanvases(final int canvasHeight, final int canvasWidth, final int barWidth) { this.canvasHeight = canvasHeight; this.canvasWidth = canvasWidth; mainCanvas.setCoordinateSpaceHeight(canvasHeight); mainCanvas.setCoordinateSpaceWidth(canvasWidth); mainCanvas.setSize(canvasWidth + "px", canvasHeight + "px"); hueCanvas.setCoordinateSpaceHeight(canvasHeight); hueCanvas.setCoordinateSpaceWidth(barWidth); hueCanvas.setSize(barWidth + "px", canvasHeight + "px"); final Context2d hueContext2d = hueCanvas.getContext2d(); CanvasGradient hueGradient = hueContext2d.createLinearGradient(0, 0, 0, canvasHeight); for (int stop = 0; stop <= 10; stop++) { hueGradient.addColorStop(stop * 0.1f, "hsl(" + 36 * stop + ",100%,50%);"); }/*from w w w.j ava 2 s. c o m*/ hueContext2d.setFillStyle(hueGradient); hueContext2d.fillRect(0, 0, barWidth, canvasHeight); }
From source file:nl.ru.languageininteraction.synaesthesia.client.view.ColourPickerCanvasView.java
License:Open Source License
synchronized private void setHue(String colourCss) { currentHueCss = colourCss;/*from ww w. j a va 2s . c om*/ // " Android clearRect / fillRect bug" ??? // GWT documentation: JavaScript interpreters are single-threaded, so while GWT silently accepts the synchronized keyword, it has no real effect. // So we are using a simple boolean which should be adequate most of the time. We could use a timer call back, but we want to keep this simple. // However the browser is probably only single threaded anyway. if (hueChangeInProgress) { return; } hueChangeInProgress = true; final Context2d mainContext2dA = mainCanvas.getContext2d(); CanvasGradient linearColour = mainContext2dA.createLinearGradient(0, 0, canvasWidth, 0); linearColour.addColorStop(1f, "white"); linearColour.addColorStop(0f, colourCss); mainContext2dA.setFillStyle(linearColour); mainContext2dA.fillRect(0, 0, canvasWidth, canvasHeight); // todo: remove the second context get if it proves unhelpful witht the samsung 4.2.2 issue final Context2d mainContext2dB = mainCanvas.getContext2d(); CanvasGradient linearGrey = mainContext2dB.createLinearGradient(0, 0, 0, canvasHeight); linearGrey.addColorStop(1f, "black"); linearGrey.addColorStop(0f, "rgba(0,0,0,0);"); mainContext2dB.setFillStyle(linearGrey); mainContext2dB.fillRect(0, 0, canvasWidth, canvasHeight); hueChangeInProgress = false; }
From source file:org.catrobat.html5player.client.Scene.java
License:Open Source License
/** * *//* w ww . j a v a 2 s . com*/ public void clearCanvas() { long start = System.currentTimeMillis(); Context2d context = sceneCanvas.getContext2d(); context.save(); context.setFillStyle(fillColor); context.fillRect(0, 0, this.sceneWidth, this.sceneHeight); context.restore(); CatrobatDebug.debug("clearCanvas-execution took " + (System.currentTimeMillis() - start) + " ms"); }
From source file:org.cruxframework.crux.widgets.client.colorpicker.HuePicker.java
License:Apache License
private void drawGradient() { Context2d ctx = canvas.getContext2d(); // draw gradient ctx.setFillStyle("#ffffff"); ctx.fillRect(0, 0, 26, 180); for (int y = 0; y <= 179; y++) { String hex = ColorUtils.hsl2hex(y * 2, 100, 100); ctx.setFillStyle("#" + hex); ctx.fillRect(3, y, 20, 1);//from www. j a v a 2 s.c om } // draw handle if (handleY >= 0) { ctx.setFillStyle("#000000"); ctx.beginPath(); ctx.moveTo(3, handleY); ctx.lineTo(0, handleY - 3); ctx.lineTo(0, handleY + 3); ctx.closePath(); ctx.fill(); ctx.moveTo(23, handleY); ctx.lineTo(26, handleY - 3); ctx.lineTo(26, handleY + 3); ctx.closePath(); ctx.fill(); } }
From source file:org.cruxframework.crux.widgets.client.colorpicker.SaturationLightnessPicker.java
License:Apache License
private void drawGradient(boolean drawHandle) { Context2d ctx = canvas.getContext2d(); // draw gradient for (int x = 0; x <= 179; x++) { CanvasGradient grad = ctx.createLinearGradient(x, 0, x, 179); int s = Math.round(x * 100 / 179); String hex = ColorUtils.hsl2hex(hue, s, 0); grad.addColorStop(0, "#" + hex); hex = ColorUtils.hsl2hex(hue, s, 100); grad.addColorStop(1, "#" + hex); ctx.setFillStyle(grad);// w w w.j ava 2s. c o m ctx.fillRect(x, 0, 1, 180); } // draw handle if (drawHandle) { ctx.beginPath(); ctx.arc(handleX, handleY, 3, 0, Math.PI * 2, false); ctx.closePath(); ctx.setFillStyle("#ffffff"); ctx.fill(); ctx.beginPath(); ctx.arc(handleX, handleY, 2, 0, Math.PI * 2, false); ctx.closePath(); ctx.setFillStyle("#000000"); ctx.fill(); } }
From source file:org.grailrtls.plunder.client.drawable.PassiveTiles.java
License:Open Source License
/** * Renders this objects tiles (if any) to the DrawableContext. * Since there are no images, uses drawing primitives to render * 2-d colored boxes.//from ww w . j ava 2 s.c o m */ @Override public void draw(Context2d context) { // FIXME: Proper solution for "out of date" data if (System.currentTimeMillis() - this.timestamp > 5000) { return; } context.save(); context.setFillStyle("rgba(40,40,230,0.5)"); for (Tile t : this.tiles) { float x1 = this.toCanvasX(t.x1); float x2 = this.toCanvasX(t.x2); float y1 = this.toCanvasY(t.y1); float y2 = this.toCanvasY(t.y2); context.fillRect(x1, y1, x2 - x1, y2 - y1); } context.restore(); }
From source file:org.rstudio.studio.client.workbench.views.vcs.diff.NavGutter.java
License:Open Source License
public void setData(CssColor background, ArrayList<CssColor> lines) { Canvas newCanvas = Canvas.createIfSupported(); newCanvas.setSize("100%", "100%"); newCanvas.setCoordinateSpaceWidth(10); newCanvas.setCoordinateSpaceHeight(lines.size()); Context2d ctx = newCanvas.getContext2d(); ctx.translate(0.5, 0.5);/*from w w w. jav a 2 s . com*/ ctx.setFillStyle(background.value()); ctx.fillRect(0, 0, 10, lines.size()); for (int i = 0; i < lines.size(); i++) { CssColor color = lines.get(i); if (color != null) { ctx.setFillStyle(color.value()); ctx.fillRect(0, i, 10, 1); } } container_.setWidget(newCanvas); }