XOR Color Invert

Actionscript:
  1. var yellow:uint = 0xFFFF00;
  2.  
  3. // draws yellow circle
  4. with(graphics) beginFill(yellow), drawCircle(100,100,50);
  5.  
  6. // invert the color using XOR assignment
  7. // yellow becomes 0x0000FF
  8. yellow ^= 0xFFFFFF;
  9.  
  10. // draws blue  circle
  11. with(graphics) beginFill(yellow), drawCircle(200,100,50);

Just a fun use for XOR. You could also do it without XOR assignment:

Actionscript:
  1. with(graphics) beginFill(yellow ^ 0xFFFFFF), drawCircle(200,100,50);

Playing a little with bitwise operators is a good way to make sure you understand them. Try tweaking this trace statement:

Actionscript:
  1. trace((0x543210 ^ 0xFFFFFF).toString(16));

If you'd like to read about bitwise operators, I recommend wikipedia's article.

This entry was posted in Operators, one-liners and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*