Index: native_client_sdk/src/gonacl_appengine/static/pnacl-demo-smoothlife/example.js |
diff --git a/native_client_sdk/src/gonacl_appengine/static/pnacl-demo-smoothlife/example.js b/native_client_sdk/src/gonacl_appengine/static/pnacl-demo-smoothlife/example.js |
index 5171d330b0c3433f6f4484b1148838dc8af0ae55..c6c6a215ae61687c8435e699270151541b4c6984 100644 |
--- a/native_client_sdk/src/gonacl_appengine/static/pnacl-demo-smoothlife/example.js |
+++ b/native_client_sdk/src/gonacl_appengine/static/pnacl-demo-smoothlife/example.js |
@@ -132,6 +132,9 @@ function moduleDidLoad() { |
bar.max = 100; |
naclModule = $('nacl_module'); |
hideStatus(); |
+ setSize(256); |
+ setThreadCount(4); |
+ setMaxScale(1); |
loadPreset(0); |
} |
@@ -202,10 +205,19 @@ function attachListeners() { |
}); |
} |
+/** |
+ * Load the current preset from the select element with id "preset". |
+ */ |
function loadSelectedPreset() { |
loadPreset($('preset').value); |
} |
+/** |
+ * Set the SmoothLife parameters from a preset, indexing into the |presets| |
+ * global above. |
+ * |
+ * @param {number} index into |presets| variable. |
+ */ |
function loadPreset(index) { |
var preset = presets[index]; |
@@ -216,10 +228,59 @@ function loadPreset(index) { |
splat(); |
} |
+/** |
+ * Clear the SmoothLife buffer with a given number value, between 0 and 1. |
+ * |
+ * @param {number} color The clear value. |
+ */ |
function clear(color) { |
naclModule.postMessage({cmd: 'clear', color: color}); |
} |
+/** |
+ * Set the size of the SmoothLife buffer. |
+ * |
+ * @param {number} size The width and height of the new buffer. Currently it |
+ * must be one of 256, 384 or 512. |
+ */ |
+function setSize(size) { |
+ naclModule.postMessage({cmd: 'setSize', size: size}); |
+} |
+ |
+/** |
+ * Set the maximum scale factor when drawing the SmoothLife buffer to the |
+ * Graphics2D canvas. If the buffer would have to scale past this factor, it |
+ * will tile instead. |
+ * |
+ * For example, if the buffer is 256x256, and the canvas is 1024x512, and the |
+ * max scale factor is 1, then the buffer will be tiled 8 times: 4 in the top |
+ * row and 4 in the bottom row. |
+ * |
+ * @param {number} scale The maximum scale, |
+ */ |
+function setMaxScale(scale) { |
+ naclModule.postMessage({cmd: 'setMaxScale', scale: scale}); |
+} |
+ |
+/** |
+ * Set the number of threads to use for calls to FFTW. |
+ * |
+ * @param {number} threadCount The number of threads to use. Must be >= 1. |
+ */ |
+function setThreadCount(threadCount) { |
+ naclModule.postMessage({cmd: 'setThreadCount', threadCount: threadCount}); |
+} |
+ |
+ |
+/** |
+ * Set the "kernel" of the SmoothLife calculations. Please read the SmoothLife |
+ * paper for more information. |
+ * |
+ * @param {number} discRadius The radius of the kernel "disc" (the inner part). |
+ * @param {number} ringRadius The radius of the kernel "ring" (surrounds the |
+ * disc). |
+ * @param {number} blendRadius The amount of blending between the disc and ring. |
+ */ |
function setKernel(discRadius, ringRadius, blendRadius) { |
naclModule.postMessage({ |
cmd: 'setKernel', |
@@ -228,6 +289,22 @@ function setKernel(discRadius, ringRadius, blendRadius) { |
blendRadius: blendRadius}); |
} |
+/** |
+ * Set the "smoother" of the SmoothLife calculations. Please read the |
+ * SmoothLife paper for more information. |
+ * |
+ * @param {number} type A timestep type, in the range [0,4]. |
+ * @param {number} dt A positive real timestep delta. Only used if type > 0. |
+ * @param {number} b1 A positive real, used to parameterize the smoother curve |
+ * @param {number} d1 A positive real, used to parameterize the smoother curve |
+ * @param {number} b2 A positive real, used to parameterize the smoother curve |
+ * @param {number} d2 A positive real, used to parameterize the smoother curve |
+ * @param {number} mode A sigmoid combination function, in the range [0,3]. |
+ * @param {number} sigmoid A sigmoid function, in the range [0,4]. |
+ * @param {number} mix Another sigmoid function, in the range [0,4]. |
+ * @param {number} sn A positive real, used to parameterize the smoother curve |
+ * @param {number} sm A positive real, used to parameterize the smoother curve |
+ */ |
function setSmoother(type, dt, b1, d1, b2, d2, mode, sigmoid, mix, sn, sm) { |
naclModule.postMessage({ |
cmd: 'setSmoother', |
@@ -237,6 +314,29 @@ function setSmoother(type, dt, b1, d1, b2, d2, mode, sigmoid, mix, sn, sm) { |
sn: sn, sm: sm}); |
} |
+/** |
+ * Set the palette used to draw the buffer, mapping a value from [0,1] to a |
+ * RGBA value. |
+ * |
+ * The first argument (arguments[0]) is either 0 or 1: |
+ * 0: Any color outside of the range is clamped to the closest color in the |
+ * range. |
+ * 1: The palette cycles for any values not in the given range. |
+ * |
+ * The rest of the arguments are pairs of (color, stop). |
+ * |
+ * |color| is a string in standard HTML/CSS format, like "#ff00ff". It does not |
+ * support abbreviations ('#fff'). |
+ * |
+ * |stop| is a number in the range [0, 100]. Any value that is not exactly on a |
+ * stop will be interpolated between the closest two stops. |
+ * |
+ * For example, if there are two stops ('#000000', 0) and ('#808080', 50), |
+ * then the buffer value 0.25 will map to the color '#404040'. |
+ * |
+ * If |repeating| is 0, then the buffer value 0.75 will map to '#808080'. |
+ * If |repeating| is 1, then the buffer value 0.75 will map to '#404040'. |
+ */ |
function setPalette() { |
var repeating = arguments[0] !== 0; |
var colors = [] |
@@ -252,10 +352,20 @@ function setPalette() { |
stops: stops}); |
} |
+/** |
+ * Draw a bunch of random circles in the SmoothLife buffer. |
+ */ |
function splat() { |
naclModule.postMessage({cmd: 'splat'}); |
} |
+/** |
+ * Change the size and color of the mouse "brush", when drawing on the canvas. |
+ * |
+ * @param {number} radius The radius of the brush in buffer units. See setSize() |
+ * @param {number} color The "color" of the brush, in the range [0, 1]. This is |
+ * actually not a color, but a value to draw into the buffer. |
+ */ |
function setBrushSize(radius, color) { |
naclModule.postMessage({cmd: 'setBrush', radius: radius, color: color}); |
} |