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);
}
}









share|improve this question




























    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);
    }
    }









    share|improve this question


























      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);
      }
      }









      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 1:46









      Kevin Workman

      33.2k53968




      33.2k53968










      asked Nov 12 at 1:32









      Sebastien Karo

      182




      182
























          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);
          }





          share|improve this answer























          • 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











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          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

























          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);
          }





          share|improve this answer























          • 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















          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);
          }





          share|improve this answer























          • 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













          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);
          }





          share|improve this answer














          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);
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          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


















          • 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


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Guess what letter conforming each word

          Port of Spain

          Run scheduled task as local user group (not BUILTIN)