Loading...
Logo
Processing Forum
Hi, i'm trying to make an function that "mirror" a color;
(example, if user give)

I make this, but with some debug and visual verification, i verifyed that this is not best approach...

Copy code
Copy code
  1. private static Color mirrorColors(Color bkg, int whichWay) {
  2.         // TODO Auto-generated method stub
  3.         int rR = bkg.getRed();
  4.         int gG = bkg.getGreen();
  5.         int bB = bkg.getBlue();
  6.         int r, g, b;
  7.         switch (whichWay) {
  8.         case colors.MIRROR_SIMPLE:
  9.             r = rR>=127?rR-127:rR+127;
  10.             g = gG>=127?gG-127:gG+127;
  11.             b = bB>=127?bB-127:bB+127;
  12.             return new Color(r,g,b);
  13.         case colors.MIRROR_EXP:
  14.             r = (int) (rR>=127?rR-Math.pow(rR, 0.5):rR+Math.pow(rR, 0.5));
  15.             g = (int) (gG>=127?rR-Math.pow(gG, 0.5):gG+Math.pow(gG, 0.5));
  16.             b = (int) (bB>=127?rR-Math.pow(bB, 0.5):bB+Math.pow(bB, 0.5));
  17.             return new Color(r,g,b);
  18.         default:
  19.             r = rR>=127?rR-127:rR+127;
  20.             g = gG>=127?gG-127:gG+127;
  21.             b = bB>=127?bB-127:bB+127;
  22.             return new Color(r,g,b);
  23.         }   
  24.     }

Anyone can suggest other ways to mirroring a reference Color?

Thanks

Replies(6)

if you want to invert the color you can do:

Copy code
  1. color col     = color(255,0,0);
  2. color col_inv = col ^ 0x00FFFFFF ;
  3. fill(col);     rect(0, 0, 100, 50);
  4. fill(col_inv); rect(0,50, 100, 50);
reading this article
]these could be the same "mirror color operation"  ?

Copy code
  1. color col     = color(255,0,0);
  2. color col_inv =  ~ col;
==
Copy code
  1. color col     = color(255,0,0);
  2. color col_inv = col ^ 0x00FFFFFF ;
Thanks
Thanks thomas_diewald!

can I have acess to some bibliography about color filtering/transformation techniques like this?



processing reference, nice explanation of bitwise operators
http://processing.org/reference/ and cathegory: Bitwise Operators

general information about bitwise operators
http://en.wikipedia.org/wiki/Bitwise_operation

java source: Color.java
http://www.java2s.com/Open-Source/Java-Document/6.0-JDK-Core/AWT/java/awt/Color.java.htm


Thanks! :DD