# Easily color elements!

**URL:** https://discourse.processing.org/t/easily-color-elements/41536
**Category:** Gallery
**Created:** [March 30, 2023, 7:09pm UTC](https://discourse.processing.org/t/easily-color-elements/41536 "2023-03-30T19:09:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Aryszin](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Aryszin](https://discourse.processing.org/u/Aryszin)
#### Post date: [March 30, 2023, 7:09pm UTC](https://discourse.processing.org/t/easily-color-elements/41536/1 "2023-03-30T19:09:59Z")

</div>

You have a giant Project and hate always typing the same code like;

```auto
fill(128);
noStroke();
rect(10,10,100,25);
fill(#FF0000);
text("Some stuff",20,30);
noFill();
stroke(0);
rect(20,20,80,5);
strokeWeight(15);
stroke(#00FFFF);
line(0,0,50,50);

```

Heres a small solutions! You can make a “style Method”;

```auto
void style(color fillcolor, color strokecolor, float thickness) {
   fill(fillcolor);
   stroke(strokecolor);
   if(thickness == 0) {
      noStroke();
   } else {
      stokeWeight(thickness);
   }
}

```

---

<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: [March 30, 2023, 9:17pm UTC](https://discourse.processing.org/t/easily-color-elements/41536/2 "2023-03-30T21:17:12Z")

</div>

I like this very much

You can also make a wrapper for line ()  
like lineHorizontal(x,y,length) or  
lineVertical

or for triangle

---

<div class="post-metadata">

### Author: ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)
#### Post date: [March 30, 2023, 10:18pm UTC](https://discourse.processing.org/t/easily-color-elements/41536/3 "2023-03-30T22:18:19Z")

</div>

I have used a similar approach, applied to creating `LINES`-type PShapes:

```auto
/**
 * Create a LINES PShape, ready for vertices (shape.vertex(x, y) calls).
 * 
 * @param strokeColor nullable (default = {@link RGB#PINK})
 * @param strokeCap nullable (default = <code>ROUND</code>)
 * @param strokeWeight nullable (default = <code>2</code>)
 * @return LINES PShape ready for vertex calls
 */
static final PShape prepareLinesPShape(@Nullable Integer strokeColor, @Nullable Integer strokeCap, @Nullable Integer strokeWeight) {
	if (strokeColor == null) {
		strokeColor = RGB.PINK;
	}
	if (strokeCap == null) {
		strokeCap = ROUND;
	}
	if (strokeWeight == null) {
		strokeWeight = 2;
	}
	PShape lines = new PShape();
	lines.setFamily(PShape.GEOMETRY);
	lines.setStrokeCap(strokeCap);
	lines.setStroke(true);
	lines.setStrokeWeight(strokeWeight);
	lines.setStroke(strokeColor);
	lines.beginShape(LINES);
	return lines;
}

```
