🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #2449

Re: Color object by pagenumber

#2449
From: jongware
Date: Mon, 15 Dec 2008 22:03
137 lines
3471 bytes
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);

}
Technical Details
Message-ID: <59b746a6.0@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!news2!newshub.sdsu.edu!webcrossing
References: <59b746a6.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,56e2343ee29ee09a
X-Google-Attributes: gidf939a,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: jongware@adobeforums.com
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!news2!newshub.sdsu.edu!webcrossing
Newsgroups: adobe.scripting.indesign
Subject: Re: Color object by pagenumber
Message-ID: <59b746a6.0@webcrossing.la2eafNXanI>
Date: Mon, 15 Dec 2008 14:03:28 -0800
References: <59b746a6.-1@webcrossing.la2eafNXanI>
Lines: 144
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit