This article has participated in the Denver Nuggets Creators Camp 3 “More Productive writing” track, see details: Digg project | creators Camp 3 ongoing, “write” personal impact.

Chestnut 6 — Calligraphy

When writing calligraphy or characters, the strokes must be strictly controlled so that the lines have style and personality. Here’s a script that adjusts your line thickness according to the direction of your pen. It lets the user set two pressure scaling factors, one for when the pen is mostly moving up and one for when the pen is mostly moving down. This allows the user to focus on the pen movement, while the script helps control the pressure/thickness aspects.

ydir = nx * 0.5 + 0.5; 
op = p * mix(minScale, maxScale, ydir);
Copy the code

The idea behind this script is to scale the pressure according to the direction of the line. To do this, we look at the current normal vector of the line (nx, ny). Because the normal vector is orthogonal to the direction of the line, ny tells us how much of the current direction of the line is horizontal, and nx tells us how much of the current direction of the line is vertical. In this case, we want to adjust the pressure based on vertical motion, so we will use NX.

The normal vector is a unit vector (length 1), so each of its coordinates is in the range [-1..1]. The first thing the script does is remap this range to [0..1] and store the result in the ydir variable. This variable is then used to calculate the final pressure scaling factor by mixing minScale and maxScale.

Set the minScale parameter range to [0..1] and maxScale to [1..2]. Below are some lines drawn with minScale set to 0.75 and maxScale set to 1.3. Smoothness is also used in this preset to give the lines a smoother effect. As you can see, this script can even give lines a 3D effect!

Now, instead of always using the vertical axis, we add two parameters for the user to set, which axis and direction will be applied to the pressure modulation effect:

dir = axis ? nx : ny; 
dir = direction ? dir : -dir; 
dir = dir * 0.5 + 0.5; 
op = p * mix(minScale, maxScale, dir);
Copy the code

Set the parameter range of axis and direction to [0..1]. Now, if you set Axis to 0, the effect will apply to the horizontal part of the line. The direction parameter can be used to reverse the direction of minScale and maxScale applications

Chestnut 7 — Shake line

Next time

Chestnut 8 — City scenery

Next time

Chestnut 9 — Lightning

Next time

Chestnut 10 – Signal misidentification

Next time

Chestnut 11 — Debugging

Next time