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 4 — Zipper

In this example, we will write a script to help us draw zippers quickly!

The previous example introduced the square wave function. Here we will use a similar sine (sin) function that takes two parameters: the distance of the sampling function and the thickness of the wave crest. You can preview the feature below.

This time, we want to use the result of this function to replace the pen position, not modify its pressure. To do this, we will use the predefined input variables nx and NY. These are the x,y components of the normal vector along the current position of the stroke. If you’re not familiar with vectors, each component represents displacement along an axis. We can use this to offset the current position on the curve directly.

Here is the script code:

offset = amplitude * sine(d/period, thickness); 
ox = x + nx * offset; 
oy = y + ny * offset;
Copy the code

This creates three script parameters. The thickness parameter here ranges from [0.25..5]. The amplitude parameter controls how high the wave can go from the center, so try [5..200]. For the period parameter, you can use the same range [10..100] as in the previous example.

All wave functions return a value in the [-1..1] range, so the first line of the script multiplies the result by our amplitude argument and stores the result in the offset variable.

The next two predefined output position variables ox and oy are assigned by taking the current (x,y) position and replacing it with an offset quantity along the (unit length) normal vector. This causes the drawn line to move back and forth around the direction the pen moves.

Be sure to use the Thickness parameter to see how you can change the shape of the wave pattern. Enabling this script and setting Thickness to 3 gives the following result:

This is another version of the script that adjusts the amplitude by the input pressure force. This allows us to change the shape by applying more or less pressure when drawing.

offset = p * amplitude * sine(d/period, thickness); 
ox = x + nx * offset; 
oy = y + ny * offset;
Copy the code

When using scripts to displace pens in this way, it helps to enable a bit of smoothing in LNP, as this will also smooth out normal vector changes as you draw lines. If you want the shape to be centered on a perfect straight line, you can also use one of LNP’s rulers!

You can find other scripts that use this normal substitution concept in the Basic Pattern section of the Mode list.

Chestnut 5 — Gear

Next time

Chestnut 6 — Calligraphy

Next time

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