We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello Processing Community, I have created a sketch , I want to fill gradients in this trapezoid, from side to side, how to use Processing to achieve it? waiting for your suggestions and trying my best for this... regards ...
color from = color (231,70,77,25);
color to = color (231,70,77,255);
//int j=20;
//int r=1;
boolean inc =false, dec =false;
void setup() {
size(400, 400);
}
void draw() {
background(-1);
ellipseMode(CENTER);
fill(125);
//rect(30, 50, 60, 20);
noStroke();
for (int i=1;i<5;i++) {
color interA=lerpColor(from, to, (float(i)/10));
fill(interA);
ellipseMode(CENTER);
// rect(i*15+15, 50, 60, 20);
quad( 100,300, 300,300, 350,100, 50,100 );
println(i);
}
}
Answers
Use 4x lerp() to fill the quad with lines of changing color
That sentence needs a bit of unpacking
for(i.....
x1=lerp(....
y1=lerp(....
x2
y2
stroke
line(...
For different approaches to gradient fills in a triangle, see:
You can also use a PShape (e.g. with
beginShape()
/endShape()
:It can also be done with a different gradient fill assigned for any vertex:
How this works is described in the beginShape() reference -- note the need to set P2D or P3D in
size()
:You may also be interested in this much more advanced tutorial on Processing gradients:
At the very end it also gets into one of the most advanced ways to do a gradient (not covered above) -- using PShader and a GLSL fragment shader.