How can i replace a pixel color?

edited June 2016 in Questions about Code

I have a sketch, in wich I overlay some shapes with opacity. Is there a way to tell the program to replace the pixel color generated from the overlay, with a new color?

Tagged:

Answers

  • edited June 2016

    How can I make the intersection area, red?

    Here's an example sketch:

    int x = 0;
    
    void setup () {
      size (400,400);
      smooth ();
    }
    
    void draw () {
      background (0);
      fill (255,200);
      ellipse (200,200, 100,100);
      ellipse (x,200, 100,100);
      x = x + 2;
      if (x == width+50) {
        x = -50;
      }
    }
    
  • edited June 2016

    But what i need is to:

    Make the intersection of two objects, an X color, and the intersection of three objects, a Y color.

    Here's another example sketch:

    int x = 0;
    int y = 50;
    
    void setup () {
      size (400,400);
      smooth ();
    }
    
    void draw () {
      background (0);
      fill (255,200);
      ellipse (200,200, 100,100);
      ellipse (x,200, 100,100);
      ellipse (200, y, 50,50);
    
      x = x + 2;
      if (x == width+50) {
        x = -50;
      }
    
      y = y + 2;
      if (y == 350) {
        y = 50;
      }
    }
    
  • Answer ✓

    There's no automatic way to do this in Processing that I can think of. You could possibly be very clever with color choice and alpha to get the desired results. . but you could use arc() to draw just the intersection part! Look at OPEN!

    https://processing.org/reference/arc_.html

Sign In or Register to comment.