Page 1 of 1

Possible to do a character by character zoom on text?

Posted: 25 Apr 2018, 00:27
by robertwinter
Is it possible to scale up character-by-character across a single 2D text node?

For example, if you had the word ZOOM on the screen, the effect would look like Zoom - ZOOM - ZOOM - ZOOM - ZOOM.

Re: Possible to do a character by character zoom on text?

Posted: 25 Apr 2018, 08:09
by stephen
Hey,

try the enriched block text provider. Here you can use HTML-like syntax to scale your text. E.g.

Code: Select all

Z<style scale="2">O</style>O<style scale="0.5">M</style>
You can add the style-tags either with a Script or Expression node. Consider using a multiline expression and iterating over the string using a loop:

Code: Select all

{
	Random rand = new Random();
	string result = "";
	string doubleScaleStart = "<style scale=\"2.0\">";
	string doubleScaleEnd = "</style>";
	
	foreach(char c in A)
	{
		if(rand.NextDouble() < 0.5)
			result += string.Format("{0}{1}{2}", doubleScaleStart, c, doubleScaleEnd);
		else
			result += c;
	}
	
	return result;
}
This is just a starting point and you probably have to add your logic to decide which characters should be scaled and by what value.

Best
Stephen

Re: Possible to do a character by character zoom on text?

Posted: 25 Apr 2018, 15:04
by robertwinter
Thanks for the suggestion however I don't believe that will work for my application.

I'm looking to smoothly scale each letter up and then back again. Think of a magnifying glass passing across the word.

Re: Possible to do a character by character zoom on text?

Posted: 26 Apr 2018, 08:39
by stephen
Then simply change the condition for the scaling as well as the scale value in the suggested expression's logic. As said, above example is just an idea on how to accomplish the scaling at all and you have to adjust that to your exact needs.

Here you have an expression that maybe goes more into the direction you want. Animate the values in the "Progresses" array to move the zoom effect along the string. Scale Range is some value between 0 and 1 - 1 means the zoom effect is spread across the length of the string. ScaleValue is the strength of the scale at the highest point.

Code: Select all

Parameters:
String A
float[] Progresses
float ScaleRange
float ScaleValue
Expression:
{
   string result = "";
   string scaleStart1 = "<style scale=\"";
   string scaleStart2 = "\">";
   string scaleEnd = "</style>";
   int length = A.Length;
   
   for(int i = 0; i < length; i++)
   {
   		float normalizedPosition = (float)i / (float)length;
		float scale = 1.0f;
		foreach(float p in Progresses)
		{
			scale += Math.Max(0, (ScaleRange - Math.Abs(normalizedPosition - p))) / ScaleRange * (ScaleValue - 1.0f);
		}
		scale += 1.0f;
		result += string.Format("{0}{1}{2}{3}{4}", scaleStart1, scale.ToString(System.Globalization.CultureInfo.InvariantCulture), scaleStart2, A[i], scaleEnd);
   }
   
   return result;
}

Re: Possible to do a character by character zoom on text?

Posted: 28 Apr 2018, 23:03
by robertwinter
I got this to basically work using your suggestion. One issue I did see was when I scaled up ANY letter within the word, it would shift the baseline of the entire word. I used the yoffset to center the character vertically but the entire word line still shifts. I used a workaround of modifying the Y Position of its axis. Not elegant, but it seems to work.