I am trying to change the opacity of my strokes, but not sure how do it in HSB color mode. Or, if I switch to RGB mode how do I make the color change over time?
Here is my code: (Any help would be appreciated)
float rainbow=0;
int dir=1;
void setup() {
size(600, 600);
background(0);
colorMode(HSB, 255);
}
void draw() {
if ( rainbow < 255 && dir==1) {
rainbow++;
}
if ( rainbow > 0 && dir==-1) {
rainbow--;
}
if ( rainbow == 255) {
dir*= -1;
}
if ( rainbow == 0) {
dir*= -1;
}
stroke(rainbow, 255, 200);
line(mouseX,mouseY,width/2,height/2);
if (mousePressed){
stroke(rainbow, 255, 200);
line(mouseX,mouseY,0,mouseX);
}
if (mousePressed){
stroke(rainbow, 100, 200);
line(mouseX,mouseY,600,mouseX);
}
}
You can give the
stroke()
orfill()
functions a fourth parameter for the opacity. Here's an example:Note that you can also use RGB mode and modify the R, G, and B arguments over time as well. This is going to be a little more complicated than cycling through HSB values, but you can create any pattern you want. Here's an example: