title: How to paint with alpha?
body: <p>I want to paint graphics onto a Canvas such that the colors are additive. For example, I want to produce this:<br>
  <img src="https://i.stack.imgur.com/4VzJr.gif" alt="Proper additive colors"></p>
  
  <p>But instead, I get this:<br>
  <img src="https://i.stack.imgur.com/HYxDH.jpg" alt="My results"></p>
  
  <p>Note that the half white, half black background is intentional, just to see how alpha interacts with both backgrounds. I will be happy to have this work with either background. Here is my code:</p>
  
  <pre><code>public class VennColorsActivity extends Activity {
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          class VennView extends View {
              public VennView(Context context) {
                  super(context);
              }
  
              @Override
              protected void onDraw(Canvas canvas) {
                  super.onDraw(canvas);
                  int alpha = 60, val = 255;
                  int ar = Color.argb(alpha, val, 0, 0);
                  int ag = Color.argb(alpha, 0, val, 0);
                  int ab = Color.argb(alpha, 0, 0, val);
                  float w = canvas.getWidth();
                  float h = canvas.getHeight();
                  float cx = w / 2f;
                  float cy = h / 2;
                  float r = w / 5;
                  float tx = (float) (r * Math.cos(30 * Math.PI / 180));
                  float ty = (float) (r * Math.sin(30 * Math.PI / 180));
                  float expand = 1.5f;
                  Paint paint = new Paint();
                  paint.setColor(Color.WHITE);
                  canvas.drawRect(new Rect(0, 0, (int) w, (int) (h / 2)), paint);
                  PorterDuff.Mode mode = android.graphics.PorterDuff.Mode.ADD;
                  paint = new Paint(Paint.ANTI_ALIAS_FLAG);
                  paint.setColorFilter(new PorterDuffColorFilter(ar, mode));
                  paint.setColor(ar);
                  canvas.drawCircle(cx, cy - r, expand * r, paint);
                  paint.setColorFilter(new PorterDuffColorFilter(ag, mode));
                  paint.setColor(ag);
                  canvas.drawCircle(cx - tx, cy + ty, expand * r, paint);
                  paint.setColorFilter(new PorterDuffColorFilter(ab, mode));
                  paint.setColor(ab);
                  canvas.drawCircle(cx + tx, cy + ty, expand * r, paint);
              }
          }
          this.setContentView(new VennView(this));
      }
  }
  </code></pre>
  
  <p>Can someone please help me understand how to paint with additive colors in Android graphics?</p>