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 1 — pressure gain

For our first example, let’s write a simple script that increases the pen pressure to make it easier to draw thicker lines (assuming your pen pressure maps to the line thickness in your art program). This can be done by using the gain parameter in the pressure curve section of the LNP, but it is a good example to start with.

While trying these examples, it is best to keep the script reference window (or the online version) open so that you can quickly see the descriptions of the predefined input/output variables and functions used.

Activate the script section with new or existing presets, and then select < Custom > mode from the list. Click the Show code button and then enter or copy/paste this code into the box:

temp = p * 2; op = temp;
Copy the code

Now click the Compile button and try drawing a few lines in your art program. They should be thicker than when the script is closed. Let’s explain what this script does:

  1. The first statement reads the predefined Pen Pressure input variable p, multiplicates it by 2, and assigns it to a variable named temp.
  2. The second statement assigns the value of the temp variable to the predefined Pen Pressure output variable op.

That’s great, but what if we don’t always want to double the stress? Let’s make this script more interactive by adding script parameters. This is done by adding an input variable and does not require any statement assignment to it:

temp = p * pressureGain; op = temp;
Copy the code

As you can see, we have replaced the constant 2 with a new variable called pressuregas. When you compile the program, you will see a new script parameter appear under the schema list:

When you add a new script parameter, by default it will be assigned a value of 0.5, and its value range will be [0..1]. In this case, we want the pressure to be able to multiply by something greater than 1, so we need to change the range. To do this, click next to the parameter value input box… Button. This opens the Parameter information window, where you can rename a variable, set its range and default values, precision, and tooltips. Go ahead and change the maximum to 5 and click OK.

Congratulations, you have now written your first interactive LNP custom script! If you save the preset now, the script and its parameter details are saved with it.