Ocelot Libraries Documentation
Documentation Table of Contents
Description:
The newCanvas function is creates a blank white canvas and displays it in Ocelot
Syntax:
newCanvas(width, height)
Parameters:
Width(number) - the width of the desired canvas
Height(number) - the height of the desired canvas
Return Value:
Width and Height of the canvas
Example:
Description:
The drawLine function draws a line on the canvas that stretches from a designated start point to a designated endpoint.
Syntax:
drawingCanvas.drawLine(x1, y1, x2, y2, color)
Parameters:
drawingCanvas - The canvas you wish to draw the line on
x1(number) - The location on the x-axis of the desired start point of the line
y1(number) - The location on the y-axis of the desired start point of the line
x2(number) - The location on the x-axis of the desired end point of the line
y2(number) - The location on the y-axis of the desired end point of the line
color(number) - The desired color of the line given as a tri-color pixel
Return Value:
N/A
Example:
Description:
The drawArc function draws an arc of a designated color centered at a given point with a given radius. The function will start drawing the arc from the location startRadians to the location end Radians in a clockwise direction.
Syntax:
drawingCanvas.drawArc(x, y, radius, startRadians,endRadians, color)
Parameters:
drawingCanvas - The canvas you wish to draw the arc on
x(number) - The location on the x-axis of the center of the desired arc
y(number) - The location on the y-axis of the center of the desired arc
radius(number) - The size of the radius of the desired arc
startRadians(number) - The location on the unit circle of the start of the arc
endRadians(number) - The location on the unit circle of the end of the arc
color(number) - The desired color of the arc given as a tri-color pixel
Return Value:
N/A
Example:
Description:
The drawCircle function draws a circle of a designated color centered at a given point with a given radius.
Syntax:
drawingCanvas.drawCircle(x, y, radius, color)
Parameters:
drawingCanvas - The canvas you wish to draw the circle on
x(number) - The location on the x-axis of the center of the desired arc
y(number) - The location on the y-axis of the center of the desired arc
radius(number) - The size of the radius of the desired arc
color(number) - The desired color of the arc given as a tri-color pixel
Return Value:
N/A
Example:
Description:
The drawFilledCircle function draws a circle of a designated color centered at a given point with a given radius.
Syntax:
drawingCanvas.drawFilledCircle(x, y, radius, color)
Parameters:
drawingCanvas - The canvas you wish to draw the circle on
x(number) - The location on the x-axis of the center of the desired arc
y(number) - The location on the y-axis of the center of the desired arc
radius(number) - The size of the radius of the desired arc
color(number) - The desired color of the arc given as a tri-color pixel
Return Value:
N/A
Example:
Description:
The clear function clears the canvas.
Syntax:
drawingCanvas.clear()
Parameters:
drawingCanvas - The canvas you wish to clear
Return Value:
N/A
Example:
Description:
The getPixel function is designed to access and get rgb channel data from a specified (i,j) location in an image. You can not directly change the value of the accessed pixel using getPixel
Syntax:
image.getPixel(i,j)
Parameters:
Image - the image in which you would like to access a specific value
(i,j) - the location of the pixel in the image
Return Value:
A pixel with values between 0 and 1 for each rgb channel
Example:
Description:
The setPixel function is designed to access and alter rgb channel data from a specified (i,j) location in an image. You can directly change the value of the accessed pixel using setPixel by inputting a new pixel value.
Syntax:
image.setPixel(i,j,[r,g,b])
Parameters:
Image - the image in which you would like to access a specific value
(i,j) - the location of the pixel in the image
[r,g,b] - the desired pixel values between 0 and 1 for the rgb channels
Return Value:
N/A
Example:
Description:
The loadImageFromURL function imports an image to the workspace from a given url.
Syntax:
loadImageFromURL(url)
Parameters:
Url - web link containing the storage location and data of a desired image.
Return Value:
Width and Height of the image as well as the names of the various functions that can affect an image( i.e copy, show, setPixel, getPixel)
Example:
Description:
The createImage function will create a new image with a desired width, height, and fill of desired rgb channel pixel values.
Syntax:
createImage(width, height,[r,g,b])
Parameters:
Width - the width of the desired image
Height - the height of the desired image
[r,g,b] - the desired pixel values between 0 and 1 for the rgb channels
Return Value:
Width and Height of the new image as well as the names of the various functions that can affect an image( i.e copy, show, setPixel, getPixel)
Example:
Description:
The copy function will create a deep copy of a specified image
Syntax:
image.copy()
Parameters:
Image - the image which you would like make a deep copy of
Return Value:
Width and Height of the copied image as well as the names of the various functions that can affect an image( i.e copy, show, setPixel, getPixel)
Example:
Description:
The show function will display a desired image on the canvas
Syntax:
image.show()
Parameters:
Image - the image which you would like display
Return Value:
N/A
Example:
Description:
The test function defines a test
Syntax:
test(description, function)
Parameters:
Description - A description of what is being tested. It will be printed when that particular test fails
Function - The function that is run when that paricular test is run
Return Value:
n/a
Example: See below
Description:
The assert function is meant to be used within a test. It throws an exception if its input boolean value is false.
Syntax:
assert(booleanVal)
Parameters:
booleanVal - boolean value that you are checking
Return Value:
True if booleanVal is true otherwise throws an exception
Example:
Description:
loadJSONFromURL loads a JSON file from a given URL and returns the JSON file as a JavaScript object
Syntax:
loadJSONFromURL(url)
Parameters:
Url - the url that directs to plain JSON text
Return Value:
An object that represents that JSON file
Example:
Description:
getProperty takes in a parsed JSON object and the string name of an object member and returns another object. The returned object has two member variables, found and value, to indicate whether the property with the specified string was found in the object or not, and if so, to return its value.
Syntax:
getProperty(object, prop)
Parameters:
Object - object to get the property from
Prop - a string that refers to the property of object
Return Value:
An object object has two member variables, found and value, to indicate whether the property with the specified string was found in the object or not, and if so, to return its value.
Example:
Description:
setProperty takes in an object, prop and value, mutating the object in place by either adding a prop-value entry in the object, or changing an existing entry’s value with the given value. It does not return anything.
Syntax:
setProperty(object, prop, value)
Parameters:
Object - object to set the property of
Prop - a string for the key of the entry
Value - the value an entry would have
Return Value:
undefined
Example:
Description:
Prompts for user input
Syntax:
input(message)
Parameters:
Message - message displayed when prompting for user input
Return Value:
Returns user input as a string, if no user input is given then it returns an empty string
Example:
Description:
Pauses the program for the specified amount of time
Syntax:
sleep(time)
Parameters:
time - the amount of time in milleseconds for which to pause the program
Return Value:
N/A
Example:
There are a few additional libraries that are loaded in Ocelot.
Note that this Array class is different from the default Array class. We have provided a static function: Array.create(length, value) - It creates an array of a given length with each index filled with a given value.