When to use/not to use pushStyle()/popStyle()?

edited July 2015 in Questions about Code

Hello,

I am making a sketch that has various little circles rotating around my screen, each in a separate subroutine the circle color, stroke weight, stroke, fill, may all be different. Is it good practice (or even acceptable) to put pushStyle() and popStyle() at the start and end of each subroutine?

I.e. (psuedocode)

void yellowCircle(){
  pushStyle();
  fill(100,0,100);
  stroke(3);
  ellipse(10,10,10,10);
 popStyle();
}

void blueCircle(){
 pushStyle();
fill(0,0,255);
stroke(1);
strokeWeight(3);
ellipse(30,30,30,30);
popStyle();
}

or is doing that a 'roundabout' way of doing it the proper way (whatever that may be)?

Thanks for any tips on best practices with pushStyle()/popStyle()!

Answers

  • edited July 2015 Answer ✓

    It looks ok to me

    pushStyle makes sense basically when the propertys are set (elsewhere before pushStyle()) and used then (after popStyle) eg. in draw().

    When you set the properties anyway (as it looks like from what I see) you can skip pushStyle and popStyle

Sign In or Register to comment.