4 Replies Latest reply on Dec 22, 2008 12:52 PM by [Jongware]

    Color object by pagenumber

      Hi,

      I'm currently working in a yearbook and want to use a color-effect, but I don't know how to do it. The idea is to create a rainbow-effect (changing colors along the page sides). Does anyone knows/has a script or tutorial I can use for this? I will have about 300 pages in the book.

      Thanks in advance...

      Greetings, Schelpie
        • 1. Re: Color object by pagenumber
          [Jongware] Most Valuable Participant
          For converting a number from a known range into a color value, and then especially a rainbow, you could use the HSB color model.

          Let me think ... (making it up as I type):

          Fill in the first page to be colored; the last page is calculated automatically. The routine draws a tiny rectangle on each page in the correct color, and adds it as a swatch as well. You probably want to convert them to CMYK before sending it off to print (perhaps with another script ;-) ). Adjust the calculation in HsbToRgb to get different start and ending points and hues.

          var firstColoredPage = 10;
          

          var lastColoredPage = app.activeDocument.pages.length;

          var range = lastColoredPage - firstColoredPage;

          var colorForPage = new Array(0,0,0);

          for (i=0; i< range; i++)

          {

          HsbToRgb (i/range,1.0,1.0, colorForPage);

          newrect = app.activeDocument.pages[firstColoredPage+i].rectangles.add({geometricBounds:[0,0,10,10]});

          color = app.activeDocument.colors.add({name:"page"+(firstColoredPage+i), space:ColorSpace.RGB, colorValue:[colorForPage[0],colorForPage[1],colorForPage[2]]});

          newrect.fillColor = color;

          }

          // from koders.com (modified):

          function HsbToRgb(hue, saturation, brightness, dest)

          {

          var red   = 0;

          var green = 0;

          var blue  = 0;

             if (saturation == 0) {

                red = parseInt(brightness * 255.0 + 0.5);

              green = red;

              blue = red;

          }

          else {

                var h = (hue - Math.floor(hue)) * 6.0;

                var f = h - Math.floor(h);

                var p = brightness * (1.0 - saturation);

                var q = brightness * (1.0 - saturation * f);

                var t = brightness * (1.0 - (saturation * (1.0 - f)));

                switch (parseInt(h)) {

                   case 0:

                      red   = (brightness * 255.0 + 0.5);

                      green = (t * 255.0 + 0.5);

                      blue  = (p * 255.0 + 0.5);

                      break;

                   case 1:

                      red   = (q * 255.0 + 0.5);

                      green = (brightness * 255.0 + 0.5);

                      blue  = (p * 255.0 + 0.5);

                      break;

                   case 2:

                      red   = (p * 255.0 + 0.5);

                      green = (brightness * 255.0 + 0.5);

                      blue  = (t * 255.0 + 0.5);

                      break;

                   case 3:

                      red   = (p * 255.0 + 0.5);

                      green = (q * 255.0 + 0.5);

                      blue  = (brightness * 255.0 + 0.5);

                      break;

                   case 4:

                      red   = (t * 255.0 + 0.5);

                      green = (p * 255.0 + 0.5);

                      blue  = (brightness * 255.0 + 0.5);

                      break;

                    case 5:

                      red   = (brightness * 255.0 + 0.5);

                      green = (p * 255.0 + 0.5);

                      blue  = (q * 255.0 + 0.5);

                      break;

               }

          }

             dest[0] = parseInt(red);

             dest[1] = parseInt(green);

             dest[2] = parseInt(blue);

          }
          • 2. Re: Color object by pagenumber
            [Jongware] Most Valuable Participant
            Make that 3rd line

            >var range = lastColoredPage - firstColoredPage + 1;

            .. so the range for a start of 1 and end of 300 is 300. Not that anyone would notice, with the tiny color shift of one page to another.
            • 3. Re: Color object by pagenumber
              Level 1
              Jongware, thanks for your reply. It's a good basis for my book.
              • 4. Re: Color object by pagenumber
                [Jongware] Most Valuable Participant
                I noticed a bit later on 2 boxes per spread may be put on the left page with a particular setup of your page rulers.
                I could program around that but it's way easier just to set the ruler to that position (whatsitcalled?) where the zero is in the middle of spreads; right-click the top ruler to change.