Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 0.58 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to compare two colors
  2. Point1 has R1 G1 B1
  3. Point2 has R2 G2 B2
  4.        
  5. d=sqrt((r2-r1)^2+(g2-g1)^2+(b2-b1)^2)
  6.        
  7. p=d/sqrt((255)^2+(255)^2+(255)^2)
  8.        
  9. avghue = (color1.hue + color2.hue)/2
  10. distance = abs(color1.hue-avghue)
  11.        
  12. int diffRed   = Math.abs(c1.getRed()   - c2.getRed());
  13. int diffGreen = Math.abs(c1.getGreen() - c2.getGreen());
  14. int diffBlue  = Math.abs(c1.getBlue()  - c2.getBlue());
  15.        
  16. float pctDiffRed   = (float)diffRed   / 255;
  17. float pctDiffGreen = (float)diffGreen / 255;
  18. float pctDiffRed   = (float)diffBlue  / 255;
  19.        
  20. (pctDiffRed + pctDiffGreen + pctDiffBlue) / 3 * 100