Difference between revisions of "Manual/Plugins/Scripting"
Jump to navigation
Jump to search
(→Color) |
|||
Line 74: | Line 74: | ||
− | ==Color== | + | ==Misc== |
+ | ===Color=== | ||
{{object list begin}} | {{object list begin}} | ||
{{object list section|Constructors}} | {{object list section|Constructors}} | ||
Line 101: | Line 102: | ||
{{object list item|hsl(h,s,l,a{{=}}255)|Color|Creates a color from its HSL 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 item|cmyk(c,m,y,k,a{{=}}255)|Color|Creates a color from its CMYK components}} | ||
+ | {{object list end}} | ||
+ | |||
+ | ===Path=== | ||
+ | Object used in cusp plugins to draw the knot line, wrapper to the Knotter internal '''Path_Builder''' class. | ||
+ | Cannot be constructed by the user. | ||
+ | {{object list begin}} | ||
+ | {{object list section|Methods}} | ||
+ | {{object list header}} | ||
+ | {{object list item|add_line( Point p1, Point p2 )|void|Draw a straight line from {{js|p1}} to {{js|p2}} }} | ||
+ | {{object list item|add_quad( Point p1, Point control, Point p2|void | ||
+ | |Draw a quadratic curve from {{js|p1}} to {{js|p2}} with control point {{js|control}} }} | ||
+ | {{object list item|add_cubic( Point p1, Point control1, Point control2, Point p2 )|void | ||
+ | |Draw a cubic curve from {{js|p1}} to {{js|p2}} with control points {{js|control1}} and {{js|control2}} }} | ||
+ | {{object list end}} | ||
+ | |||
+ | ==Graph== | ||
+ | |||
+ | ===Graph=== | ||
+ | The graph for a given knot. | ||
+ | {{object list begin}} | ||
+ | {{object list header}} | ||
+ | {{object list item|new graph()|Graph|Creates an empty graph}} | ||
+ | {{object list item|nodes|Array[Node]|Nodes in the graph}} | ||
+ | {{object list item|edges|Array[Edge]|Edges in the graph}} | ||
+ | {{object list item|style|Graph.Style|Graph Style}} | ||
+ | {{object list item|selected_nodes|Array[node]|List of the selected nodes}} | ||
+ | {{object list item|add_node(point)|Node|Creates a new node}} | ||
+ | {{object list item|add_node(x,y)|Node|Creates a new node}} | ||
+ | {{object list item|remove_node(node)|void|Remove node from the graph}} | ||
+ | {{object list item|remove_edge(edge)|void|Remove edge from the graph}} | ||
+ | {{object list item|connect(node1,node2)|Edge|Creates a new edge}} | ||
+ | {{object list item|node_at(point)|Node|Get the node at the given location}} | ||
+ | {{object list item|node_at(x,y)|Node|Get the node at the given location}} | ||
+ | {{object list item|node_at(point,radius)|Array[Node]|Get the nodes within given distance from location}} | ||
+ | {{object list item|node_at(x,y,radius)|Array[Node]|Get the nodes within given distance from location}} | ||
+ | {{object list item|append( file_name, keep_style{{=}}false, offset{{=}}Point() )|Boolean|Add nodes and edges from a file. '''keep_style''' controls whether the nodes should have their custom style set to override the graph style in order to follow the style from the file.}} | ||
+ | {{object list item|append(Graph other)|void|The contents of the other graph are copied to this graph.}} | ||
+ | {{object list item|clear()|void|Remove all edges and nodes}} | ||
+ | {{object list end}} | ||
+ | |||
+ | |||
+ | ===Node=== | ||
+ | {{object list begin}} | ||
+ | {{object list header}} | ||
+ | {{object list item|pos|Point|Position of the node.}} | ||
+ | {{object list item|x|Number|{{js|pos.x}}.}} | ||
+ | {{object list item|y|Number|{{js|pos.y}}.}} | ||
+ | {{object list item|selected|Boolean|Whether the node is selected.}} | ||
+ | {{object list item|edges|Array[Edge]|(Read-Only) Edges with this node as vertex.}} | ||
+ | {{object list item|style|Node.Style|Contains the style features that this node overrides from the graph}} | ||
+ | {{object list item|has_edge_too(Node other)|Boolean|Whether there is an edge from {{js|this}} to {{js|other}}.}} | ||
+ | {{object list item|edge_to(Node other)|Edge|Edge connecting {{js|this}} and {{js|other}}.}} | ||
+ | {{object list end}} | ||
+ | |||
+ | ===Edge=== | ||
+ | {{object list begin}} | ||
+ | {{object list header}} | ||
+ | {{object list item|vertex1|Node|One of the vertices of the edge}} | ||
+ | {{object list item|vertex2|Node|One of the vertices of the edge}} | ||
+ | {{object list item|line|Line|Line from {{js|vertex1.pos}} to {{js|vertex2.pos}}}} | ||
+ | {{object list item|midpoint|Point|Point at the middle of the edge}} | ||
+ | {{object list item|style|Edge.Style|Contains the style features that this edge overrides from the graph}} | ||
+ | {{object list item|is_vertex(node)|Boolean|Whether the node is a vertex of the edge}} | ||
+ | {{object list item|other(node)|Node|If the given node is one of its vertices, return the other vertex}} | ||
+ | {{object list end}} | ||
+ | |||
+ | |||
+ | ===Graph.Style=== | ||
+ | Default style for nodes and edges and graph appearance | ||
+ | {{object list begin}} | ||
+ | {{object list header}} | ||
+ | {{object list item|crossing|Edge.Style|Default edge style}} | ||
+ | {{object list item|cusp|Node.Style|Default node style}} | ||
+ | {{object list item|colors|Array[Color]|(Read-Only) Colors}} | ||
+ | {{object list end}} | ||
+ | |||
+ | ===Node.Style=== | ||
+ | For nodes, a single style feature can be removed by setting it to {{js|undefined}} | ||
+ | {{object list begin}} | ||
+ | {{object list header}} | ||
+ | {{object list item|angle|Number|Minimum angle required to trigger a cusp}} | ||
+ | {{object list item|curve|Number|Size of the curve control handles}} | ||
+ | {{object list item|distance|Number|Distance of the tip of the cusp from the node}} | ||
+ | {{object list item|shape|String|Name of the cusp shape. Possible values are the elements of {{js|knotter.cusp_shapes}}}} | ||
+ | {{object list item|clear()|void|Reset all features}} | ||
+ | {{object list end}} | ||
+ | |||
+ | ===Edge.Style=== | ||
+ | For nodes, a single style feature can be removed by setting it to {{js|undefined}} | ||
+ | {{object list begin}} | ||
+ | {{object list header}} | ||
+ | {{object list item|curve|Number|Size of the curve control handles}} | ||
+ | {{object list item|gap|Number|Size of the gap for a rope passing under a crossing}} | ||
+ | {{object list item|slide|Number|Slide the crossing position [0-1]}} | ||
+ | {{object list item|type|String|The name of the edge type. Possible values are the elements of {{js|knotter.edge_types}} }} | ||
+ | {{object list item|clear()|void|Reset all features}} | ||
{{object list end}} | {{object list end}} |
Revision as of 10:49, 11 November 2013
This page is updated to Knotter version 0.9.6 |
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.
Contents
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 .
|
Misc
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 |
Path
Object used in cusp plugins to draw the knot line, wrapper to the Knotter internal Path_Builder class. Cannot be constructed by the user.
Methods | ||
---|---|---|
Name | Type | Description |
add_line( Point p1, Point p2 )
|
void
|
Draw a straight line from p1 to p2
|
add_quad( Point p1, Point control, Point p2
|
void
|
Draw a quadratic curve from p1 to p2 with control point control
|
add_cubic( Point p1, Point control1, Point control2, Point p2 )
|
void
|
Draw a cubic curve from p1 to p2 with control points control1 and control2
|
Graph
Graph
The graph for a given knot.
Name | Type | Description |
---|---|---|
new graph()
|
Graph
|
Creates an empty graph |
nodes
|
Array[Node]
|
Nodes in the graph |
edges
|
Array[Edge]
|
Edges in the graph |
style
|
Graph.Style
|
Graph Style |
selected_nodes
|
Array[node]
|
List of the selected nodes |
add_node(point)
|
Node
|
Creates a new node |
add_node(x,y)
|
Node
|
Creates a new node |
remove_node(node)
|
void
|
Remove node from the graph |
remove_edge(edge)
|
void
|
Remove edge from the graph |
connect(node1,node2)
|
Edge
|
Creates a new edge |
node_at(point)
|
Node
|
Get the node at the given location |
node_at(x,y)
|
Node
|
Get the node at the given location |
node_at(point,radius)
|
Array[Node]
|
Get the nodes within given distance from location |
node_at(x,y,radius)
|
Array[Node]
|
Get the nodes within given distance from location |
append( file_name, keep_style=false, offset=Point() )
|
Boolean
|
Add nodes and edges from a file. keep_style controls whether the nodes should have their custom style set to override the graph style in order to follow the style from the file. |
append(Graph other)
|
void
|
The contents of the other graph are copied to this graph. |
clear()
|
void
|
Remove all edges and nodes |
Node
Name | Type | Description |
---|---|---|
pos
|
Point
|
Position of the node. |
x
|
Number
|
pos.x .
|
y
|
Number
|
pos.y .
|
selected
|
Boolean
|
Whether the node is selected. |
edges
|
Array[Edge]
|
(Read-Only) Edges with this node as vertex. |
style
|
Node.Style
|
Contains the style features that this node overrides from the graph |
has_edge_too(Node other)
|
Boolean
|
Whether there is an edge from this to other .
|
edge_to(Node other)
|
Edge
|
Edge connecting this and other .
|
Edge
Name | Type | Description |
---|---|---|
vertex1
|
Node
|
One of the vertices of the edge |
vertex2
|
Node
|
One of the vertices of the edge |
line
|
Line
|
Line from vertex1.pos to vertex2.pos
|
midpoint
|
Point
|
Point at the middle of the edge |
style
|
Edge.Style
|
Contains the style features that this edge overrides from the graph |
is_vertex(node)
|
Boolean
|
Whether the node is a vertex of the edge |
other(node)
|
Node
|
If the given node is one of its vertices, return the other vertex |
Graph.Style
Default style for nodes and edges and graph appearance
Name | Type | Description |
---|---|---|
crossing
|
Edge.Style
|
Default edge style |
cusp
|
Node.Style
|
Default node style |
colors
|
Array[Color]
|
(Read-Only) Colors |
Node.Style
For nodes, a single style feature can be removed by setting it to undefined
Name | Type | Description |
---|---|---|
angle
|
Number
|
Minimum angle required to trigger a cusp |
curve
|
Number
|
Size of the curve control handles |
distance
|
Number
|
Distance of the tip of the cusp from the node |
shape
|
String
|
Name of the cusp shape. Possible values are the elements of knotter.cusp_shapes
|
clear()
|
void
|
Reset all features |
Edge.Style
For nodes, a single style feature can be removed by setting it to undefined
Name | Type | Description |
---|---|---|
curve
|
Number
|
Size of the curve control handles |
gap
|
Number
|
Size of the gap for a rope passing under a crossing |
slide
|
Number
|
Slide the crossing position [0-1] |
type
|
String
|
The name of the edge type. Possible values are the elements of knotter.edge_types
|
clear()
|
void
|
Reset all features |