5 Replies Latest reply on Oct 12, 2015 9:43 PM by boo radley 2013

    Variable amount of hue shift

    boo radley 2013 Level 3

      Hi

       

      I've assembled a small script which shifts the hue upwards/positive by 15%. I am trying to find a way to make the script shift the hue by a random amount- so anywhere between {0 and 15%}, but also anywhere between {0 and -15%}. This would be a random shift anywhere within those values.

       

      So in other words, when the script is executed, it will shift the hue anywhere between {0% and 15%} *OR* from {0% and -15%}.

       

      I hope this makes sense. If not, I can clarify further. Here's the current code I put together. Each time you run it, pay attention to the color picker panel (PhotoshopCC and up)- when you run this script, the hue slider will move up by 15%. Again- I want that slider to move up *or* down by a random amount between -15% and +15%. Can it be done?

       

      var foreColor = new SolidColor;

      foreColorH=app.foregroundColor.hsb.hue;

      foreColorS=app.foregroundColor.hsb.saturation;

      foreColorB=app.foregroundColor.hsb.brightness;

      foreColor.hsb.hue=foreColorH+15;

      foreColor.hsb.saturation=foreColorS+0;

      foreColor.hsb.brightness=foreColorB+0;

      app.foregroundColor = foreColor;

       

       

       

       

       

      
      
      
        • 1. Re: Variable amount of hue shift
          c.pfaffenbichler Level 9

          Hue is not expressed in percent but degree.

           

          It seems the values above 360˚ are automatically changed, so you could give this a try.

          var foreColor = new SolidColor;

          foreColorH=app.foregroundColor.hsb.hue;

          foreColorS=app.foregroundColor.hsb.saturation;

          foreColorB=app.foregroundColor.hsb.brightness;

          var theNewValue = foreColorH + 15 - Math.random() * 30;

          foreColor.hsb.hue=theNewValue;

          foreColor.hsb.saturation=foreColorS+0;

          foreColor.hsb.brightness=foreColorB+0;

          app.foregroundColor = foreColor;

          • 2. Re: Variable amount of hue shift
            boo radley 2013 Level 3

            thanks, c - that really works well. I'm trying to emulate the "hue jitter" in the brushes panel under color dynamics. Same for brightness, and also saturation. So whenever the script it executed, the hue jitters upwards or downwards just a little bit- this does the trick. The only catch is that when it shifts up or down, then the next time the code is run, it shifts again but not from the original color, but from the new color that was just shifted - I hope that makes sense. So in other words the "hue jitter" in the brushes panel keeps the original color in memory (ff0000, for example), and every time you draw a brush stroke, it jitters up or down from ff0000. This script however, jitters from ff0000 the first time you run the script, and now the color has shifted to, say, ff0202. Now, when you run the script a second time, it shifts the color  from ff0202 instead of the original ff0000. This causes the jitter to eventually stray further away from ff0000 and shift through the entire color spectrum if you run it enough times. Is there a way to have it always shift from ff0000 no matter how many times you run the script?

            • 3. Re: Variable amount of hue shift
              c.pfaffenbichler Level 9

              One could store the information (the Hue value in this case) in the metadata or as a txt file and check that.

               

              Problem is how to decide when to start wholly anew (based on the current Foreground Color).

              One could use

              ScriptUI.environment.keyboardState.shiftKey

              to have one Script perform two different tasks.

              Edit: Sorry, was a bit unclear, that property can be used to have a Script perform one task if the shift-key is pressed when it is started and another if the shift-key is not pressed …

              • 4. Re: Variable amount of hue shift
                c.pfaffenbichler Level 9

                I guess a more "basic" approach could be to save a Solid Color Layer (with a black Layer Mask) to store the original Color.

                Deleting that Layer could then force the Script to start with the Foreground Color again.

                • 5. Re: Variable amount of hue shift
                  boo radley 2013 Level 3

                  managed to get it working - the very first step was to copy the foreground color to the clipboard by pressing ALT+F12 (this works in CC2014, I don't know about other versions). Next, the "jitter" code that you supplied is executed- and the color is shifted up or down by 15 degrees.  Third, I included a "wait until left mouse button has been pressed and released"- this allows the user to paint a single brush stroke using the shifted color and then it waits until the left button is released after painting that stroke. Finally,  the color which is in the clipboard (from step 1) is restored as the new foreground color (I used "Paul's External Library"- 'psClipboard64.dll' to cover that part). And now we're back to square one. Run the script a second time, and all of the above is repeated, except that your jitter code should shift the color to a different random color. So as a result, this becomes a successful reproduction of "hue jitter" in the brush panel.  I've already worked in the saturation and brightness to it as well. I would love to share what I have but the only thing is that I'm using other 3rd party software along with the code to get it to work. So it's not all .jsx code and posting any other type of language here probably won't help anyone.

                   

                  What I'm getting at is, thanks for the help - it works