=
sign to assign a value to the variable. The following demonstrates various variable declarationst
— How many seconds has passed since this Scenario was started?dt
— Time between frames as seconds, e.g. 0.1 is 1/10th of a second.frame_count
— How many frames have passed? e.g. 1, 2, 3...X
, Y
, Z
— These are shortcuts for indexing the first two elements of 3-D matrices, e.g. my_particle.pos[X]
+
— Addition-
— Subtraction*
- Multiplication/
- Division^
- Exponent%
- Modulopow(base, power)
function takes two arguments, raising the base
by the power
.sqrt(positive_number)
function takes a single non negative number and returns the real square root of the number.abs(number)
function returns the absolute value of a number.pi
to represent PI.sin(angle)
function is used to evaluate the trigonometric sine value for a given input angle. The input angle must be provided in radians.cos(angle)
function is used to evaluate the trigonometric cosine value for a given input angle. The input angle must be provided in radians.tan(angle)
function is used to evaluate the trigonometric tangent value for a given input angle. The input angle must be provided in radians.asin(value)
function is used to evaluate the trigonometric arcsine value (inverse sine) for a given input. The output angle is given in radians.acos(value)
function is used to evaluate the trigonometric arccosine value (inverse cosine) for a given input. The output angle is given in radians.atan2(value)
function is used to evaluate the trigonometric arctangent value (inverse tangent) for a given X and Y input. The output angle is given in radians.deg_to_rad(angle)
function is not part of the MathNotepad language but is provided as a helper function to make the conversion from degree angles to radians easier. The input is an angle measurement in degrees and the output is the angle measurement in radians.degrees(angle)
function is not part of the MathNotepad language but is provided as a helper function to make the conversion from radian angles to degrees easier. The input is an angle measurement in radians and the output is the angle measurement in degrees.x = [a1, a2, a3, ..., an]
and y = [b1, b2, b3, ..., bn]
is defined as:dot(x, y) = a1 * b1 + a2 * b2 + a3 * b3 + … + an * bn
x = [a1, a2, a3]
and y = [b1, b2, b3]
is defined as:cross(x, y) = [ a2 * b3 - a3 * b2, a3 * b1 - a1 * b3, a1 * b2 - a2 * b1 ]
dim: number
is a zero-based dimension over which to concatenate the matrices. By default the last dimension of the matrices.Arrow
to represent arrows in your simulations. See below for more details.drawArrow
function draws an arrow and is commonly used to illustrate vectors for a particle. drawArrow should be called in the Calculations editor because it only draws the arrow for the current frame. If you call drawArrow() in the Initial State editor, you will not see anything.drawArrow(pos=[0,0], size=[1,0], color="black", components=false, thickness=1)
-> returns and draws an Arrow objectpos
— coordinates for the starting point of the arrow as an [X,Y] matrix.size
— the vector to illustrate, e.g. [10, 0] will draw an arrow 10 units to the right.color
— Optional HTML color value for your arrow, e.g. "red" or "#ff0000".components
— Optional flag that determines if vector components are drawn, a value of true
displays the components.thickness
— Optional stroke value that determines the visual thickness of the arrow.Line
to represent lines in your simulations. See below for more details.drawLine
function draws a line and is commonly used to illustrate some connecting member like a string or cable, but could really represent anything you like. drawLine
should be called in the Calculations editor because it only draws the line for the current frame. If you call drawLine
in the Initial State editor, you will not see anything.drawLine(pos=[0,0], pos2=[10,0], color="black", thickess=1)
-> returns and draws an Line objectpos
— coordinates for the starting point of the line as an [X,Y] matrix.pos2
— the coordinates of the end point of the line as an [X,Y] matrix.color
— Optional HTML color value for the line, e.g. "red" or "#ff0000".thickness
— Optional stroke value that determines the visual thickness of the line.unit_vector(vec)
-> returns a vector of length 1, and in same direction as vec
.vec
- any two dimensional vector as a [X, Y] matrix.magnitude(vec)
-> returns the scaler magnitude of the vector vec
.vec
- any two dimensional vector as a [X, Y] matrix.direction(vec, units="rad")
-> returns the scaler angle measurement of the vector vec
heading in radian form or in degree form.vec
- any two dimensional vector as a [X, Y] matrix.units
- optional deg
for degree measurement or the default of rad
for radians. polar(radius, angle, units="rad")
-> returns a two dimensional vector as a [X, Y] matrix.radius
- scalar quantity representing the scalar distance of the radius of the angle
- scalar quantity representing the angle measurement of the polar coordinate.units
- optional deg
for degree measurement or the default of rad
for radians.createPoints(min, max, step, expression)
-> returns an array of points whose domain is defined from the min
value to the max
value with an increment defined by step
and whose range is evaluated based on the function expression
.min
- the inclusive minimum value of the domain.max
- the exclusive maximum value of the domain.step
- the increment step value of the domain.expression
- a string representing a functional expression that can be evaluated in terms of "x".stop(test)
-> returns a either false or true. If true is returned, the simulation stops.test
- a boolean statement that can be evaluated to true
or false
. hasCollided(source, target)
-> returns a boolean true
or false
.source
- Circle
or Rectangle
object target
- Circle
or Rectangle
objectgetIntersect(source, target)
-> returns a two dimensional matrix.source
- Circle
or Rectangle
object target
- Circle
or Rectangle
objectequal(a, b)
or a == b
true
or false
.equal
, but it tests element wise whether two matrices are equal. It returns a boolean value of true
or false
. The code below demonstrates the difference between equal
and deepEqual
:larger(a, b)
or a > b
true
or false
.smaller(a, b)
or a < b
true
or false
.unequal(a, b)
or a != b
true
or false
.true
or false
but these also evaluate to 1 (true) or 0 (false). This can allow you to conditionally assign a value to a variable depending on the evaluation of the comparison. See the code below as an example:if(test, true_result, false_result)
if()
function returns true_result
or false_result
depending on test
.and
operator to test if two comparisons are both true:or
operator to test if one of two comparisons are true:Cirlcle
, the Rectangle
, the Arrow
, the Line
, the Label
, and the Spring
The tools that can be used for analyzing the behavior of your simulations are the Graph
, the Gauge
and the Meter
. There are also user input objects that can be added to your simulations to make them more interactive: the Toggle
, the Slider
, the Input
, and the Menu
controls.Circle
is drawn as a colored circle in the World View. A Circle
has a position, a radius, a color, an opacity, a flag for setting its visibility state, and a flag for determining if a motion map should be attached.Circle
class that shows its default values:Circle(
{pos:[0,0],
radius:10,
color:default_color,
border_size: 0,
border_color: default_color,
border_style: "none"
image: "",
opacity: 1,
visible: true,
motion_map: false,
label: {text: "", color: default_color}
}
)
pos
— The initial position of your Circle
in [X,Y]
coordinates.radius
— The radius of the circle that is drawn in the World View to represent this particle.color
— The circle will be drawn in this color. Use HTML colors e.g. "#ff3300", "blue".border_size
— The border thickness in pixels.border_color
— The border will be drawn in this color. Use HTML colors e.g. "#ff3300", "blue".border_style
— Sets the border as either solid (default = "none") or "dash" for a dashed border, or "dot" for a dotted border.image
— A URL that identifies a JPEG, GIF, SVG or PNG image.opacity
— The circle will be drawn with an opacity between 1 and 0, representing 100% opaque to 100% transparent.visible
— The circle can be hidden from view by setting this flag to false
. motion_map
— This flag tells Tychos to attach a series of strobe images called a motion map.label
- You can attach a label to the Circle
object by indicating a the text
and color
of the label. Circle
after it is created. In particular, one will usually change the pos
attribute of a Circle
in the Calculations editor to show movement. e.g.Circle
objects can be rotated.Circle.rotate(angle=0, axis=[0, 0])
— Rotates the Circle
object by a given angle value in radian units. You can also provide an optional matrix that identifies the axis of rotation. This method should only be called from the Calculations code editor.Circle
objects can also be represented with an image by setting the image attribute of the object. The text must be a URI link to a graphic file that can be a PNG, SVG, GIF, or JPEG image.direction
function as well as the rotate
method:rocket.rotate(direction(rocket.v))
Circle
objects can also be given a text label. This is similar to the Label
object.c.label = {text:"Hello", color:"green"}
— This adds a text label to the Circle
object that scales to fit inside the circle.Ellipse
is drawn as a colored ellipse in the World View. An Ellipse
has a position, a size corresponding to its horizontal radius (x) and vertical radius (y) , a color, an opacity, a flag for setting its visibility state, and a flag for determining if a motion map should be attached.Ellipse
class that shows its default values:Ellipse(
{pos:[0,0],
size:[10,5],
color:default_color,
image: "",
opacity: 1,
visible: true,
motion_map: false,
label: {text: "", color: default_color}
}
)
pos
— The initial position of your Ellipse
in [X,Y]
coordinates.size
— Representing the x radius and y radius of the ellipse that is drawn in the World View.color
— The Ellipse
will be drawn in this color. Use HTML colors e.g. "#ff3300", "blue".border_size
— The border thickness in pixels.border_color
— The border will be drawn in this color. Use HTML colors e.g. "#ff3300", "blue".border_style
— Sets the border as either solid (default = "none") or "dash" for a dashed border, or "dot" for a dotted border.image
— A URL that identifies a JPEG, GIF, SVG or PNG image.opacity
— The Ellipse
will be drawn with an opacity between 1 and 0, representing 100% opaque to 100% transparent.visible
— The Ellipse
can be hidden from view by setting this flag to false
. motion_map
— This flag tells Tychos to attach a series of strobe images called a motion map.label
- You can attach a label to the Ellipse
object by indicating a the text
and color
of the label. Ellipse
after it is created, just like the Circle
. Ellipse
objects can be rotated, just like the Circle.
Ellipse.rotate(angle=0, axis=[0, 0])
— Rotates the Ellipse
object by a given angle value in radian units. You can also provide an optional matrix that identifies the axis of rotation. This method should only be called from the Calculations code editor.Ellipse
objects can also be represented with an image by setting the image attribute of the object. The text must be a URI link to a graphic file that can be a PNG, SVG, GIF, or JPEG image. See the Circle
above for more detail.Ellipse
objects can also be given a text label. This is similar to the Label
object.e.label = {text:"Hello", color:"green"}
— This adds a text label to the Ellipse
object that scales to fit inside the ellipse.Rectangle
is very similar to a Circle
but it is represented as a colored rectangle in the World View. A Rectangle
has position, width, height, color, opacity, visibility, a motion map flag, as well as a label. Just as with the Circle
, Tychos only uses the width and height attributes for display. You can define how these attributes change given the rules of the simulation that you define.Rectangle
class that shows its default values:Rectangle(
{pos:[0,0],
size:[10,10],
color:default_color,
image: "",
opacity: 1,
visible: true,
motion_map: false,
label: {text: "", color: default_color}
}
)
pos
— The initial position of your Rectangle
in [X,Y]
coordinates.size
— The width and height of the Rectangle
that is drawn in the World View to represent this particle.color
— The Rectangle
will be drawn in this color. Use HTML colors e.g. "#ff3300", "blue".border_size
— The border thickness in pixels.border_color
— The border will be drawn in this color. Use HTML colors e.g. "#ff3300", "blue".border_style
— Sets the border as either solid (default = "none") or "dash" for a dashed border, or "dot" for a dotted border.image
— A URL that identifies a JPEG, GIF, SVG or PNG image.opacity
— The Rectangle
will be drawn with an opacity between 1 and 0, representing 100% opaque to 100% transparent.visible
— The Rectangle
can be hidden from view by setting this flag to false
. motion_map
— This flag tells Tychos to attach a series of strobe images called a motion map.label
- You can attach a label to the Rectangle
object by indicating a the text
and color
of the label. Rectangle
object after it is created. In particular, one will usually change the pos
attribute in the Calculations editor to show movement. e.g.Rectangle
object in order to simulate rotational behavior.Rectangle.rotate(angle=0, axis=[0, 0])
— Rotates the Rectangle
object by a given angle value in radian units. You can also provide an optional matrix that identifies the center of rotation. This method should only be called from the Calculations code editor.Circle
objects, Rectangle
objects can also be represented with an image by setting the image attribute of the object.Rectangle
objects can also be given a text label. This is similar to the Label
object.Rectangle
object.Arrow
class represents a graphical arrow and is commonly used to illustrate vectors, but can be used for representing anything in your simulations.Arrow
class that shows its default values:Arrow(
{pos:[0,0],
size:[1,0],
color:default_color,
components: false,
stroke: 1,
style: "none",
opacity: 1,
visible: true,
motion_map: false
}
)
pos
— coordinates for the starting point of the Arrow
as an [X,Y]
matrix.size
— the vector to illustrate, e.g. [10, 0]
will draw an Arrow
10 units to the right.color
— HTML color value for your Arrow
, e.g. "red" or "#ff0000".components
— A flag that determines if X and Y components are drawn, a value of true
displays the components.stroke
— Stroke value that determines the visual thickness of the Arrow
.style
— Sets the arrow line as either solid (default = "none") or "dash" for a dashed arrow, or "dot" for a dotted arrow.opacity
— The Arrow
will be drawn with an opacity between 1 and 0, representing 100% opaque to 100% transparent.visible
— The Arrow
can be hidden from view by setting this flag to false
.motion_map
— This flag tells Tychos to attach a series of strobe images called a motion map.Line
class draws a line and is commonly used to illustrate some connecting member like a string or cable, but could really represent anything you like.Line
class that shows its default values:Line(
{pos:[0,0],
pos2:[1,0],
color:default_color,
stroke: 1,
style: "none",
opacity: 1,
visible: true,
motion_map: false
}
)
pos
— coordinates for the starting point of the Line
as an [X,Y]
matrix.pos2
— coordinates of the termination point of the Line
as an [X,Y]
matrixcolor
— HTML color value for your Line
, e.g. "red" or "#ff0000".stroke
— Stroke value that determines the visual thickness of the Line
. This is measured in pixels.style
— Sets the line as either solid (default = "none") or "dash" for a dashed line, or "dot" for a dotted line.opacity
— The Line
will be drawn with an opacity between 1 and 0, representing 100% opaque to 100% transparent.visible
— The Line
can be hidden from view by setting this flag to false
.motion_map
— This flag tells Tychos to attach a series of strobe images called a motion map.PolyLine
class draws a series of connected lines between a given set of points. This object can be used to represent a complex path or a shape other than a circle or rectangle.PolyLine
class that shows its default values:PolyLine(
{points:[],
color:default_color,
stroke: 1,
style: "none"
fill: false
opacity: 1,
visible: true,
motion_map: false
}
)
points
— an array of points given as [X,Y]
matrices.color
— HTML color value for your PolyLine
, e.g. "red" or "#ff0000".stroke
— Stroke value that determines the visual thickness of the PolyLine
. This is measured in pixels.style
— Can be "none"
for solid segments, "dash"
for dashed line segments or "dot"
for dotted line segments.fill
— Boolean value (true or false) for displaying the PolyLine object as a filled in solid.opacity
— The PolyLine
will be drawn with an opacity between 1 and 0, representing 100% opaque to 100% transparent.visible
— The PolyLine
can be hidden from view by setting this flag to false
.motion_map
— This flag tells Tychos to attach a series of strobe images called a motion map.setPoints: (points)
-> Set the points for the PolyLine given an array of points. translate: (deltaPosition)
-> Move all the points according to a matrix [X, Y]
.rotate: (angle, axis)
-> Transform the points a certain angle measurement about an axis. This axis is relative to the first point in the PolyLine.npoints():
-> Returns the number of points in the PolyLine.append: (point)
-> Add a point to the end of the PolyLine.remove: (n)
-> Remove a point at the given index. The first point is at index = 0.unshift: (point)
-> Add a point at the beginning of the PolyLine.shift: ()
-> Remove the first point in the PolyLine object.splice: (point, n)
-> Add a point into the PolyLine at the specific index position. The first point is at index = 0.drop: (n)
-> Remove all points from the start to the "n" index position from the PolyLine.dropRight: (n)
-> Remove all points from the end of the PolyLine to the "n" index position.last: ()
-> Returns the last point in the PolyLine.first: ()
-> Returns the first point in the PolyLine.replace: (point, n)
-> Replace the point at "n" index position with a new point.clear: ()
-> Remove all the points in the PolyLine.point: (n)
-> Returns the point at that "n" index position.slice: (start, end)
-> Returns the set of points (but does not remove them) from the PolyLine object beginning at the start
value and ending at the end
index position.Spring
is a visual representation of a common elastic connector that displays a given number of coils that dynamically change shape once the dimensions of the Spring
are changed in the Calculations Pane.Spring
class that shows its default values:Spring(
{pos:[0,0],
pos2:[1,0],
color:default_color,
coils: 5,
width: 10,
stroke: 1,
opacity: 1,
visible: true,
motion_map: false
}
)
pos
— coordinates for the starting point of the Spring
as an [X,Y]
matrix.pos2
— coordinates of the termination point of the Spring
as an [X,Y]
matrixcolor
— HTML color value for your Spring
, e.g. "red" or "#ff0000".coils
— The number "coil" zig-zags.width
— The width of the "coil" zig-zags.stroke
— Stroke value that determines the visual thickness of the Spring
. This is measured in pixels.opacity
— The Spring
will be drawn with an opacity between 1 and 0, representing 100% opaque to 100% transparent.visible
— The Spring
can be hidden from view by setting this flag to false
.motion_map
— This flag tells Tychos to attach a series of strobe images called a motion map.Spring
objects above that have different lengths, widths and coil numbers. The Circle
objects are shown just for reference.Spring
is created.Label
class.Label
class that shows its default values:Label(
{pos:[0,0],
size:[10,10],
text: "",
color:default_color,
opacity: 1,
visible: true,
motion_map: false
}
)
pos
— coordinates for the center point of the Label
as an [X,Y]
matrix.size
— The width and height of the Label
as an [X,Y]
matrixtext
— The text of the Label
as a string.color
— HTML color value for your Label
, e.g. "red" or "#ff0000".opacity
— The Label
will be drawn with an opacity between 1 and 0, representing 100% opaque to 100% transparent.visible
— The Label
can be hidden from view by setting this flag to false
.motion_map
— This flag tells Tychos to attach a series of strobe images called a motion map.Label
object is created. Here is an example of how to make several Label
objects:Block
object or a Particle
object, you can rotate a label as shown above:Circle
class.Particle
represents a spherical particle in the simulated world and is drawn as a colored circle in the World View. A particle has position, radius and color.Particle(pos=[0,0], radius=10, color=default_color)
-> returns a Particlepos
— The initial position of your particle in [X,Y] coordinates. If you don't specify a position, the default value of [0,0] is used.radius
— The radius of the circle that is drawn in the World View to represent this particle.color
— The particle will be drawn in this color. Use HTML colors e.g. "#ff3300", "blue".pos
attribute of a particle in the Calculations editor to show a particle's movement. E.g.Particle
objects can be rotated, but it will have no noticeable affect on the object unless you are using an image as a representation of the Particle
.particle.rotate(angle=0, center_of_rotation=[0, 0])
— Rotates the Particle
object by a given angle value in degree units. You can also provide an optional matrix that identifies the center of rotation. This method should only be called from the Calculations code editor.Particle
objects can also be given a text label. This is similar to the Label object.particle.addLabel(text="Hello", color="green")
— This adds a text label to the Particle
object.Rectanlge
class.Block
. A Block
is very similar to a Partcle
but it is represented as a colored rectangle in the World View. A block has position, width, height and color. Just as with Particle's, Tychos only uses the width and height attributes for display. You can define how these attributes change given the rules of the simulation that you define.Block(pos=[0,0], size=[10, 10], color=default_color)
-> returns a Blockpos
— The inital position of your block in [X,Y] coordinates. If you don't specify a position, the default value of [0,0] is used.size
— The width and height of the block that is drawn in the World View to represent the block.color
— The block will be drawn in this color. Use HTML colors e.g. "#ff3300", "blue".pos
attribute of a block in the Calculations editor to show a block's movement. E.g.Block
object in order to simulate rotational behavior.Block.rotate(angle=0, center_of_rotation=[0, 0])
— Rotates the Block
object by a given angle value in degree units. You can also provide an optional matrix that identifies the center of rotation. This method should only be called from the Calculations code editor.Particle
objects, Block
objects can also be represented with an image by setting the image attribute of the object. The text must be a URI link to a graphic file that can be a PNG, SVG, GIF, or JPEG image.Block
objects can also be given a text label. This is similar to the Label
object.block.addLabel(text="Hello", color="green")
— This adds a text label to the Block
object.Graph
is a 2-dimensional chart of data that you specify in the Calculations editor. Each Graph
that is created will appear on the right side of the World View. Your program needs to add points to the graph with the plot
command.Graph
object:Graph({title:"Graph", y_axis:"Y", x_axis:"X"})
-> Returns a Graphtitle
= Optional text that will appear at the top of the graph.y_axis
= Optional text that will appear on the left side of the graph as the vertical axis label.x_axis
= Optional text that will appear at the bottom of the graph as the horizontal axis label.graph.plot(x, y, color=default_color)
— Adds a data point to your graph.graph.integrate(color=default_color)
— When you call the plot
function of a graph, you create a new plot set. You can then integrate this plot set. This is done by referencing the plot set's color. This returns the calculated area based on the trapezoidal method of approximation. BarChart
is a chart of data that is displayed as a set of bars representing an array of data values. Each BarChart
that is created will appear on the right side of the World View.title
= Optional text that will appear at the top of the BarChart.min
= Optional minimum value whose default is 0. If any bar data value is less than this minimum, the bar will be truncated.max
= Optional maximum value whose default is 1. This sets the maximum viewable bar height. If any bar data value is greater than this maximum, the bar will be truncated.barChart.setData(data = [])
— Sets the data values for the bars in the bar chart.barChart.setLabels(["label_one", "label_two", ...])
— Adds a set of labels to the chart - one label corresponding to each data bar in the chart. If the number of labels does not match the number of bars set by the number of data values, then a numbered label will be assigned to the extra data value.barChart.setColors(["color_one", "color_two", ...])
— Adds a set of colors to the chart - one color corresponding to each data bar in the chart. If the number of colors does not match the number of bars set by the number of data values, then any extra bars will be given the default HTML color of #aaa
.Meter
is a numeric display of data that you specify in the Calculations editor. Each Meter
that is created will appear on the left side of the World View. Your program needs to tell the Meter
what value it needs to display by using the display
command.Meter
widget and default values:Meter({title:"Meter", color:default_color})
title
= Optional text that will appear at the top of the Gauge
widget.color
— HTML color value for your Gauge
, e.g. "red" or "#ff0000".meter.display(value, units)
— Displays the value on the Meter.value
= Numeric value to be displayed.units
= Optional string representing the unit label to be displayed.