Change Opacity in HSB Colormode
up vote
3
down vote
favorite
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);
}
}
java colors processing opacity hsb
add a comment |
up vote
3
down vote
favorite
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);
}
}
java colors processing opacity hsb
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
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);
}
}
java colors processing opacity hsb
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);
}
}
java colors processing opacity hsb
java colors processing opacity hsb
edited Nov 12 at 1:46
Kevin Workman
33.2k53968
33.2k53968
asked Nov 12 at 1:32
Sebastien Karo
182
182
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You can give the stroke()
or fill()
functions a fourth parameter for the opacity. Here's a simple example:
void setup(){
size(500, 500);
colorMode(HSB, 255);
background(255);
}
void draw(){
fill(0, 255, 200, 100);
ellipse(mouseX, mouseY, 20, 20);
}
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 a simple example:
float r = 0;
float g = 0;
float b = 0;
float deltaR = 1;
float deltaG = 2;
float deltaB = 4;
void setup(){
size(500, 500);
background(255);
}
void draw(){
r += deltaR;
g += deltaG;
b += deltaB;
if(r < 0 || r > 255){
deltaR *= -1;
r = constrain(r, 0, 255);
}
if(g < 0 || g > 255){
deltaG *= -1;
g = constrain(g, 0, 255);
}
if(b < 0 || b > 255){
deltaB *= -1;
b = constrain(b, 0, 255);
}
fill(r, g, b);
ellipse(mouseX, mouseY, 20, 20);
}
Can you explain how I could modify the RGB arguments over time?
– Sebastien Karo
Nov 12 at 1:55
@SebastienKaro Sure, see my edited answer.
– Kevin Workman
Nov 12 at 3:28
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You can give the stroke()
or fill()
functions a fourth parameter for the opacity. Here's a simple example:
void setup(){
size(500, 500);
colorMode(HSB, 255);
background(255);
}
void draw(){
fill(0, 255, 200, 100);
ellipse(mouseX, mouseY, 20, 20);
}
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 a simple example:
float r = 0;
float g = 0;
float b = 0;
float deltaR = 1;
float deltaG = 2;
float deltaB = 4;
void setup(){
size(500, 500);
background(255);
}
void draw(){
r += deltaR;
g += deltaG;
b += deltaB;
if(r < 0 || r > 255){
deltaR *= -1;
r = constrain(r, 0, 255);
}
if(g < 0 || g > 255){
deltaG *= -1;
g = constrain(g, 0, 255);
}
if(b < 0 || b > 255){
deltaB *= -1;
b = constrain(b, 0, 255);
}
fill(r, g, b);
ellipse(mouseX, mouseY, 20, 20);
}
Can you explain how I could modify the RGB arguments over time?
– Sebastien Karo
Nov 12 at 1:55
@SebastienKaro Sure, see my edited answer.
– Kevin Workman
Nov 12 at 3:28
add a comment |
up vote
0
down vote
accepted
You can give the stroke()
or fill()
functions a fourth parameter for the opacity. Here's a simple example:
void setup(){
size(500, 500);
colorMode(HSB, 255);
background(255);
}
void draw(){
fill(0, 255, 200, 100);
ellipse(mouseX, mouseY, 20, 20);
}
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 a simple example:
float r = 0;
float g = 0;
float b = 0;
float deltaR = 1;
float deltaG = 2;
float deltaB = 4;
void setup(){
size(500, 500);
background(255);
}
void draw(){
r += deltaR;
g += deltaG;
b += deltaB;
if(r < 0 || r > 255){
deltaR *= -1;
r = constrain(r, 0, 255);
}
if(g < 0 || g > 255){
deltaG *= -1;
g = constrain(g, 0, 255);
}
if(b < 0 || b > 255){
deltaB *= -1;
b = constrain(b, 0, 255);
}
fill(r, g, b);
ellipse(mouseX, mouseY, 20, 20);
}
Can you explain how I could modify the RGB arguments over time?
– Sebastien Karo
Nov 12 at 1:55
@SebastienKaro Sure, see my edited answer.
– Kevin Workman
Nov 12 at 3:28
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You can give the stroke()
or fill()
functions a fourth parameter for the opacity. Here's a simple example:
void setup(){
size(500, 500);
colorMode(HSB, 255);
background(255);
}
void draw(){
fill(0, 255, 200, 100);
ellipse(mouseX, mouseY, 20, 20);
}
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 a simple example:
float r = 0;
float g = 0;
float b = 0;
float deltaR = 1;
float deltaG = 2;
float deltaB = 4;
void setup(){
size(500, 500);
background(255);
}
void draw(){
r += deltaR;
g += deltaG;
b += deltaB;
if(r < 0 || r > 255){
deltaR *= -1;
r = constrain(r, 0, 255);
}
if(g < 0 || g > 255){
deltaG *= -1;
g = constrain(g, 0, 255);
}
if(b < 0 || b > 255){
deltaB *= -1;
b = constrain(b, 0, 255);
}
fill(r, g, b);
ellipse(mouseX, mouseY, 20, 20);
}
You can give the stroke()
or fill()
functions a fourth parameter for the opacity. Here's a simple example:
void setup(){
size(500, 500);
colorMode(HSB, 255);
background(255);
}
void draw(){
fill(0, 255, 200, 100);
ellipse(mouseX, mouseY, 20, 20);
}
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 a simple example:
float r = 0;
float g = 0;
float b = 0;
float deltaR = 1;
float deltaG = 2;
float deltaB = 4;
void setup(){
size(500, 500);
background(255);
}
void draw(){
r += deltaR;
g += deltaG;
b += deltaB;
if(r < 0 || r > 255){
deltaR *= -1;
r = constrain(r, 0, 255);
}
if(g < 0 || g > 255){
deltaG *= -1;
g = constrain(g, 0, 255);
}
if(b < 0 || b > 255){
deltaB *= -1;
b = constrain(b, 0, 255);
}
fill(r, g, b);
ellipse(mouseX, mouseY, 20, 20);
}
edited Nov 12 at 3:28
answered Nov 12 at 1:46
Kevin Workman
33.2k53968
33.2k53968
Can you explain how I could modify the RGB arguments over time?
– Sebastien Karo
Nov 12 at 1:55
@SebastienKaro Sure, see my edited answer.
– Kevin Workman
Nov 12 at 3:28
add a comment |
Can you explain how I could modify the RGB arguments over time?
– Sebastien Karo
Nov 12 at 1:55
@SebastienKaro Sure, see my edited answer.
– Kevin Workman
Nov 12 at 3:28
Can you explain how I could modify the RGB arguments over time?
– Sebastien Karo
Nov 12 at 1:55
Can you explain how I could modify the RGB arguments over time?
– Sebastien Karo
Nov 12 at 1:55
@SebastienKaro Sure, see my edited answer.
– Kevin Workman
Nov 12 at 3:28
@SebastienKaro Sure, see my edited answer.
– Kevin Workman
Nov 12 at 3:28
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254961%2fchange-opacity-in-hsb-colormode%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown