防抖辅助绘画神器 —— Lazy Nezumi Pro 入门(十)【脚本】

334 阅读4分钟

本文已参与掘金创作者训练营第三期「高产更文」赛道,详情查看:掘力计划|创作者训练营第三期正在进行,「写」出个人影响力

程序语言定义

脚本程序是由分号分隔的一系列语句定义的。编译器从上到下读取和评估语句。这些语句可以由变量赋值、函数调用和数学表达式组成。所有变量都存储为 32 位浮点值。

有一组预定义的输入变量可以读取,还有一组输出变量可以写入。

这些变量如下表所示:

预定义的输入变量

名字描述单位/范围
xCurrent pen x coordinateScreen pixels
yCurrent pen y coordinateScreen pixels
rxIf ruler active, x coordinate input to ruler stageScreen pixels
ryIf ruler active, y coordinate input to ruler stageScreen pixels
sxStart of stroke x coordinateScreen pixels
syStart of stroke y coordinateScreen pixels
exLast stroke end x coordinateScreen pixels
eyLast stroke end y coordinateScreen pixels
psxLast stroke start x coordinateScreen pixels
psyLast stroke start y coordinateScreen pixels
pPen pressureNormalized [0..1]
dDistance from start of current strokeScreen pixels
dnFor rulers with a center or connection point: normalized distanceRadial/Perspective/Connected: 1.0 at start, 0.0 at center/VP/connection point Ellipse: 0.0 at start, plus or minus 1.0 for each time around.
dsRulers: Radial, Perspective, Connected Distance from start to center/VP/connection pointScreen pixels
sPen speedScreen pixels between updates
ewCurrent ellipse ruler width (width >= height)Screen pixels
ehCurrent ellipse ruler heightScreen pixels
erEllipse ruler rotationDegrees
ecaEllipse ruler current angle of pen positionDegrees
nxLine normal x coordinateNormalized [0..1]
nyLine normal y coordinateNormalized [0..1]
dxChange in x since last pen positionScreen pixels
dyChange in y since last pen positionScreen pixels
cxCustom center position x (set with shortcut)Screen pixels
cyCustom center position y (set with shortcut)Screen pixels
rcxRuler center position xScreen pixels
rcyRuler center position yScreen pixels
rPen rotationNormalized [0..1]
tePen tilt elevation[0..1024]
taPen tilt angleNormalized [0..1]
res0Result 0 of special functionsFunction dependant
res1Result 1 of special functionsFunction dependant

预定义的输出变量

名字描述单位/范围
oxPen x coordinateScreen pixels
oyPen y coordinateScreen pixels
opPen pressureNormalized [0..1]
orPen rotationNormalized [0..1]
otePen tilt elevation[0..1024]
otaPen tilt angleNormalized [0..1]

当您开始启用脚本程序进行绘图时,所有输出变量(预定义的,以及您自己的)都初始化为 0 。

当你作画时,预定义的输入变量值将被更新,程序将被评估,预定义的输出变量将被读取并用于修改传递给你的美术应用程序的数据。

请注意,如果您不想修改所有的输出变量,则不必修改。如果一个程序只影响输出压力(op),或者只影响位置(ox 和 oy),这是完全可以接受的。

但是,为了使程序成功编译,您至少需要修改其中一个变量。

如果程序使用中心位置变量( cx 和 cy ),您可以通过将鼠标悬停在您想要的屏幕位置上,并点击设置脚本中心位置(Set Scripting Center Pos)快捷方式来设置该位置,该快捷方式可以在设置->编辑快捷方式菜单中设置。

如果您启用了覆盖,您还可以看到屏幕上的圆心位置,并与您的鼠标或笔进行交互。

程序中使用的数学运算符

操作符释义优先级
=assignement-1 (can only be applied to variables)
condition ? x : yif condition expression is true, x, otherwise y0
&&boolean and1
boolean or2
<=less or equal4
>=greater or equal4
!=not equal4
==equal4
greater than4
<less than4
+addition5
-subtraction5
*multiplication6
/division6
raise x to the power of y7

程序中使用的内置函数

函数名描述
sin(x)sine function (all trigonometric functions use radians)
cos(x)cosine function
tan(x)tangent function
asin(x)inverse sine function
acos(x)inverse cosine function
atan(x)inverse tangent function
atan2(y, x)inverse tangent of y/x, use if correct angle quadrant is needed
sinh(x)hyperbolic sine function
cosh(x)hyperbolic cosine function
tanh(x)hyperbolic tangent function
asinh(x)inverse hyperbolic sine function
acosh(x)inverse hyperbolic cosine function
atanh(x)inverse hyperbolic tangent function
log2(x)logarithm to the base 2
log10(x)logarithm to the base 10
log(x)logarithm to the base 10
ln(x)logarithm to base e (2.71828...)
exp(x)e raised to the power of x
fsqrt(x)square root
frsqrt(x)reciprocal square root
sign(x)sign function -1 if x<0; 1 if x>0
rint(x)round to nearest integer
fabs(x)absolute value
min(...)min of all arguments
max(...)max of all arguments
sum(...)sum of all arguments
avg(...)mean value of all arguments
rand()random value between 0 and 1
srand()random value between -1 and 1
randGauss(mean, stddev)random value using gaussian distribution using supplied mean and standard deviation
fmod(x, d)floating point remainder of x/d
ceil(x)smallest integral value that is not less than x (round up)
floor(x)largest integral value that is not greater than x (round down)
frac(x)fractional part of x, equivalent to x - floor(x)
mix(a, b, w)linear interpolation: a + (b - a) * w
smoothStep(e0, e1, x)0 when x <= e0, 1 when x >= e1, 3rd order interpolation in between
smootherStep(e0, e1, x)0 when x <= e0, 1 when x >= e1, 5th order interpolation in between
clamp(min, max, x)clamps x between min and max
rotDeg(x, y, angle)rotates the (x,y) vector angle degrees stores the rotated vector in (res0,res1), and returns the rotated x component
rotRad(x, y, angle)same as rotDeg, but angle is in radians
normalize(x, y)normalizes vector (x, y), stores it in (res0, res1), and returns the length of (x, y)
length(x, y)length of vector (x, y)
rlength(x, y)1 / length(x, y)
lengthSq(x, y)square length of vector (x, y)
debugOut(string, value)printf style function that prints to the log file. Example: debugOut(“value: %f”, value);