public void ColourGetGreen() { // homogeneous point translation Color c = new Color(0x12, 0x34, 0x56, 0x78); Assert.AreEqual <byte>(c.GetGreen(), 0x34); }
/** * @return color of the line. If color is not Set returns <code>java.awt.Color.black</code> */ public Color GetLineColor() { EscherOptRecord opt = (EscherOptRecord)GetEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); EscherSimpleProperty p1 = (EscherSimpleProperty)GetEscherProperty(opt, EscherProperties.LINESTYLE__COLOR); EscherSimpleProperty p2 = (EscherSimpleProperty)GetEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH); int p2val = p2 == null ? 0 : p2.PropertyValue; Color clr = null; if ((p2val & 0x8) != 0 || (p2val & 0x10) != 0) { int rgb = p1 == null ? 0 : p1.PropertyValue; if (rgb >= 0x8000000) { int idx = rgb % 0x8000000; if (Sheet != null) { ColorSchemeAtom ca = Sheet.GetColorScheme(); if (idx >= 0 && idx <= 7) { rgb = ca.GetColor(idx); } } } Color tmp = new Color(rgb, true); clr = new Color(tmp.GetBlue(), tmp.GetGreen(), tmp.GetRed()); } return(clr); }
/** * Color * * @param newcolor */ public Color(Color newcolor) { red = newcolor.GetRed(); green = newcolor.GetGreen(); blue = newcolor.GetBlue(); }
static public void Test_A2(Point point) { double x = point.GetX(); double y = point.GetY(); double z = point.GetZ(); Debug.Assert(Program.IsApprox(x, 636784.74, 0.01)); Debug.Assert(Program.IsApprox(y, 849106.66, 0.01)); Debug.Assert(Program.IsApprox(z, 426.71, 0.01)); double time = point.GetTime(); Debug.Assert(Program.IsApprox(time, 245382.13595, 0.00001)); Debug.Assert(point.GetIntensity() == 118); Debug.Assert(point.GetReturnNumber() == 1); Debug.Assert(point.GetNumberOfReturns() == 1); Classification classif = point.GetClassification(); Debug.Assert(classif.GetClassName() == "Unclassified"); Debug.Assert(!classif.IsKeyPoint()); Debug.Assert(!classif.IsSynthetic()); Debug.Assert(!classif.IsWithheld()); Color color = point.GetColor(); Debug.Assert(color.GetRed() == 112); Debug.Assert(color.GetGreen() == 97); Debug.Assert(color.GetBlue() == 114); }
/** * Write * * @param brightness * @param x * @param y * @param color */ public void Write(double brightness, int x, int y, Color color) { color.Scale(brightness); double max = color.FindMax(); if (max > 1.0f) { color.Scale(1.0f / max); } SetRed(x, y, color.GetRed() * 255); SetGreen(x, y, color.GetGreen() * 255); SetBlue(x, y, color.GetBlue() * 255); //System.out.println( "Set "+x+","+y+"="+Pixels[y * GetWidth() + x] ); }
/** * Write * * @param brightness * @param x * @param y * @param color */ public void Write(double brightness, int x, int y, Color color) { color.Scale(brightness); double max = color.FindMax(); if(max > 1.0f) { color.Scale(1.0f / max); } SetRed(x, y, color.GetRed() * 255); SetGreen(x, y, color.GetGreen() * 255); SetBlue(x, y, color.GetBlue() * 255); //System.out.println( "Set "+x+","+y+"="+Pixels[y * GetWidth() + x] ); }
/** * Scale * * @param factor * @param color */ public void Scale(double factor, Color color) { red *= factor * color.GetRed(); green *= factor * color.GetGreen(); blue *= factor * color.GetBlue(); }
/** * Combine * * @param color1 * @param color2 * @param color2factor * @param color3 * @param color4 * @param color5 */ public void Combine(Color color1, Color color2, double color2factor, Color color3, Color color4, Color color5) { red = color1.GetRed() + color2.GetRed() * color2factor + color3.GetRed() + color4.GetRed() + color5.GetRed(); green = color1.GetGreen() + color2.GetGreen() * color2factor + color3.GetGreen() + color4.GetGreen() + color5.GetGreen(); blue = color1.GetBlue() + color2.GetBlue() * color2factor + color3.GetBlue() + color4.GetBlue() + color5.GetBlue(); }
/** * Mix * * @param factor * @param color1 * @param color2 */ public void Mix(double factor, Color color1, Color color2) { red += factor * color1.GetRed() * color2.GetRed(); green += factor * color1.GetGreen() * color2.GetGreen(); blue += factor * color1.GetBlue() * color2.GetBlue(); }
/** * Background color */ public void SetBackgroundColor(Color color){ EscherOptRecord opt = (EscherOptRecord)Shape.GetEscherChild(shape.GetSpContainer(), EscherOptRecord.RECORD_ID); if (color == null) { Shape.SetEscherProperty(opt, EscherProperties.FILL__FILLBACKCOLOR, -1); } else { int rgb = new Color(color.GetBlue(), color.GetGreen(), color.GetRed(), 0).GetRGB(); Shape.SetEscherProperty(opt, EscherProperties.FILL__FILLBACKCOLOR, rgb); } }
public virtual Color Shade(Vector3D p, Vector3D n, Vector3D v, ArrayList lights, ArrayList objects, Color bgnd) { IEnumerator lightSources = lights.GetEnumerator(); float r = 0; float g = 0; float b = 0; while (lightSources.MoveNext()) { Light light = (Light)lightSources.Current; if (light.lightType == Light.AMBIENT) { r += ka * ir * light.ir; g += ka * ig * light.ig; b += ka * ib * light.ib; } else { Vector3D l; if (light.lightType == Light.POINT) { l = new Vector3D(light.lvec.x - p.x, light.lvec.y - p.y, light.lvec.z - p.z); l.Normalize(); } else { l = new Vector3D(-light.lvec.x, -light.lvec.y, -light.lvec.z); } // Check if the surface point is in shadow Vector3D poffset = new Vector3D(p.x + TINY * l.x, p.y + TINY * l.y, p.z + TINY * l.z); Ray shadowRay = new Ray(poffset, l); if (shadowRay.Trace(objects)) { break; } float lambert = Vector3D.Dot(n, l); if (lambert > 0) { if (kd > 0) { float diffuse = kd * lambert; r += diffuse * ir * light.ir; g += diffuse * ig * light.ig; b += diffuse * ib * light.ib; } if (ks > 0) { lambert *= 2; float spec = v.Dot(lambert * n.x - l.x, lambert * n.y - l.y, lambert * n.z - l.z); if (spec > 0) { spec = ks * ((float)Math.Pow((double)spec, (double)ns)); r += spec * light.ir; g += spec * light.ig; b += spec * light.ib; } } } } } // Compute illumination due to reflection if (kr > 0) { float t = v.Dot(n); if (t > 0) { t *= 2; Vector3D reflect = new Vector3D(t * n.x - v.x, t * n.y - v.y, t * n.z - v.z); Vector3D poffset = new Vector3D(p.x + TINY * reflect.x, p.y + TINY * reflect.y, p .z + TINY * reflect.z); Ray reflectedRay = new Ray(poffset, reflect); if (reflectedRay.Trace(objects)) { Color rcolor = reflectedRay.Shade(lights, objects, bgnd); r += kr * rcolor.GetRed(); g += kr * rcolor.GetGreen(); b += kr * rcolor.GetBlue(); } else { r += kr * bgnd.GetRed(); g += kr * bgnd.GetGreen(); b += kr * bgnd.GetBlue(); } } } // Add code for refraction here r = (r > 1f) ? 1f : r; g = (g > 1f) ? 1f : g; b = (b > 1f) ? 1f : b; return(new Color(r, g, b)); }
public virtual Color Shade(Vector3D p, Vector3D n, Vector3D v, ArrayList lights, ArrayList objects, Color bgnd) { IEnumerator lightSources = lights.GetEnumerator(); float r = 0; float g = 0; float b = 0; while (lightSources.MoveNext()) { Light light = (Light)lightSources.Current; if (light.lightType == Light.AMBIENT) { r += ka * ir * light.ir; g += ka * ig * light.ig; b += ka * ib * light.ib; } else { Vector3D l; if (light.lightType == Light.POINT) { l = new Vector3D(light.lvec.x - p.x, light.lvec.y - p.y, light.lvec.z - p.z); l.Normalize(); } else { l = new Vector3D(-light.lvec.x, -light.lvec.y, -light.lvec.z); } // Check if the surface point is in shadow Vector3D poffset = new Vector3D(p.x + TINY * l.x, p.y + TINY * l.y, p.z + TINY * l.z); Ray shadowRay = new Ray(poffset, l); if (shadowRay.Trace(objects)) { break; } float lambert = Vector3D.Dot(n, l); if (lambert > 0) { if (kd > 0) { float diffuse = kd * lambert; r += diffuse * ir * light.ir; g += diffuse * ig * light.ig; b += diffuse * ib * light.ib; } if (ks > 0) { lambert *= 2; float spec = v.Dot(lambert * n.x - l.x, lambert * n.y - l.y, lambert * n.z - l.z); if (spec > 0) { spec = ks * ((float)Math.Pow((double)spec, (double)ns)); r += spec * light.ir; g += spec * light.ig; b += spec * light.ib; } } } } } // Compute illumination due to reflection if (kr > 0) { float t = v.Dot(n); if (t > 0) { t *= 2; Vector3D reflect = new Vector3D(t * n.x - v.x, t * n.y - v.y, t * n.z - v.z); Vector3D poffset = new Vector3D(p.x + TINY * reflect.x, p.y + TINY * reflect.y, p .z + TINY * reflect.z); Ray reflectedRay = new Ray(poffset, reflect); if (reflectedRay.Trace(objects)) { Color rcolor = reflectedRay.Shade(lights, objects, bgnd); r += kr * rcolor.GetRed(); g += kr * rcolor.GetGreen(); b += kr * rcolor.GetBlue(); } else { r += kr * bgnd.GetRed(); g += kr * bgnd.GetGreen(); b += kr * bgnd.GetBlue(); } } } // Add code for refraction here r = (r > 1f) ? 1f : r; g = (g > 1f) ? 1f : g; b = (b > 1f) ? 1f : b; return new Color(r, g, b); }
public static string ColorToHTML(Color color) { string r = int.ToHexString(color.GetRed()); if (r.Length == 0) { r = "00"; } else { if (r.Length == 1) { r = "0" + r; } else { if (r.Length > 2) { throw new ArgumentException("invalid hex color for red" + r); } } } string g = int.ToHexString(color.GetGreen()); if (g.Length == 0) { g = "00"; } else { if (g.Length == 1) { g = "0" + g; } else { if (g.Length > 2) { throw new ArgumentException("invalid hex color for green" + g); } } } string b = int.ToHexString(color.GetBlue()); if (b.Length == 0) { b = "00"; } else { if (b.Length == 1) { b = "0" + b; } else { if (b.Length > 2) { throw new ArgumentException("invalid hex color for blue" + b); } } } return("#" + r + g + b); }
/** * @return color of the line. If color is not Set returns <code>java.awt.Color.black</code> */ public Color GetLineColor() { EscherOptRecord opt = (EscherOptRecord)GetEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); EscherSimpleProperty p1 = (EscherSimpleProperty)GetEscherProperty(opt, EscherProperties.LINESTYLE__COLOR); EscherSimpleProperty p2 = (EscherSimpleProperty)GetEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH); int p2val = p2 == null ? 0 : p2.PropertyValue; Color clr = null; if ((p2val & 0x8) != 0 || (p2val & 0x10) != 0) { int rgb = p1 == null ? 0 : p1.PropertyValue; if (rgb >= 0x8000000) { int idx = rgb % 0x8000000; if (Sheet != null) { ColorSchemeAtom ca = Sheet.GetColorScheme(); if (idx >= 0 && idx <= 7) rgb = ca.GetColor(idx); } } Color tmp = new Color(rgb, true); clr = new Color(tmp.GetBlue(), tmp.GetGreen(), tmp.GetRed()); } return clr; }