Difference between revisions of "Manual/Plugins/Scripting"

From Knotter
Jump to navigation Jump to search
(Created page with "{{ambox|type=info|text=To read the documentation for development version {{Development Version}}, see {{rl|{{Development Version}}|Scripting/{{Development Version}}}}.}} {{:M...")
 
Line 1: Line 1:
{{ambox|type=info|text=To read the documentation for development version {{Development Version}}, see {{rl|{{Development Version}}|Scripting/{{Development Version}}}}.}}
+
{{vbox|0.9.6}}
  
{{:Manual/Plugins/Scripting/{{Download Version}}}}
+
Scripts are in QtScript aka ECMAScript aka JavaScript.
 +
 
 +
The details of the language are specified in the [http://qt-project.org/doc/qt-5.0/qtscript/ecmascript.html Qt ECMAScript reference]. This page focuses on functions and objects specific to Knotter.
 +
 
 +
 
 +
 
 +
==Geometry==
 +
 
 +
===Point===
 +
A wrapper to [http://qt-project.org/doc/qt-5.0/qtcore/qpointf.html QPointF].
 +
 
 +
{{object list begin}}
 +
 
 +
{{object list section|Constructors}}
 +
{{object list header}}
 +
{{object list item|new Point()|Point|{{js|new Point(0,0)}}}}
 +
{{object list item|new Point( Point other )|Point|Copy point {{js|other}}}}
 +
{{object list item|new Point( Number x, Number y )|Point|Create point with given coordinates}}
 +
 
 +
{{object list section|External functions}}
 +
{{object list header}}
 +
{{object list item|opposite( Point p )|Point|{{js|new Point(-p.x,-p.y)}}}}
 +
{{object list item|distance(Point a, Point b)|Number|Distance from '''a''' and '''b'''}}
 +
 
 +
{{object list end}}
 +
 
 +
===Line===
 +
A wrapper to [http://qt-project.org/doc/qt-5.0/qtcore/qlinef.html QLineF] most of the functionality of '''QLineF''' is also present in {{js|line}}.
 +
 
 +
{{object list begin}}
 +
 
 +
{{object list section|Constructors}}
 +
{{object list header}}
 +
{{object list item|new Line()|Line|Empty line}}
 +
{{object list item|new Line( Line other )|Line|Copy line {{js|other_line}}}}
 +
{{object list item|new Line( point1, point2 )|Line|Line from point {{js|point1}} to {{js|point2}}}}
 +
 
 +
{{object list section|Properties}}
 +
{{object list header}}
 +
{{object list item|p1|Point|Starting point of the line}}
 +
{{object list item|p2|Point|End point of the line}}
 +
{{object list item|x1|Number|{{js|p1.x}}}}
 +
{{object list item|x2|Number|{{js|p2.x}}}}
 +
{{object list item|y1|Number|{{js|p1.y}}}}
 +
{{object list item|y2|Number|{{js|p2.y}}}}
 +
{{object list item|angle|Number
 +
|Angle of the line in degrees. An angle of 0° is a horizontal line pointing to the right.}}
 +
{{object list item|length|Number|Length of the line (distance between {{js|p1}} and {{js|p2}}}}
 +
{{object list item|dx|Number|{{js|p1.x-p2.x}}}}
 +
{{object list item|dy|Number|{{js|p1.y-p2.y}}}}
 +
 
 +
{{object list section|Methods}}
 +
{{object list header}}
 +
{{object list item|intersect ( Line other )|Point|Return the intersection point between the current line and other}}
 +
{{object list item|normalVector()|Line|Returns a line that is perpendicular to this line with the same starting point and length.}}
 +
{{object list item|unitVector()|Line|Returns the unit vector for this line, i.e a line starting at the same point as this line with a length of 1.0.}}
 +
{{object list item|pointAt(Number t)|Point|Returns the point at the parameterized position specified by t. The function returns the line's start point if t {{=}} 0, and its end point if t {{=}} 1.}}
 +
{{object list item|translate(Point offset)|void|Translate the line by {{js|offset}}}}
 +
{{object list item|translate(Number x,Number y)|void|{{js|translate(point(x,y))}}}}
 +
{{object list end}}
 +
 
 +
===Polygon===
 +
{{object list begin}}
 +
{{object list header}}
 +
{{object list item|new Polygon()|Polygon|Create an empty polygon.}}
 +
{{object list item|new Polygon(vertices)|Polygon|Create a polygon with given vertices.}}
 +
{{object list item|vertices|Array[Point]|Vertices of the polygon.}}
 +
{{object list item|contains(point)|Boolean|Whether the point is inside the polygon.}}
 +
{{object list item|contains(x,y)|Boolean|{{js|contains(new Point(x,y))}}.}}
 +
{{object list item|add_vertex(point)|void|Appends a vertex to {{js|vertices}}.}}
 +
{{object list end}}
 +
 
 +
 
 +
==Color==
 +
{{object list begin}}
 +
{{object list section|Constructors}}
 +
{{object list header}}
 +
{{object list item|new Color()|Color|Creates a transparent black color}}
 +
{{object list item|new Color(string)|Color|Create a color from a color name eg: '''#ff00ff''', '''red'''}}
 +
{{object list item|new Color(r,g,b,a{{=}}255)|Color|Create a color from rgb components [0-255]}}
 +
{{object list item|new Color(color)|Color|Copy color}}
 +
{{object list section|Properties}}
 +
{{object list header}}
 +
{{object list item|alpha|Number|Transparency [0-255]}}
 +
{{object list item|red|Number|RGB red channel [0-255]}}
 +
{{object list item|green|Number|RGB green channel [0-255]}}
 +
{{object list item|blue|Number|RGB blue channel [0-255]}}
 +
{{object list item|hue|Number|HSV hue channel [0-360]}}
 +
{{object list item|saturation|Number|HSV saturation channel [0-255]}}
 +
{{object list item|value|Number|HSV value channel [0-255]}}
 +
{{object list item|cyan|Number|CMYK cyan channel [0-255]}}
 +
{{object list item|magenta|Number|CMYK magenta channel [0-255]}}
 +
{{object list item|yellow|Number|CMYK yellow channel [0-255]}}
 +
{{object list item|black|Number|CMYK black channel [0-255]}}
 +
{{object list section|Number|External functions}}
 +
{{object list header}}
 +
{{object list item|rgb(r,g,b,a{{=}}255)|Color|Same as {{js|new Color(r,g,b,a)}}}}
 +
{{object list item|hsv(h,s,v,a{{=}}255)|Color|Creates a color from its HSV components}}
 +
{{object list item|hsl(h,s,l,a{{=}}255)|Color|Creates a color from its HSL components}}
 +
{{object list item|cmyk(c,m,y,k,a{{=}}255)|Color|Creates a color from its CMYK components}}
 +
{{object list end}}

Revision as of 10:48, 11 November 2013

Scripts are in QtScript aka ECMAScript aka JavaScript.

The details of the language are specified in the Qt ECMAScript reference. This page focuses on functions and objects specific to Knotter.


Geometry

Point

A wrapper to QPointF.

Constructors
Name Type Description
new Point() Point new Point(0,0)
new Point( Point other ) Point Copy point other
new Point( Number x, Number y ) Point Create point with given coordinates
External functions
Name Type Description
opposite( Point p ) Point new Point(-p.x,-p.y)
distance(Point a, Point b) Number Distance from a and b

Line

A wrapper to QLineF most of the functionality of QLineF is also present in line.

Constructors
Name Type Description
new Line() Line Empty line
new Line( Line other ) Line Copy line other_line
new Line( point1, point2 ) Line Line from point point1 to point2
Properties
Name Type Description
p1 Point Starting point of the line
p2 Point End point of the line
x1 Number p1.x
x2 Number p2.x
y1 Number p1.y
y2 Number p2.y
angle Number Angle of the line in degrees. An angle of 0° is a horizontal line pointing to the right.
length Number Length of the line (distance between p1 and p2
dx Number p1.x-p2.x
dy Number p1.y-p2.y
Methods
Name Type Description
intersect ( Line other ) Point Return the intersection point between the current line and other
normalVector() Line Returns a line that is perpendicular to this line with the same starting point and length.
unitVector() Line Returns the unit vector for this line, i.e a line starting at the same point as this line with a length of 1.0.
pointAt(Number t) Point Returns the point at the parameterized position specified by t. The function returns the line's start point if t = 0, and its end point if t = 1.
translate(Point offset) void Translate the line by offset
translate(Number x,Number y) void translate(point(x,y))

Polygon

Name Type Description
new Polygon() Polygon Create an empty polygon.
new Polygon(vertices) Polygon Create a polygon with given vertices.
vertices Array[Point] Vertices of the polygon.
contains(point) Boolean Whether the point is inside the polygon.
contains(x,y) Boolean contains(new Point(x,y)).
add_vertex(point) void Appends a vertex to vertices.


Color

Constructors
Name Type Description
new Color() Color Creates a transparent black color
new Color(string) Color Create a color from a color name eg: #ff00ff, red
new Color(r,g,b,a=255) Color Create a color from rgb components [0-255]
new Color(color) Color Copy color
Properties
Name Type Description
alpha Number Transparency [0-255]
red Number RGB red channel [0-255]
green Number RGB green channel [0-255]
blue Number RGB blue channel [0-255]
hue Number HSV hue channel [0-360]
saturation Number HSV saturation channel [0-255]
value Number HSV value channel [0-255]
cyan Number CMYK cyan channel [0-255]
magenta Number CMYK magenta channel [0-255]
yellow Number CMYK yellow channel [0-255]
black Number CMYK black channel [0-255]
Number
Name Type Description
rgb(r,g,b,a=255) Color Same as new Color(r,g,b,a)
hsv(h,s,v,a=255) Color Creates a color from its HSV components
hsl(h,s,l,a=255) Color Creates a color from its HSL components
cmyk(c,m,y,k,a=255) Color Creates a color from its CMYK components