数式シンタックス

リテラル バリュー

数式インプットでレイヤ名を参照したり、数字、文字列などを使用するとき、下記の表記法に合わせて使用しなければなりません。

Layer name

Use backticks around the layer name.

Layer name
Text

Use double quotation marks around the text.

Text
Text with multiple lines

Add a \n to add a line break between characters or words.

Text with multiple lines
Number

Use Arabic numbers only; other symbols are not allowed.

Number
Color

Colors must be expressed in the #FFFFFF format (Hex color code).

Color
Variable

Use variable names that do not have any symbols in the name.

Variable

四則演算

足し算(+), 引き算(-), 掛け算(*), 割り算(/), 剰余演算(%)など四則演算ができます。

剰余演算(%)

割り算をした後の剰余を求めます。例えば5%2は5を2で割った後の剰余である1になります。

文字列演算

他の演算は全て数字どうしの演算だけを支援しますが、足し算は文字列に使用できます。文字列で足し算をしたときには文字列をつなげる用途で使用されます。たとえば、文字列"1"と文字列"2"で足し算をすると,"12"になります。

Text + Text
"helloworld""12"
Text + Number
"hello1234"

レイヤプロパティ

レイヤの座標、大きさなどのプロパティ値が参照できます。

  • `layerName`.x

    The x-coordinate of a layer.

  • `layerName`.y

    The y-coordinate of a layer.

  • `layerName`.width

    The width of a layer.

  • `layerName`.height

    The height of a layer.

  • `layerName`.scaleX

    The scale factor X of a layer.

  • `layerName`.scaleY

    The scale factor Y of a layer.

  • `layerName`.rotation

    The rotation value of a layer.

  • `layerName`.rotation3d

    The 3D rotation value of a layer.

  • `layerName`.opacity

    The opacity value of a layer.

  • `layerName`.radius

    The radius value of a layer.

  • `containerName`.scrollOffset

    The current scroll value.

  • `layerName`.color

    The Hex color code of a layer.

  • `layerName`.fillOpacity

    The fill opacity value of a layer.

  • `layerName`.borderWidth

    The border width of a layer.

  • `layerName`.borderColor

    The border color of a layer.

  • `layerName`.borderOpacity

    The border opacity of a layer.

  • `layerName`.shadowOffsetX

    The x-coordinate of the shadow of a layer.

  • `layerName`.shadowOffsetY

    The y-coordinate of the shadow of a layer.

  • `layerName`.shadowBlur

    The shadow blur of a layer.

  • `layerName`.shadowColor

    The shadow color of a layer.

  • `layerName`.shadowOpacity

    The shadow opacity of a layer.

  • `layerName`.text

    The text in a text layer.

  • `layerName`.textColor

    The color of a text layer.

  • `layerName`.textOpacity

    The opacity of a text layer.

  • `layerName`.currentTime

    The current playtime of a video or audio layer.

Functions

Text Manipulation

  • length(source: TEXT)NUMBER
    • Calculates the number of characters in a text.
    • e.g.length("hello")5
  • left(source: TEXT, count: NUMBER)TEXT
    • Extracts a number of letters from a text, starting on the left side.
    • e.g.left("hello", 3)"hel"
  • right(source: TEXT, count: NUMBER)TEXT
    • Extracts a number of letters from a text, starting on the right side.
    • e.g.right("hello", 3)"llo"
  • concat(source1: TEXT, source2: TEXT)TEXT
    • Joins two separate texts into one text.
    • e.g.concat("hello", "world")"helloworld"
  • replace(source: TEXT, from: TEXT, to: TEXT)TEXT
    • Replaces a part of a text with another text.
    • e.g.replace("helloworld", "world", "protopie")"helloprotopie"
  • trim(source: TEXT)TEXT
    • Removes whitespace on either side of a text.
    • e.g.trim(" helloworld ")"helloworld"
  • ltrim(source: TEXT)TEXT
    • Removes whitespace from the left side of a text.
    • e.g.ltrim(" helloworld ")"helloworld "
  • rtrim(source: TEXT)TEXT
    • Removes whitespace from the right side of a text.
    • e.g.rtrim(" helloworld ")" helloworld"
  • indexOf(source: TEXT, searchValue: TEXT)NUMBER
    • Returns the position of the occurrence of the searchValue in a text. This method returns -1 if searchValue never occurs.
    • e.g.indexOf("hello world")6
  • lowerCase(source: TEXT)TEXT
    • Converts a text to lowercase.
    • e.g.lowerCase("Hello")"hello"
  • upperCase(source: TEXT)TEXT
    • Converts a text to uppercase.
    • e.g.upperCase("Hello")"HELLO"
  • lpad(source: TEXT, length: NUMBER, padString: TEXT)TEXT
    • Add padString on the left side of a text to match the chosen length.
    • e.g.lpad(5, 2, "0")"05"
  • rpad(source: TEXT, length: NUMBER, padString: TEXT)TEXT
    • Add padString on the right side of a text to match the chosen length.
    • e.g.rpad(5.2, "0")"50"
  • repeat(source: TEXT, count: NUMBER)TEXT
    • Repeat a text at count times.
    • e.g.repeat("hello", 3)"hellohellohello"

Math

  • min(source1: NUMBER, source2: NUMBER)NUMBER
    • Returns the smallest of two numbers.
    • e.g.min(0, 1)0
  • max(source1: NUMBER, source2: NUMBER)NUMBER
    • Returns the largest of two numbers.
    • e.g.max(0, 1)1
  • abs(source: NUMBER)NUMBER
    • Returns the absolute value of a number.
    • e.g.abs(-1)1
  • round(source: NUMBER)NUMBER
    • Returns the rounded value of a number.
    • e.g.round(1.5)2
  • floor(source: NUMBER)NUMBER
    • Returns the largest integer value smaller than or equal to a number.
    • e.g.floor(1.5)1
  • ceil(source: NUMBER)NUMBER
    • Returns the smallest integer value larger than or equal to a number.
    • e.g.ceil(1.5)2
  • sqrt(source: NUMBER)NUMBER
    • Returns the square root of a given number. If the number is negative, an error occurs.
    • e.g.sqrt(9)3
  • pow(source1: NUMBER, source2: NUMBER)NUMBER
    • Calculates the first number raised to the power of the second number.
    • e.g.pow(2, 3)8
  • sin(radian: NUMBER)NUMBER
    • Returns the sine of a number.
    • e.g.sin(90)-0.89
  • cos(radian: NUMBER)NUMBER
    • Returns the cosine of a number.
    • e.g.cos(90)-0.45
  • tan(radian: NUMBER)NUMBER
    • Returns the tangent of a number.
    • e.g.tan(45)1.62
  • asin(value: NUMBER)NUMBER
    • Returns the arcsine of x, in radians.
    • e.g.asin(0)0
    • e.g.asin(1)1.5707963267948966(PI / 2, 90°)
  • acos(value: NUMBER)NUMBER
    • Returns the arccosine of x, in radians.
    • e.g.acos(0)1.5707963267948966(PI / 2, 90°)
    • e.g.acos(1)0
  • atan(value: NUMBER)NUMBER
    • Returns the arctangent of a number.
    • e.g.atan(0)0
    • e.g.atan(0)0.7853981633974483(PI / 4, 45°)
  • random()NUMBER
    • Returns a random number between 0 and 1.
    • e.g.random()a random number between 0 and 1
  • random(min: NUMBER, max: NUMBER)NUMBER
    • Returns a random number between two given numbers.
    • e.g.random(1, 5)a random number between 1 and 5
  • randomInt(min: NUMBER, max: NUMBER)NUMBER
    • Returns a random integer value between two given numbers.
    • e.g.randomInt(1, 5)a random number between 1 and 5(integar)
  • sign(value: NUMBER)NUMBER
    • Returns 1 if the number is a positive number. Returns -1 if the number is a negative number. Returns 0 if the number is 0.
  • atan2(x: NUMBER, y: NUMBER)NUMBER
    • Returns the angle in the plane (in radians) between the positive x-axis and the ray from (0,0) to the point (x,y).
  • degrees(radians: NUMBER)NUMBER
    • Convert radians to degrees.
  • radians(degree: NUMBER)NUMBER
    • Convert degrees to radians.

Color

  • color(red: NUMBER, green: NUMBER, blue: NUMBER)COLOR
    • Returns a color value (Hex color code) based on the RGB value.
    • e.g.color(255, 255, 255)#FFFFFF
  • red(source: COLOR)NUMBER
    • Returns the red RGB value of a color code.
    • e.g.red(#FF0000)255
  • green(source: COLOR)NUMBER
    • Returns the green RGB value of a color value (Hex color code).
    • e.g.green(#FF0000)0
  • blue(source: COLOR)NUMBER
    • Returns the blue RGB value of a color value (Hex color code).
    • e.g.blue(#FF0000)0

Type Conversion

  • text(source: NUMBER)TEXT
    • Converts a number to a text.
    • e.g.text(1234)"1234"
  • number(source: TEXT)NUMBER
    • Converts a text to a number. If the text is not a number, an error occurs.
    • e.g.number("1234")1234
  • color(source: TEXT)COLOR
    • Converts a text to a color value. The text must be in the form of a Hex color code (#FF0000), and if it isn’t, an error occurs.
    • e.g.color("#FFFFFF")#FFFFFF
  • format(value: NUMBER, format: TEXT)NUMBER
    • Converts a number into a text. The number can be split into separate texts made up of any number of digits. Furthermore, numbers with decimals can be expressed, and the number of digits following a decimal point can be designated. number: the number that is to be converted into a text. formatText: the text that will be made up of the number. # is the placeholder for integers and 0 is a placeholder for fractional numbers. Additional numbers can be inserted into the text.
    • e.g.format(1234.567, "#,###.00")1,234.58
    • e.g.format(1234567, "#,###.00")1,234,567
    • e.g.format(1234.567, "#.###,00")1.234,57
    • e.g.format(1234.567, "#,##.00")12,34.57
    • e.g.format(1234.567, "#,###")1,235
    • e.g.format(1234.567, "#")1235
  • layer(source: TEXT).layerPropertyTEXT or NUMBER
    • Refer to a layer.
    • e.g.layer("Rectangle 1").layerPropertyGet the x value of a layer called Rectangle 1