protected void clearFrame(DrawContext dc) { Color cc = dc.getClearColor(); dc.getGL().glClearColor(cc.getRed(), cc.getGreen(), cc.getBlue(), cc.getAlpha()); dc.getGL().glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); }
public static Color makeColorDarker(Color color) { if (color == null) { String message = Logging.getMessage("nullValue.ColorIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } float[] hsbComponents = new float[3]; Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsbComponents); float hue = hsbComponents[0]; float saturation = hsbComponents[1]; float brightness = hsbComponents[2]; saturation *= 3f; brightness /= 3f; if (saturation > 1f) { saturation = 1f; } if (brightness < 0f) { brightness = 0f; } int rgbInt = Color.HSBtoRGB(hue, saturation, brightness); return(new Color(rgbInt)); }
/** * Returns the component-wise linear interpolation of <code>color1</code> and <code>color2</code>. Each of the RGBA * components in the colors are interpolated according to the function: <code>(1 - amount) * c1 + amount * * c2</code>, where c1 and c2 are components of <code>color1</code> and <code>color2</code>, respectively. The * interpolation factor <code>amount</code> defines the weight given to each value, and is clamped to the range [0, * 1]. * * @param amount the interpolation factor. * @param color1 the first color. * @param color2 the second color. * * @return this returns the linear interpolation of <code>color1</code> and <code>color2</code> if <amount> is * between 0 and 1, a color equivalent to color1 if <code>amount</code> is 0 or less, or a color equivalent * to <code>color2</code> if <code>amount</code> is 1 or more. * * @throws ArgumentException if either <code>color1</code> or <code>color2</code> are <code>null</code>. */ public static Color interpolateColor(double amount, Color color1, Color color2) { if (color1 == null || color2 == null) { String message = Logging.getMessage("nullValue.ColorIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } float t = (amount < 0 ? 0 : (amount > 1 ? 1 : (float)amount)); float r = color1.getRed() + t * (color2.getRed() - color1.getRed()); float g = color1.getGreen() + t * (color2.getGreen() - color1.getGreen()); float b = color1.getBlue() + t * (color2.getBlue() - color1.getBlue()); float a = color1.getAlpha() + t * (color2.getAlpha() - color1.getAlpha()); return(new Color(r / 255f, g / 255f, b / 255f, a / 255f)); }
public static Color computeContrastingColor(Color color) { if (color == null) { String message = Logging.getMessage("nullValue.ColorIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } float[] compArray = new float[4]; Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), compArray); int colorValue = compArray[2] < 0.5f ? 255 : 0; int alphaValue = color.getAlpha(); return(new Color(colorValue, colorValue, colorValue, alphaValue)); }
//protected void glMaterialPremult(GL2 gl, int face, int name, Color color) //{ // float[] compArray = new float[4]; // color.getRGBComponents(compArray); // compArray[0] = compArray[0] * compArray[3]; // compArray[1] = compArray[1] * compArray[3]; // compArray[2] = compArray[2] * compArray[3]; // gl.glMaterialfv(face, name, compArray, 0); //} //protected void glMaterialfvPremult(GL2 gl, int face, int name, Color color, float alpha) //{ // float[] compArray = new float[4]; // color.getRGBColorComponents(compArray); // compArray[0] = compArray[0] * alpha; // compArray[1] = compArray[1] * alpha; // compArray[2] = compArray[2] * alpha; // compArray[3] = alpha; // gl.glMaterialfv(face, name, compArray, 0); //} protected Color makeDarker(Color color) { if (color == null) { String msg = Logging.getMessage("nullValue.ColorIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } float factor = 0.3f; int r = color.getRed(); int g = color.getGreen(); int b = color.getBlue(); int a = color.getAlpha(); return(new Color( Math.Max(0, (int)(r * factor)), Math.Max(0, (int)(g * factor)), Math.Max(0, (int)(b * factor)), a)); }
public Color getColor(int index) { if (color == null) { Random r = new Random(); color = new Color(min.getRed() + r.Next((max.getRed() - min.getRed())), min.getGreen() + r.Next((max.getGreen() - min.getGreen())), min.getBlue() + r.Next((max.getBlue() - min.getBlue()))); } return(color); }
public Color getColor(int index) { return(new Color((start.getRed() + step.getRed() * index) % 256, (start.getGreen() + step.getGreen() * index) % 256, (start.getBlue() + step.getBlue() * index) % 256)); }
private string toCSS(Color c) { return("rgb(" + c.getRed() + "," + c.getGreen() + "," + c.getBlue() + ")"); }
/** * Detects the locations of the sector geometries in this list that intersect any of the points in a specified list * of screen points. * <p/> * Note: Prior to calling this method, {@link #beginRendering(gov.nasa.worldwind.render.DrawContext)} must be * called. * * @param dc the current draw context. * @param pickPoints the points to test. * * @return an array of picked objects that intersect one or more of the specified screen points. */ public List <PickedObject> pick(DrawContext dc, List <Point> pickPoints) { if (dc == null) { String message = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().severe(message); throw new IllegalStateException(message); } if (pickPoints == null || pickPoints.Count < 1) { return(null); } this.pickSupport.clearPickList(); this.pickSupport.beginPicking(dc); GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility. gl.glShadeModel(GL2.GL_FLAT); try { // render each sector in a unique color this.beginRendering(dc); foreach (SectorGeometry sector in this) { Color color = dc.getUniquePickColor(); gl.glColor3ub((byte)color.getRed(), (byte)color.getGreen(), (byte)color.getBlue()); sector.render(dc); // lat/lon/elevation not used in this case this.pickSupport.addPickableObject(color.getRGB(), sector, Position.ZERO, true); } // Determine the sectors underneath the pick points. Assemble a pick-points per sector map. // Several pick points might intersect the same sector. this.pickSectors.Clear(); foreach (Point pickPoint in pickPoints) { PickedObject pickedSector = this.pickSupport.getTopObject(dc, pickPoint); if (pickedSector == null || pickedSector.getObject() == null) { continue; } SectorGeometry sector = (SectorGeometry)pickedSector.getObject(); List <Point> sectorPickPoints; if (!this.pickSectors.ContainsKey(sector)) { sectorPickPoints = new List <Point>(); this.pickSectors.Add(sector, sectorPickPoints); } else { this.pickSectors.TryGetValue(sector, out sectorPickPoints); } sectorPickPoints.Add(pickPoint); } if (this.pickSectors.Count < 1) { return(null); } // Now have each sector determine the pick position for each intersecting pick point. this.beginSectorGeometryPicking(dc); List <PickedObject> pickedObjects = new List <PickedObject>(); foreach (KeyValuePair <SectorGeometry, List <Point> > sector in this.pickSectors) { List <Point> sectorPickPoints = sector.Value; PickedObject[] pos = sector.Key.pick(dc, sectorPickPoints); if (pos == null) { continue; } foreach (PickedObject po in pos) { if (po != null) { pickedObjects.Add(po); } } } return(pickedObjects); } finally { this.endSectorGeometryPicking(dc); this.endRendering(dc); gl.glShadeModel(GL2.GL_SMOOTH); // restore to default explicitly to avoid more expensive pushAttrib this.pickSupport.endPicking(dc); this.pickSupport.clearPickList(); } }
/** * Detects the locations of the sector geometries in this list that intersect a specified screen point. * <p/> * Note: Prior to calling this method, {@link #beginRendering(gov.nasa.worldwind.render.DrawContext)} must be * called. * * @param dc the current draw context. * @param pickPoint the screen point to test. */ public void pick(DrawContext dc, java.awt.Point pickPoint) { if (dc == null) { String message = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().severe(message); throw new IllegalStateException(message); } if (pickPoint == null) { return; } this.pickSupport.clearPickList(); this.pickSupport.beginPicking(dc); GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility. gl.glShadeModel(GL2.GL_FLAT); try { // render each sector in unique color this.beginRendering(dc); foreach (SectorGeometry sector in this) { Color color = dc.getUniquePickColor(); gl.glColor3ub((byte)color.getRed(), (byte)color.getGreen(), (byte)color.getBlue()); sector.render(dc); // lat/lon/elevation not used in this case this.pickSupport.addPickableObject(color.getRGB(), sector, Position.ZERO, true); } PickedObject pickedSector = this.pickSupport.getTopObject(dc, pickPoint); if (pickedSector == null || pickedSector.getObject() == null) { return; // no sector picked } this.beginSectorGeometryPicking(dc); SectorGeometry sector = (SectorGeometry)pickedSector.getObject(); sector.pick(dc, pickPoint); } finally { this.endSectorGeometryPicking(dc); this.endRendering(dc); gl.glShadeModel(GL2.GL_SMOOTH); // restore to default explicitly to avoid more expensive pushAttrib this.pickSupport.endPicking(dc); this.pickSupport.clearPickList(); } }
/** * Causes the SurfaceObject to draw itself in a unique pick color, and add itself as a pickable object to the * specified pickSupport. * * @param dc the current DrawContext. * @param pickSupport the PickSupport to add the SurfaceObject to. */ protected void pickOrderedRenderable(DrawContext dc, PickSupport pickSupport) { // Register a unique pick color with the PickSupport. We define the pickable object to be the caller specified // delegate owner, or this object if the delegate owner is null. We define the picked position to be the // terrain's picked position to maintain backwards compatibility with previous implementations of SurfaceObject. Color pickColor = dc.getUniquePickColor(); pickSupport.addPickableObject(this.createPickedObject(dc, pickColor)); // Draw an individual representation of this object in a unique pick color. This representation is created // during the preRender pass in makeOrderedPreRenderable(). GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility. gl.glColor3ub((byte)pickColor.getRed(), (byte)pickColor.getGreen(), (byte)pickColor.getBlue()); this.drawPickRepresentation(dc); }
public void setRGB(Color color) { red = color.getRed(); green = color.getGreen(); blue = color.getBlue(); }
public void setPixel(int x, int y, Color color) { /* Color is a triple (r,g,b) representing a color for the pixel. Sets pixel at (x,y) to the given color. */ unsafe { byte *pixels = (byte *)this.pixbuf.Pixels; byte *r = &pixels[x * bytesPerPixel + y * pixbuf.Rowstride + 0]; byte *g = &pixels[x * bytesPerPixel + y * pixbuf.Rowstride + 1]; byte *b = &pixels[x * bytesPerPixel + y * pixbuf.Rowstride + 2]; *r = (byte) color.getRed(); *g = (byte) color.getGreen(); *b = (byte) color.getBlue(); } }
public void clear(Color color) { unsafe { int rowstride = pixbuf.Rowstride; int width = pixbuf.Width; int height = pixbuf.Height; byte *line = (byte *) pixbuf.Pixels; int r = color.getRed(); int g = color.getGreen(); int b = color.getBlue(); for (int y = 0; y < height; y++){ for (int x = 0; x < width; x++){ byte *rgb = &line[x * bytesPerPixel]; *rgb++ = (byte) r; *rgb++ = (byte) g; *rgb++ = (byte) b; } line += rowstride; } } }