# Set drawing style in one function

**URL:** <https://discourse.processing.org/t/set-drawing-style-in-one-function/13254>\
**Category:** Coding Questions\
**Created:** [August 8, 2019, 11:17am UTC](https://discourse.processing.org/t/set-drawing-style-in-one-function/13254 "2019-08-08T11:17:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![philipplehmann](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/philipplehmann/32/4111_2.png) [@philipplehmann](https://discourse.processing.org/u/philipplehmann)\
**Post date:** [August 8, 2019, 11:17am UTC](https://discourse.processing.org/t/set-drawing-style-in-one-function/13254/1 "2019-08-08T11:17:05Z")

</div>

Hey there

What do you guys think about the idea of a all-in-one function to set the drawing style.  
I created such a function as a shortcut and find it very handy.

- Is there already a similar behavior which i missed?
- Do you have ideas for improvement i.e performance wise?
- How would you name such a function?
- Which defaults would you set?

```auto
// Set the drawing style: fill, stroke, strokeWeight
function setStyle(fc, sc = null, sw = null) {
    fc ? fill(fc) : noFill();
    sc ? stroke(sc) : noStroke();
    sw ? strokeWeight(sw) : 0;
}

```

Thanks for your input.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [August 8, 2019, 1:39pm UTC](https://discourse.processing.org/t/set-drawing-style-in-one-function/13254/2 "2019-08-08T13:39:40Z")

</div>

Name setDrawingProperties  
setDrawProps

Default red / 111 / 1

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [August 10, 2019, 3:22am UTC](https://discourse.processing.org/t/set-drawing-style-in-one-function/13254/3 "2019-08-10T03:22:35Z")

</div>

Interesting. Would it also map the things that are controlled with textStyle?

[https://p5js.org/reference/#/p5/textStyle](https://p5js.org/reference/#/p5/textStyle)

Possibly related: In processing (not p5.js), PStyle is an object with almost all the possible style properties, and you interact with the pushStyle / popStyle stack (like with p5.js push pop) in terms of those objects.

[https://processing.github.io/processing-javadocs/core/processing/core/PStyle.html](https://processing.github.io/processing-javadocs/core/processing/core/PStyle.html)

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [August 10, 2019, 8:30am UTC](https://discourse.processing.org/t/set-drawing-style-in-one-function/13254/4 "2019-08-10T08:30:05Z")

</div>

a different idea ( here use JAVA ) could be to work with prepared THEMEs

```auto
void setup() {
  size(200, 200);
  set_Theme(1, 1, 0); // Theme 1, fill ON, stroke OFF
}

void draw() {
  background(bg);
  translate(width/2, height/2);
  circle(0, 0, 50);

  // temporary change color ( tc (text color) from theme OR any other color )
  fill(tc); // fill(color(200,0,200));
  text("sun", -25, 50);
  reset_Style(); //instead wrap it into pushStyle popStyle, or recall set_Theme(), just reset to theme
}

// _________________________________________________________________________________ RESET to THEME settings
void reset_Style() {
  strokeWeight(sw); // set the line width
  if ( bfill == 1) fill(fc); 
  else noFill();
  if ( bstroke == 1) stroke(sc); 
  else noStroke();
}

// ________________________________________________________________________________ THEME IDEA
color bg, fc, sc, tc; // color: background / fill / stroke / text /
int bfill=1, bstroke=1; // yes i want that global too
float sw=1, ts = 15; // stroke Weight / text size /
PFont myFont;

void set_Theme(int itheme, int b_fill, int b_stroke) { // Set the drawing style: fill, stroke, strokeWeight...
  boolean diagp = true;
  String name="";
  bfill = b_fill; // copy to global theme vars
  bstroke = b_stroke;
  //printArray(PFont.list());

  switch(itheme) {
  case 0: 
    name = "theme default";
    bg = color(200, 200, 0);
    fc = color(0, 200, 0);
    sc = color(0, 0, 200);
    tc = color(200, 0, 0);
    sw = 1.5;
    myFont = createFont("Georgia", 20);
    ts = 12;
    break;
  case 1: 
    name = "theme night sky";
    bg = color(0, 0, 80);
    fc = color(255, 255, 0);
    sc = color(127);
    tc = color(255);
    sw = 0.5;
    myFont = createFont("Yu Gothic Bold", 20);
    ts = 25;
    break;
  }

  reset_Style(); // set fill stroke strokeWeight

  // set the by theme used text
  textFont(myFont);
  textSize(ts);                    

  // prepared options for disable ...
  rectMode(CENTER);

  if ( diagp ) println(name+", with fill "+bfill+", with stroke "+bstroke);
}

/*
// https://discourse.processing.org/t/set-drawing-style-in-one-function/13254
 
 // Set the drawing style: fill, stroke, strokeWeight
 function setStyle(fc, sc = null, sw = null) {
 fc ? fill(fc) : noFill();
 sc ? stroke(sc) : noStroke();
 sw ? strokeWeight(sw) : 0;
 }
 
 */

```
