Jump to content

Type with a gradient blend


tim lindner

Recommended Posts

Recently a client need some type with a horizontal gradient blend. I came up with this:

// Return "FieldName" colorized from left (start color) to right (end color).
// Remember to turn on "Treat returned strings as tagged text" check box.

var FieldName="Field Name";
var Start = [2,63,98,1]; // Start color: [C,M,Y,K]
var End = [23,85,100,16]; // End Color: [C,M,Y,K]

var FieldLength = Len(Rule(FieldName));
var StepCyan = (End[0]-Start[0])/FieldLength;
var StepMagenta = (End[1]-Start[1])/FieldLength;
var StepYellow = (End[2]-Start[2])/FieldLength;
var StepBlack = (End[3]-Start[3])/FieldLength;
var myColor;
var Result = "<span>";

// Build Colors for Text

for (c = 0; c < FieldLength; c++)
{
myColor = new FusionProColor("CustomGradColor"+c, Start[0]+(StepCyan*c), Start[1]+(StepMagenta*c), Start[2]+(StepYellow*c), Start[3]+(StepBlack*c));
}

// Build resulting string

for (c = 0; c < FieldLength; c++)
{
   if (Asc(Mid(Rule(FieldName), c+1, 1)) == 32)
   {
	// Special case the space character
       Result = Result + " "; // Use " " for a breaking space
   }
   else if (Asc(Mid(Rule(FieldName), c+1, 1)) == 38)
   {
       // Special case the ampersand character
       Result = Result + "&";
   }
   else
   {
       Result = Result + '<color name="CustomGradColor'+c+'">'+Mid(Rule(FieldName), c+1, 1);
   }
}

Result = Result + "<\span>";

return Result;

This does a "fake" gradient blend by colorizing each character in the string.

It's really only useful for a single line of type. If the line breaks the gradient will wrap with the type.

Link to comment
Share on other sites

  • 3 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...