Skip to content

Library documentation & update #686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jul 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The Source Academy is a gamified platform designed to teach students coding whil
### Installation
1. Install a stable version of NodeJS (tested: Node 10.15.0).
2. Run `npm install` to install dependencies.
3. Copy the `.env.example` file as `.env` and set the necessary variables (refer to docs/contributing for more information)
3. Copy the `.env.example` file as `.env` and set the necessary variables (refer below for more information)
4. Run `npm start` to start the server at `localhost:8075`.

### Setting up your environment
Expand Down
3 changes: 3 additions & 0 deletions public/externalLibs/graphics/CURVES_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Graphic Library

Curve-producing library for Source Academy.
3 changes: 0 additions & 3 deletions public/externalLibs/graphics/README.md

This file was deleted.

15 changes: 15 additions & 0 deletions public/externalLibs/graphics/RUNES_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
RUNES is a library for realising the picture language of
<a href="https://sicp.comp.nus.edu.sg/chapters/33">section
2.2.4 Example: A Picture Language</a>
of the textbook
<a href="https://sicp.comp.nus.edu.sg">Structure and Interpretation
of Computer Programs, JavaScript Adaptation</a> (SICP JS).
It provides primitive values, called runes, such
as `heart` and `circle`, operations such as `beside`
to construct more complex runes from simpler ones, and ways
to display runes, in two-dimensional and three-dimensional
space.

On the right, you see all predeclared names of the RUNES library,
in alphabetical
order. Click on a name to see how it is defined and used.
2 changes: 1 addition & 1 deletion public/externalLibs/graphics/gl-matrix.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* @fileoverview gl-matrix - High performance matrix and vector operations
* @author Brandon Jones
* @author Colin MacKenzie IV
Expand Down
99 changes: 96 additions & 3 deletions public/externalLibs/graphics/webGLcurve.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,50 +64,143 @@ function generateCurve(scaleMode, drawMode, numPoints, func, isFullView) {
return new ShapeDrawn()
}

/**
* returns a function that turns a given Curve into a Drawing,
* by sampling the Curve at <CODE>num</CODE> sample points
* and connecting each pair with a line.
* When a program evaluates to a Drawing, the Source system
* displays it graphically, in a window, instead of textually.
* The parts between (0,0) and (1,1) of the resulting Drawing
* are shown in the window.
* @param {number} num - determines the number of points to be
* sampled. Including 0 and 1,
* there are <CODE>num + 1</CODE> evenly spaced sample points.
* @return {function} function from Curves to Drawings.
*/
function draw_connected(num) {
return function(func) {
return generateCurve('none', 'lines', num, func)
}
}

/**
* returns a function that turns a given Curve into a Drawing,
* by sampling the Curve at <CODE>num</CODE> sample points.
* The Drawing consists of isolated points, and does not connect them.
* When a program evaluates to a Drawing, the Source system
* displays it graphically, in a window, instead of textually.
* The parts between (0,0) and (1,1) of the resulting Drawing
* are shown in the window.
* @param {number} num - determines the number of points to be
* sampled. Including 0 and 1,
* there are <CODE>num + 1</CODE> evenly spaced sample points.
* @return {function} function from Curves to Drawings.
*/
function draw_points_on(num) {
return function(func) {
return generateCurve('none', 'points', num, func)
}
return curve =>
generateCurve('none', 'points', num, curve)
}

/**
* returns a function that turns a given Curve into a Drawing,
* by sampling the Curve at <CODE>num</CODE> sample points.
* The Drawing consists of isolated points, and does not connect them.
* When a program evaluates to a Drawing, the Source system
* displays it graphically, in a window, instead of textually.
* The Drawing is squeezed such that all its parts are shown in the
* window.
* @param {number} num - determines the number of points to be
* sampled. Including 0 and 1,
* there are <CODE>num + 1</CODE> evenly spaced sample points.
* @return {function} function from Curves to Drawings.
*/
function draw_points_squeezed_to_window(num) {
return function(func) {
return generateCurve('fit', 'points', num, func)
}
}

/**
* returns a function that turns a given Curve into a Drawing,
* by sampling the Curve at <CODE>num</CODE> sample points
* and connecting each pair with a line.
* When a program evaluates to a Drawing, the Source system
* displays it graphically, in a window, instead of textually.
* The Drawing is squeezed such that all its parts are shown in the
* window.
* @param {number} num - determines the number of points to be
* sampled. Including 0 and 1,
* there are <CODE>num + 1</CODE> evenly spaced sample points.
* @return {function} function from Curves to Drawings.
*/
function draw_connected_squeezed_to_window(num) {
return function(func) {
return generateCurve('fit', 'lines', num, func)
}
}

/**
* returns a function that turns a given Curve into a Drawing,
* by sampling the Curve at <CODE>num</CODE> sample points
* and connecting each pair with a line.
* When a program evaluates to a Drawing, the Source system
* displays it graphically, in a window, instead of textually.
* The Drawing is stretched or shrunk
* to show the full curve and maximize its width and height.
* @param {number} num - determines the number of points to be
* sampled. Including 0 and 1,
* there are <CODE>num + 1</CODE> evenly spaced sample points.
* @return {function} function from Curves to Drawings.
*/
function draw_connected_full_view(num) {
return function(func) {
return generateCurve('stretch', 'lines', num, func, true)
}
}

/**
* returns a function that turns a given Curve into a Drawing,
* by sampling the Curve at <CODE>num</CODE> sample points
* and connecting each pair with a line.
* When a program evaluates to a Drawing, the Source system
* displays it graphically, in a window, instead of textually.
* The Drawing is scaled proportionally to show the full curve
* and maximize its size.
* @param {number} num - determines the number of points to be
* sampled. Including 0 and 1,
* there are <CODE>num + 1</CODE> evenly spaced sample points.
* @return {function} function from Curves to Drawings.
*/
function draw_connected_full_view_proportional(num) {
return function(func) {
return generateCurve('fit', 'lines', num, func, true)
}
}

/**
* makes a Point with given x and y coordinates
* @param {number} x - x-coordinate of new point
* @param {number} y - y-coordinate of new point
* @returns {Point} with x and y as coordinates
*/
function make_point(x, y) {
return [x, y]
}

/**
* retrieves the x-coordinate a given Point
* @param {Point} p - given point
* @returns {number} x-coordinate of the Point
*/
function x_of(pt) {
return pt[0]
}

/**
* retrieves the y-coordinate a given Point
* @param {Point} p - given point
* @returns {number} y-coordinate of the Point
*/
function y_of(pt) {
return pt[1]
}
2 changes: 1 addition & 1 deletion public/externalLibs/graphics/webGLgraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ function resetCanvas() {
}
}

/**
/*
* Gets the WebGL object (gl) ready for usage. Use this
* to reset the mode of rendering i.e to change from 2d to 3d runes.
*
Expand Down
Loading