Using the stroke(); command

Is there any way of layering a stroke on top of another stroke? For instance, with this code:

size(100,100);
background(0);

stroke(255);
strokeWeight(7);
rectMode(CENTER);
fill(255,0,0);
rect(50,50,50,50);

Is there a way to put another stroke on top of the white stroke, without overriding it when I click on the rectangle?

Answers

  • As far as I know, you could either stack rect()s with noStroke() to make the same visual effect like this:

    void setup() {
      size(100, 100);
      rectMode(CENTER);
      noStroke();
      background(0);
    
      fill(255);
      rect(50, 50, 64, 64);
      fill(0, 0, 255);
      rect(50, 50, 58, 58);
      fill(255);
      rect(50, 50, 56, 56);
      fill(255, 0, 0);
      rect(50, 50, 50, 50);
    }
    

    Or you could continue using stroke() and stack rect()s. Personally I find the way I posted to be more intuitive but that is just preference.

Sign In or Register to comment.