Easily color elements!

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

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”;

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

I like this very much

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

or for triangle

1 Like

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

/**
 * 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;
}
1 Like