Skip to content

Commit

Permalink
adding traverse method #5 + some minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
azeem committed Nov 4, 2013
1 parent 6777677 commit dd160dc
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
doc
node_modules
.idea
build
Expand Down
8 changes: 4 additions & 4 deletions examples/JelloCube.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,18 @@
}
]
};

var webvsMain;
window.onload = function () {
// initialize dancer and webvs
var clientId = "e818e8c85bb8ec3e90a9bbca23ca5e2a";
var dancer = new Dancer();
var webvs = new Webvs.Main({
webvsMain = new Webvs.Main({
canvas: document.getElementById("canvas"),
analyser: new Webvs.DancerAdapter(dancer),
showStat: true
});
webvs.loadPreset(samplePreset);
webvs.start();
webvsMain.loadPreset(samplePreset);
webvsMain.start();

// load and play the track
/*dancer.load({
Expand Down
7 changes: 4 additions & 3 deletions examples/PilloFight.html
Original file line number Diff line number Diff line change
Expand Up @@ -357,17 +357,18 @@
]
};

var webvsMain;
window.onload = function () {
// initialize dancer and webvs
var clientId = "e818e8c85bb8ec3e90a9bbca23ca5e2a";
var dancer = new Dancer();
var webvs = new Webvs.Main({
webvsMain = new Webvs.Main({
canvas: document.getElementById("canvas"),
analyser: new Webvs.DancerAdapter(dancer),
showStat: true
});
webvs.loadPreset(samplePreset);
webvs.start();
webvsMain.loadPreset(samplePreset);
webvsMain.start();

// load and play the track
/*dancer.load({
Expand Down
7 changes: 4 additions & 3 deletions examples/SilkString.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,18 @@
]
};

var webvsMain
window.onload = function () {
// initialize dancer and webvs
var clientId = "e818e8c85bb8ec3e90a9bbca23ca5e2a";
var dancer = new Dancer();
var webvs = new Webvs.Main({
webvsMain = new Webvs.Main({
canvas: document.getElementById("canvas"),
analyser: new Webvs.DancerAdapter(dancer),
showStat: true
});
webvs.loadPreset(samplePreset);
webvs.start();
webvsMain.loadPreset(samplePreset);
webvsMain.start();

// load and play the track
/*dancer.load({
Expand Down
7 changes: 4 additions & 3 deletions examples/SuperscopeScience.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,18 @@
]
};

var webvsMain
window.onload = function () {
// initialize dancer and webvs
var clientId = "e818e8c85bb8ec3e90a9bbca23ca5e2a";
var dancer = new Dancer();
var webvs = new Webvs.Main({
webvsMain = new Webvs.Main({
canvas: document.getElementById("canvas"),
analyser: new Webvs.DancerAdapter(dancer),
showStat: true
});
webvs.loadPreset(samplePreset);
webvs.start();
webvsMain.loadPreset(samplePreset);
webvsMain.start();

// load and play the track
var trackUrl = "https://soundcloud.com/kartell/atwater";
Expand Down
4 changes: 2 additions & 2 deletions src/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Webvs.Promise = Webvs.defineClass(Promise, Object, {
/**
* resolves the promise object and runs all
* the callbacks
* @memberof Webvs.Promise
* @memberof Webvs.Promise#
*/
resolve: function() {
if(!this.resolved) {
Expand All @@ -165,7 +165,7 @@ Webvs.Promise = Webvs.defineClass(Promise, Object, {
* register a callback which should be called
* when the promise resolves
* @param {function} cb - callback
* @memberof Webvs.Promise
* @memberof Webvs.Promise#
*/
onResolve : function(cb) {
if(this.resolved) {
Expand Down
26 changes: 26 additions & 0 deletions src/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,34 @@ Webvs.Container = Webvs.defineClass(Container, Webvs.Component, {
options.components.push(this.components[i].getOptions());
}
return options;
},

/**
* Traverses a callback over this subtree, starting with this container
* @param {Webvs.Container~traverseCallback} callback - callback.
* @memberof Webvs.Container#
*/
traverse: function(callback) {
callback.call(this, this.id, (this.parent?this.parent.id:undefined), this.options);
_.each(this.components, function(component) {
if(component instanceof Container) {
component.traverse(callback);
} else {
var parentId = component.parent?component.parent.id:undefined;
var id = component.id;
var options = component.options;
callback.call(component, id, parentId, options);
}
});
}

/**
* This function is called once for each component in the tree
* @callback Webvs.Container~traverseCallback
* @param {string} id - id of the component
* @param {string} parentId - id of the parent. Undefined for root
* @param {object} options - the options for this component.
*/
});

/**
Expand Down
17 changes: 17 additions & 0 deletions src/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,24 @@ Webvs.Main = Webvs.defineClass(Main, Object, {
*/
setResource: function(name, data) {
this.resources[name] = data;
},

/**
* Traverses a callback over the component tree
* @param {Webvs.Main~traverseCallback} callback - callback.
* @memberof Webvs.Main#
*/
traverse: function(callback) {
this.rootComponent.traverse(callback);
}

/**
* This function is called once for each component in the tree
* @callback Webvs.Main~traverseCallback
* @param {string} id - id of the component
* @param {string} parentId - id of the parent. Undefined for root
* @param {object} options - the options for this component.
*/
});

Main.ui = {
Expand Down
3 changes: 1 addition & 2 deletions src/trans/Convolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function ConvolutionProgram(kernel, kernelSize, edgeMode, scale, bias) {
if(value === 0) {
continue;
}
colorSumEq.push("pos = corn + texel * vec2("+(i-mid)+","+(j-mid)+");");
colorSumEq.push("pos = v_position + texel * vec2("+(i-mid)+","+(j-mid)+");");
colorSumEq.push(edgeFunc);
colorSumEq.push("colorSum += texture2D(u_srcTexture, pos) * "+Webvs.glslFloatRepr(value)+";");
}
Expand All @@ -147,7 +147,6 @@ function ConvolutionProgram(kernel, kernelSize, edgeMode, scale, bias) {
fragmentShader: [
"void main() {",
" vec2 texel = 1.0/(u_resolution-vec2(1,1));",
" vec2 corn = floor(v_position/texel)*texel;",
" vec2 pos;",
" vec4 colorSum = vec4(0,0,0,0);",
colorSumEq.join("\n"),
Expand Down

0 comments on commit dd160dc

Please sign in to comment.