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.

Scripting language

In LNP (Lazy Nezumi Pro), scripts are defined by a series of statements separated by semicolons. Read and evaluate statements from top to bottom. These statements can consist of variable assignments, function calls, and mathematical expressions. All variables contain real numbers (stored as 32-bit floating-point numbers). Here’s a typical example:

wave = triangle(d/period);
Copy the code

In this example, the value of the variable d is divided by the value of the variable period, and the result is passed as an argument to the Triangle function, which assigns its result to the wave variable.

Variable names can contain the following characters:

_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
Copy the code

They should not start with numeric characters. Unlike other scripting languages, variables do not need to be declared before being used in a statement.

If you use a variable in an expression to produce a result, it is treated as an input variable, and if you assign a value to it, it is treated as an output variable. A variable can be an input variable or an output variable.

If the script contains input variables that are not output variables (they are used in a statement, but no statement assigns a value to them), these variables are treated as script parameters and displayed in the UI under the schema list after successful compilation. This will allow the user to set their values through a slider or input box.

Conditional assignment can be performed using the following syntax:

a = condition ? b : c;
Copy the code

In this case, variable A receives the value B if the conditional test is true, and c otherwise.

All predefined input/output variables, operators for mathematical expressions, and functions are described in a table on the script reference page.

Starting with version 211.06.04 of LNP, you can write comments in scripts to document its functionality. The compiler ignores all text after // up to the end of the line, and all text between /* and */.

Script Engine Operations

When you start drawing with the enabled script, all output variables (predefined, as well as your own) are initialized to zero. When you enter new tablet data while drawing, the predefined input variable values are updated, the program is evaluated, the predefined output variable is read and used for modification, and the data is passed to the art application to draw lines.

Note that you do not have to modify all the predefined output variables if you do not need to. This is perfectly acceptable if the program affects only the output pressure (variable op), or only the position of the pen (variables ox and oy). However, in order for the program to compile successfully, you need to modify at least one of the variables.

As with rulers, be sure to turn off brush smoothing/stabilization for the art app when using scripts. Since application smoothing is applied after all LNP processing, leaving it on May interfere with your script output and change the expected shape of your pattern. If you need stability, you can use LNP smoothing, since this is applied before the script