Exemple #1
0
	/**
	 * Color
	 *
	 * @param newcolor
	 */
	public Color(Color newcolor)
	{

		red = newcolor.GetRed();
		green = newcolor.GetGreen();
		blue = newcolor.GetBlue();
	}
Exemple #2
0
 /**
  * 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] );
 }
Exemple #3
0
 /**
  * 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);
 }
Exemple #5
0
	/**
	 * Scale
	 *
	 * @param factor
	 * @param color
	 */
	public void Scale(double factor, Color color)
	{
		red *= factor * color.GetRed();
		green *= factor * color.GetGreen();
		blue *= factor * color.GetBlue();
	}
Exemple #6
0
	/**
	 * 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();
	}
Exemple #7
0
        /**
         * @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;
        }
Exemple #8
0
	/**
	 * 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();
	}
        public static string ColorToHTML(Color color)
        {
            string r = int.ToHexString(color.GetRed());

            if (r.IsEmpty())
            {
                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.IsEmpty())
            {
                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.IsEmpty())
            {
                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);
        }
Exemple #10
0
 /**
  * Scale
  *
  * @param factor
  * @param color
  */
 public void Scale(double factor, Color color)
 {
     red   *= factor * color.GetRed();
     green *= factor * color.GetGreen();
     blue  *= factor * color.GetBlue();
 }
Exemple #11
0
 /**
  * Color
  *
  * @param newcolor
  */
 public Color(Color newcolor)
 {
     red   = newcolor.GetRed();
     green = newcolor.GetGreen();
     blue  = newcolor.GetBlue();
 }
Exemple #12
0
 /**
  * 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();
 }
Exemple #13
0
 /**
  * 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();
 }