List of usage examples for com.google.gwt.canvas.dom.client CanvasGradient addColorStop
public final native void addColorStop(double offset, String color) ;
From source file:com.lushprojects.circuitjs1.client.CircuitElm.java
License:Open Source License
void drawCoil(Graphics g, int hs, Point p1, Point p2, double v1, double v2) { double len = distance(p1, p2); g.context.save();/*from www . j a v a 2 s . co m*/ g.context.setLineWidth(3.0); g.context.transform(((double) (p2.x - p1.x)) / len, ((double) (p2.y - p1.y)) / len, -((double) (p2.y - p1.y)) / len, ((double) (p2.x - p1.x)) / len, p1.x, p1.y); CanvasGradient grad = g.context.createLinearGradient(0, 0, len, 0); grad.addColorStop(0, getVoltageColor(g, v1).getHexValue()); grad.addColorStop(1.0, getVoltageColor(g, v2).getHexValue()); g.context.setStrokeStyle(grad); g.context.setLineCap(LineCap.ROUND); if (len > 24) g.context.scale(1, hs / (len / 6)); else g.context.scale(1, hs > 0 ? 1 : -1); int loop; for (loop = 0; loop != 3; loop++) { g.context.beginPath(); double start = len * loop / 3; g.context.moveTo(start, 0); g.context.arc(len * (loop + .5) / 3, 0, len / 6, Math.PI, Math.PI * 2); g.context.lineTo(len * (loop + 1) / 3, 0); g.context.stroke(); } g.context.restore(); }
From source file:com.lushprojects.circuitjs1.client.element.passive.ResistorElm.java
License:Open Source License
public void draw(Graphics g) { // int segments = 16; int i;/*from w ww . ja va 2 s .co m*/ // int ox = 0; // int hs = sim.euroResistorCheckItem.getState() ? 6 : 8; int hs = 6; double v1 = volts[0]; double v2 = volts[1]; setBbox(point1, point2, hs); draw2Leads(g); setPowerColor(g, true); // double segf = 1./segments; double len = distance(lead1, lead2); g.context.save(); g.context.setLineWidth(3.0); g.context.setTransform(((double) (lead2.x - lead1.x)) / len, ((double) (lead2.y - lead1.y)) / len, -((double) (lead2.y - lead1.y)) / len, ((double) (lead2.x - lead1.x)) / len, lead1.x, lead1.y); CanvasGradient grad = g.context.createLinearGradient(0, 0, len, 0); grad.addColorStop(0, getVoltageColor(g, v1).getHexValue()); grad.addColorStop(1.0, getVoltageColor(g, v2).getHexValue()); g.context.setStrokeStyle(grad); if (!sim.gui.euroResistorCheckItem.getState()) { // // draw zigzag // for (i = 0; i != segments; i++) { // int nx = 0; // switch (i & 3) { // case 0: nx = 1; break; // case 2: nx = -1; break; // default: nx = 0; break; // } // double v = v1+(v2-v1)*i/segments; // setVoltageColor(g, v); // interpPoint(lead1, lead2, ps1, i*segf, hs*ox); // interpPoint(lead1, lead2, ps2, (i+1)*segf, hs*nx); // drawThickLine(g, ps1, ps2); // ox = nx; // } g.context.beginPath(); g.context.moveTo(0, 0); for (i = 0; i < 4; i++) { g.context.lineTo((1 + 4 * i) * len / 16, hs); g.context.lineTo((3 + 4 * i) * len / 16, -hs); } g.context.lineTo(len, 0); g.context.stroke(); } else { // draw rectangle // setVoltageColor(g, v1); // interpPoint2(lead1, lead2, ps1, ps2, 0, hs); // drawThickLine(g, ps1, ps2); // for (i = 0; i != segments; i++) { // double v = v1+(v2-v1)*i/segments; // setVoltageColor(g, v); // interpPoint2(lead1, lead2, ps1, ps2, i*segf, hs); // interpPoint2(lead1, lead2, ps3, ps4, (i+1)*segf, hs); // drawThickLine(g, ps1, ps3); // drawThickLine(g, ps2, ps4); // } // interpPoint2(lead1, lead2, ps1, ps2, 1, hs); // drawThickLine(g, ps1, ps2); g.context.strokeRect(0, -hs, len, 2.0 * hs); } g.context.restore(); if (sim.gui.showValuesCheckItem.getState()) { String s = getShortUnitText(resistance, ""); drawValues(g, s, hs); } doDots(g); drawPosts(g); }
From source file:com.lushprojects.circuitjs1.client.ResistorElm.java
License:Open Source License
void draw(Graphics g) { int segments = 16; int i;//from w w w.j a va2s . c o m int ox = 0; //int hs = sim.euroResistorCheckItem.getState() ? 6 : 8; int hs = 6; double v1 = volts[0]; double v2 = volts[1]; setBbox(point1, point2, hs); draw2Leads(g); setPowerColor(g, true); // double segf = 1./segments; double len = distance(lead1, lead2); g.context.save(); g.context.setLineWidth(3.0); g.context.transform(((double) (lead2.x - lead1.x)) / len, ((double) (lead2.y - lead1.y)) / len, -((double) (lead2.y - lead1.y)) / len, ((double) (lead2.x - lead1.x)) / len, lead1.x, lead1.y); CanvasGradient grad = g.context.createLinearGradient(0, 0, len, 0); grad.addColorStop(0, getVoltageColor(g, v1).getHexValue()); grad.addColorStop(1.0, getVoltageColor(g, v2).getHexValue()); g.context.setStrokeStyle(grad); if (!sim.euroResistorCheckItem.getState()) { g.context.beginPath(); g.context.moveTo(0, 0); for (i = 0; i < 4; i++) { g.context.lineTo((1 + 4 * i) * len / 16, hs); g.context.lineTo((3 + 4 * i) * len / 16, -hs); } g.context.lineTo(len, 0); g.context.stroke(); } else { g.context.strokeRect(0, -hs, len, 2.0 * hs); } g.context.restore(); if (sim.showValuesCheckItem.getState()) { String s = getShortUnitText(resistance, ""); drawValues(g, s, hs); } doDots(g); drawPosts(g); }
From source file:com.philbeaudoin.quebec.client.scene.Rectangle.java
License:Apache License
@Override public void drawUntransformed(double time, Context2d context) { CanvasGradient gradient = context.createLinearGradient(x0, y0, x0, y1); gradient.addColorStop(0, color0); gradient.addColorStop(1, color1);/*from w ww. ja v a 2 s . c om*/ context.setFillStyle(gradient); context.fillRect(x0, y0, w, h); if (strokeColor != null && strokeWidth > 0) { context.setStrokeStyle(strokeColor); context.setLineWidth(strokeWidth); context.strokeRect(ox0, oy0, ow, oh); } }
From source file:com.sencha.gxt.chart.client.draw.engine.Canvas2d.java
License:sencha.com license
protected CanvasGradient makeGradient(Gradient gradient, PreciseRectangle bbox) { // emulating http://www.w3.org/TR/SVG/pservers.html#LinearGradientElementGradientUnitsAttribute = objectBoundingBox double radAngle = Math.toRadians(gradient.getAngle()); double[] vector = { 0, 0, Math.cos(radAngle) * bbox.getHeight(), Math.sin(radAngle) * bbox.getWidth() }; @SuppressWarnings("unused") double temp = Math.max(Math.abs(vector[2]), Math.abs(vector[3])); if (vector[2] < 0) { vector[0] = -vector[2];//from w w w . j a va2 s. c o m vector[2] = 0; } if (vector[3] < 0) { vector[1] = -vector[3]; vector[3] = 0; } CanvasGradient g = getContext().createLinearGradient(bbox.getX() + vector[0], bbox.getY() + vector[1], bbox.getX() + vector[2], bbox.getY() + vector[3]); for (Stop s : gradient.getStops()) { g.addColorStop(((double) s.getOffset()) / 100.0, getColorString(s.getColor(), s.getOpacity())); } return g; }
From source file:forplay.html.HtmlGraphics.java
License:Apache License
@Override public Gradient createLinearGradient(float x0, float y0, float x1, float y1, int[] colors, float[] positions) { Asserts.checkArgument(colors.length == positions.length); CanvasGradient gradient = dummyCtx.createLinearGradient(x0, y0, x1, y1); for (int i = 0; i < colors.length; ++i) { gradient.addColorStop(positions[i], cssColorString(colors[i])); }/*w w w . ja va 2 s. co m*/ return new HtmlGradient(gradient); }
From source file:forplay.html.HtmlGraphics.java
License:Apache License
@Override public Gradient createRadialGradient(float x, float y, float r, int[] colors, float[] positions) { Asserts.checkArgument(colors.length == positions.length); CanvasGradient gradient = dummyCtx.createRadialGradient(x, y, r, x, y, r); for (int i = 0; i < colors.length; ++i) { gradient.addColorStop(positions[i], cssColorString(colors[i])); }// w w w . j av a 2 s . com return new HtmlGradient(gradient); }
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%)"); }/*w w w. ja va 2 s .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;/* ww w. ja v a 2s . co m*/ // " 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%);"); }/* w ww.j a v a 2 s . co m*/ hueContext2d.setFillStyle(hueGradient); hueContext2d.fillRect(0, 0, barWidth, canvasHeight); }