house cleaning

This commit is contained in:
Jono Brandel 2011-02-11 11:25:33 -08:00
commit 6a2903681d
12 changed files with 1257 additions and 1248 deletions

View File

@ -1,39 +1,39 @@
GUI.BooleanController = function() { GUI.BooleanController = function() {
this.type = "boolean"; this.type = "boolean";
GUI.Controller.apply(this, arguments); GUI.Controller.apply(this, arguments);
var _this = this; var _this = this;
var input = document.createElement('input'); var input = document.createElement('input');
input.setAttribute('type', 'checkbox'); input.setAttribute('type', 'checkbox');
this.domElement.addEventListener('click', function(e) { this.domElement.addEventListener('click', function(e) {
input.checked = !input.checked; input.checked = !input.checked;
e.preventDefault(); e.preventDefault();
_this.setValue(input.checked); _this.setValue(input.checked);
}, false); }, false);
input.addEventListener('mouseup', function(e) { input.addEventListener('mouseup', function(e) {
input.checked = !input.checked; // counteracts default. input.checked = !input.checked; // counteracts default.
}, false); }, false);
this.domElement.style.cursor = "pointer"; this.domElement.style.cursor = "pointer";
this.propertyNameElement.style.cursor = "pointer"; this.propertyNameElement.style.cursor = "pointer";
this.domElement.appendChild(input); this.domElement.appendChild(input);
this.updateDisplay = function() { this.updateDisplay = function() {
input.checked = _this.getValue(); input.checked = _this.getValue();
}; };
this.setValue = function(val) { this.setValue = function(val) {
if (typeof val != "boolean") { if (typeof val != "boolean") {
try { try {
val = eval(val); val = eval(val);
} catch (e) {} } catch (e) {}
} }
return GUI.Controller.prototype.setValue.call(this, val); return GUI.Controller.prototype.setValue.call(this, val);
} };
}; };
GUI.extendController(GUI.BooleanController); GUI.extendController(GUI.BooleanController);

View File

@ -1,30 +1,29 @@
GUI.FunctionController = function() { GUI.FunctionController = function() {
this.type = "function"; this.type = "function";
var _this = this; var _this = this;
GUI.Controller.apply(this, arguments); GUI.Controller.apply(this, arguments);
this.domElement.addEventListener('click', function() { this.domElement.addEventListener('click', function() {
_this.fire(); _this.fire();
}, false); }, false);
this.domElement.style.cursor = "pointer"; this.domElement.style.cursor = "pointer";
this.propertyNameElement.style.cursor = "pointer"; this.propertyNameElement.style.cursor = "pointer";
var fireFunction = null; var fireFunction = null;
this.onFire = function(fnc) { this.onFire = function(fnc) {
fireFunction = fnc; fireFunction = fnc;
return this; return this;
} }
this.fire = function() { this.fire = function() {
if (fireFunction != null) { if (fireFunction != null) {
fireFunction.call(this); fireFunction.call(this);
} }
_this.object[_this.propertyName].call(_this.object); _this.object[_this.propertyName].call(_this.object);
}; };
}; };
GUI.extendController(GUI.FunctionController); GUI.extendController(GUI.FunctionController);

View File

@ -1,96 +1,97 @@
GUI.Controller = function() { GUI.Controller = function() {
this.parent = arguments[0]; this.parent = arguments[0];
this.object = arguments[1]; this.object = arguments[1];
this.propertyName = arguments[2]; this.propertyName = arguments[2];
if (arguments.length > 0) this.initialValue = this.propertyName[this.object]; if (arguments.length > 0) this.initialValue = this.propertyName[this.object];
this.domElement = document.createElement('div'); this.domElement = document.createElement('div');
this.domElement.setAttribute('class', 'guidat-controller ' + this.type); this.domElement.setAttribute('class', 'guidat-controller ' + this.type);
this.propertyNameElement = document.createElement('span'); this.propertyNameElement = document.createElement('span');
this.propertyNameElement.setAttribute('class', 'guidat-propertyname'); this.propertyNameElement.setAttribute('class', 'guidat-propertyname');
this.name(this.propertyName); this.name(this.propertyName);
this.domElement.appendChild(this.propertyNameElement); this.domElement.appendChild(this.propertyNameElement);
GUI.makeUnselectable(this.domElement); GUI.makeUnselectable(this.domElement);
}; };
GUI.Controller.prototype.changeFunction = null; GUI.Controller.prototype.changeFunction = null;
GUI.Controller.prototype.finishChangeFunction = null; GUI.Controller.prototype.finishChangeFunction = null;
GUI.Controller.prototype.name = function(n) { GUI.Controller.prototype.name = function(n) {
this.propertyNameElement.innerHTML = n; this.propertyNameElement.innerHTML = n;
return this; return this;
}; };
GUI.Controller.prototype.reset = function() { GUI.Controller.prototype.reset = function() {
this.setValue(this.initialValue); this.setValue(this.initialValue);
return this; return this;
}; };
GUI.Controller.prototype.listen = function() { GUI.Controller.prototype.listen = function() {
this.parent.listenTo(this); this.parent.listenTo(this);
return this; return this;
} };
GUI.Controller.prototype.unlisten = function() { GUI.Controller.prototype.unlisten = function() {
this.parent.unlistenTo(this); // <--- hasn't been tested yet this.parent.unlistenTo(this); // <--- hasn't been tested yet
return this; return this;
} };
GUI.Controller.prototype.setValue = function(n) { GUI.Controller.prototype.setValue = function(n) {
this.object[this.propertyName] = n; this.object[this.propertyName] = n;
if (this.changeFunction != null) { if (this.changeFunction != null) {
this.changeFunction.call(this, n); this.changeFunction.call(this, n);
} }
this.updateDisplay(); this.updateDisplay();
return this; return this;
} };
GUI.Controller.prototype.getValue = function() { GUI.Controller.prototype.getValue = function() {
return this.object[this.propertyName]; return this.object[this.propertyName];
} };
GUI.Controller.prototype.updateDisplay = function() {};
GUI.Controller.prototype.updateDisplay = function() {}
GUI.Controller.prototype.onChange = function(fnc) { GUI.Controller.prototype.onChange = function(fnc) {
this.changeFunction = fnc; this.changeFunction = fnc;
return this; return this;
} };
GUI.Controller.prototype.onFinishChange = function(fnc) { GUI.Controller.prototype.onFinishChange = function(fnc) {
this.finishChangeFunction = fnc; this.finishChangeFunction = fnc;
return this; return this;
} };
GUI.Controller.prototype.options = function() { GUI.Controller.prototype.options = function() {
var _this = this; var _this = this;
var select = document.createElement('select'); var select = document.createElement('select');
if (arguments.length == 1) { if (arguments.length == 1) {
var arr = arguments[0]; var arr = arguments[0];
for (var i in arr) { for (var i in arr) {
var opt = document.createElement('option'); var opt = document.createElement('option');
opt.innerHTML = i; opt.innerHTML = i;
opt.setAttribute('value', arr[i]); opt.setAttribute('value', arr[i]);
select.appendChild(opt); select.appendChild(opt);
} }
} else { } else {
for (var i = 0; i < arguments.length; i++) { for (var i = 0; i < arguments.length; i++) {
var opt = document.createElement('option'); var opt = document.createElement('option');
opt.innerHTML = arguments[i]; opt.innerHTML = arguments[i];
opt.setAttribute('value', arguments[i]); opt.setAttribute('value', arguments[i]);
select.appendChild(opt); select.appendChild(opt);
} }
} }
select.addEventListener('change', function() { select.addEventListener('change', function() {
_this.setValue(this.value); _this.setValue(this.value);
if (_this.finishChangeFunction != null) { if (_this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue()); _this.finishChangeFunction.call(this, _this.getValue());
} }
}); }, false);
_this.domElement.appendChild(select); _this.domElement.appendChild(select);
return this; return this;
} };

View File

@ -1,150 +1,152 @@
GUI.NumberController = function() { GUI.NumberController = function() {
this.type = "number"; this.type = "number";
GUI.Controller.apply(this, arguments); GUI.Controller.apply(this, arguments);
var _this = this; var _this = this;
// If we simply click and release a number field, we want to highlight it. // If we simply click and release a number field, we want to highlight it.
// This variable keeps track of whether or not we've dragged // This variable keeps track of whether or not we've dragged
var draggedNumberField = false; var draggedNumberField = false;
var clickedNumberField = false; var clickedNumberField = false;
var y = py = 0; var y = 0, py = 0;
var min = arguments[3]; var min = arguments[3];
var max = arguments[4]; var max = arguments[4];
var step = arguments[5]; var step = arguments[5];
if (!step) { if (!step) {
if (min != undefined && max != undefined) { if (min != undefined && max != undefined) {
step = (max-min)*0.01; step = (max-min)*0.01;
} else { } else {
step = 1; step = 1;
} }
} }
var numberField = document.createElement('input'); var numberField = document.createElement('input');
numberField.setAttribute('id', this.propertyName); numberField.setAttribute('id', this.propertyName);
numberField.setAttribute('type', 'text'); numberField.setAttribute('type', 'text');
numberField.setAttribute('value', this.getValue()); numberField.setAttribute('value', this.getValue());
if (step) numberField.setAttribute('step', step); if (step) numberField.setAttribute('step', step);
this.domElement.appendChild(numberField); this.domElement.appendChild(numberField);
var slider; var slider;
if (min != undefined && max != undefined) { if (min != undefined && max != undefined) {
slider = new GUI.Slider(this, min, max, step, this.getValue()); slider = new GUI.Slider(this, min, max, step, this.getValue());
this.domElement.appendChild(slider.domElement); this.domElement.appendChild(slider.domElement);
} }
numberField.addEventListener('blur', function(e) { numberField.addEventListener('blur', function(e) {
var val = parseFloat(this.value); var val = parseFloat(this.value);
console.log(val);
if (!isNaN(val)) { if (!isNaN(val)) {
_this.setValue(val); _this.setValue(val);
} }
}, false); }, false);
numberField.addEventListener('mousewheel', function(e) { numberField.addEventListener('mousewheel', function(e) {
e.preventDefault(); e.preventDefault();
_this.setValue(_this.getValue() + Math.abs(e.wheelDeltaY)/e.wheelDeltaY*step); _this.setValue(_this.getValue() + Math.abs(e.wheelDeltaY)/e.wheelDeltaY*step);
return false; return false;
}, false); }, false);
numberField.addEventListener('mousedown', function(e) { numberField.addEventListener('mousedown', function(e) {
py = y = e.pageY; py = y = e.pageY;
clickedNumberField = true; clickedNumberField = true;
document.addEventListener('mousemove', dragNumberField, false); document.addEventListener('mousemove', dragNumberField, false);
document.addEventListener('mouseup', mouseup, false); document.addEventListener('mouseup', mouseup, false);
}, false);
// Handle up arrow and down arrow
numberField.addEventListener('keydown', function(e) {
var newVal;
switch(e.keyCode) {
case 38: // up
newVal = _this.getValue() + step;
_this.setValue(newVal);
break;
case 40: // down
newVal = _this.getValue() - step;
_this.setValue(newVal);
break;
}
}, false); }, false);
// Handle up arrow and down arrow
numberField.addEventListener('keydown', function(e) {
switch(e.keyCode) {
case 38: // up
var newVal = _this.getValue() + step;
_this.setValue(newVal);
break;
case 40: // down
var newVal = _this.getValue() - step;
_this.setValue(newVal);
break;
}
}, false);
var mouseup = function(e) { var mouseup = function(e) {
document.removeEventListener('mousemove', dragNumberField, false); document.removeEventListener('mousemove', dragNumberField, false);
GUI.makeSelectable(_this.parent.domElement); GUI.makeSelectable(_this.parent.domElement);
GUI.makeSelectable(numberField); GUI.makeSelectable(numberField);
if (clickedNumberField && !draggedNumberField) { if (clickedNumberField && !draggedNumberField) {
numberField.focus(); numberField.focus();
numberField.select(); numberField.select();
} }
if(slider) slider.domElement.className = slider.domElement.className.replace(' active', '');
draggedNumberField = false; draggedNumberField = false;
clickedNumberField = false; clickedNumberField = false;
if (_this.finishChangeFunction != null) { if (_this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue()); _this.finishChangeFunction.call(this, _this.getValue());
} }
document.removeEventListener('mouseup', mouseup, false); document.removeEventListener('mouseup', mouseup, false);
} };
var dragNumberField = function(e) { var dragNumberField = function(e) {
draggedNumberField = true;
e.preventDefault();
// We don't want to be highlighting this field as we scroll. draggedNumberField = true;
// Or any other fields in this gui for that matter ... e.preventDefault();
// TODO: Make makeUselectable go through each element and child element.
// We don't want to be highlighting this field as we scroll.
// Or any other fields in this gui for that matter ...
// TODO: Make makeUselectable go through each element and child element.
GUI.makeUnselectable(_this.parent.domElement);
GUI.makeUnselectable(numberField);
if(slider) slider.domElement.className += ' active';
py = y;
y = e.pageY;
var dy = py - y;
var newVal = _this.getValue() + dy*step;
_this.setValue(newVal);
return false;
};
GUI.makeUnselectable(_this.parent.domElement);
GUI.makeUnselectable(numberField);
py = y;
y = e.pageY;
var dy = py - y;
var newVal = _this.getValue() + dy*step;
_this.setValue(newVal);
return false;
}
this.options = function() { this.options = function() {
_this.noSlider(); _this.noSlider();
_this.domElement.removeChild(numberField); _this.domElement.removeChild(numberField);
return GUI.Controller.prototype.options.apply(this, arguments); return GUI.Controller.prototype.options.apply(this, arguments);
}; };
this.noSlider = function() { this.noSlider = function() {
if (slider) { if (slider) {
_this.domElement.removeChild(slider.domElement); _this.domElement.removeChild(slider.domElement);
} }
return this; return this;
}; };
this.setValue = function(val) { this.setValue = function(val) {
val = parseFloat(val); val = parseFloat(val);
if (min != undefined && val <= min) { if (min != undefined && val <= min) {
val = min; val = min;
} else if (max != undefined && val >= max) { } else if (max != undefined && val >= max) {
val = max; val = max;
} }
return GUI.Controller.prototype.setValue.call(this, val); return GUI.Controller.prototype.setValue.call(this, val);
} };
this.updateDisplay = function() { this.updateDisplay = function() {
numberField.value = GUI.roundToDecimal(_this.getValue(), 4); numberField.value = GUI.roundToDecimal(_this.getValue(), 4);
if (slider) slider.value = _this.getValue(); if (slider) slider.value = _this.getValue();
} };
}; };
GUI.extendController(GUI.NumberController); GUI.extendController(GUI.NumberController);

View File

@ -1,47 +1,47 @@
GUI.StringController = function() { GUI.StringController = function() {
this.type = "string"; this.type = "string";
var _this = this; var _this = this;
GUI.Controller.apply(this, arguments); GUI.Controller.apply(this, arguments);
var input = document.createElement('input'); var input = document.createElement('input');
var initialValue = this.getValue(); var initialValue = this.getValue();
input.setAttribute('value', initialValue); input.setAttribute('value', initialValue);
input.setAttribute('spellcheck', 'false'); input.setAttribute('spellcheck', 'false');
this.domElement.addEventListener('mouseup', function() { this.domElement.addEventListener('mouseup', function() {
input.focus(); input.focus();
input.select(); input.select();
}, false); }, false);
// TODO: getting messed up on ctrl a // TODO: getting messed up on ctrl a
input.addEventListener('keyup', function(e) { input.addEventListener('keyup', function(e) {
if (e.keyCode == 13 && _this.finishChangeFunction != null) { if (e.keyCode == 13 && _this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue()); _this.finishChangeFunction.call(this, _this.getValue());
} }
_this.setValue(input.value); _this.setValue(input.value);
}, false); }, false);
input.addEventListener('blur', function() { input.addEventListener('blur', function() {
if (_this.finishChangeFunction != null) { if (_this.finishChangeFunction != null) {
_this.finishChangeFunction.call(this, _this.getValue()); _this.finishChangeFunction.call(this, _this.getValue());
} }
}, false); }, false);
this.updateDisplay = function() { this.updateDisplay = function() {
input.value = _this.getValue(); input.value = _this.getValue();
}
this.options = function() {
_this.domElement.removeChild(input);
return GUI.Controller.prototype.options.apply(this, arguments);
}; };
this.options = function() {
_this.domElement.removeChild(input);
return GUI.Controller.prototype.options.apply(this, arguments);
};
this.domElement.appendChild(input); this.domElement.appendChild(input);
}; };
GUI.extendController(GUI.StringController); GUI.extendController(GUI.StringController);

View File

@ -1,69 +1,92 @@
GUI.Slider = function(numberController, min, max, step, initValue) { GUI.Slider = function(numberController, min, max, step, initValue) {
var min = min;
var max = max;
var step = step;
var clicked = false;
var _this = this;
var x, px;
this.domElement = document.createElement('div');
this.domElement.setAttribute('class', 'guidat-slider-bg');
this.fg = document.createElement('div');
this.fg.setAttribute('class', 'guidat-slider-fg');
this.domElement.appendChild(this.fg);
var findPos = function(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
return [curleft,curtop];
}
}
this.__defineSetter__('value', function(e) {
var pct = GUI.map(e, min, max, 0, 100);
this.fg.style.width = pct+"%";
});
var onDrag = function(e) { var clicked = false;
if (!clicked) return; var _this = this;
var pos = findPos(_this.domElement);
var val = GUI.map(e.pageX, pos[0], pos[0] + _this.domElement.offsetWidth, min, max);
val = Math.round(val/step)*step;
numberController.setValue(val);
}
this.domElement.addEventListener('mousedown', function(e) {
clicked = true;
x = px = e.pageX;
_this.domElement.setAttribute('class', 'guidat-slider-bg active');
_this.fg.setAttribute('class', 'guidat-slider-fg active');
onDrag(e);
document.addEventListener('mouseup', mouseup, false);
}, false);
var mouseup = function(e) {
_this.domElement.setAttribute('class', 'guidat-slider-bg');
_this.fg.setAttribute('class', 'guidat-slider-fg');
clicked = false;
if (numberController.finishChangeFunction != null) {
numberController.finishChangeFunction.call(this, numberController.getValue());
}
document.removeEventListener('mouseup', mouseup, false);
};
var x, px;
document.addEventListener('mousemove', onDrag, false);
this.domElement = document.createElement('div');
this.value = initValue; this.domElement.setAttribute('class', 'guidat-slider-bg');
} this.fg = document.createElement('div');
this.fg.setAttribute('class', 'guidat-slider-fg');
this.domElement.appendChild(this.fg);
var onDrag = function(e) {
if (!clicked) return;
var pos = findPos(_this.domElement);
var val = GUI.map(e.pageX, pos[0], pos[0] + _this.domElement.offsetWidth, min, max);
val = Math.round(val/step)*step;
numberController.setValue(val);
};
this.domElement.addEventListener('mousedown', function(e) {
clicked = true;
x = px = e.pageX;
_this.domElement.className += ' active';
_this.fg.className += ' active';
numberController.domElement.className += ' active';
onDrag(e);
document.addEventListener('mouseup', mouseup, false);
}, false);
var mouseup = function(e) {
_this.domElement.className = _this.domElement.className.replace(' active', '');
_this.fg.className = _this.fg.className.replace(' active', '');
numberController.domElement.className = numberController.domElement.className.replace(' active', '');
clicked = false;
if (numberController.finishChangeFunction != null) {
numberController.finishChangeFunction.call(this, numberController.getValue());
}
document.removeEventListener('mouseup', mouseup, false);
};
var findPos = function(obj) {
var curleft = 0, curtop = 0;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} while ((obj = obj.offsetParent));
return [curleft,curtop];
}
};
this.__defineSetter__('value', function(e) {
var pct = GUI.map(e, min, max, 0, 100);
this.fg.style.width = pct+"%";
});
var onDrag = function(e) {
if (!clicked) return;
var pos = findPos(_this.domElement);
var val = GUI.map(e.pageX, pos[0], pos[0] + _this.domElement.offsetWidth, min, max);
val = Math.round(val/step)*step;
numberController.setValue(val);
};
this.domElement.addEventListener('mousedown', function(e) {
clicked = true;
x = px = e.pageX;
_this.domElement.setAttribute('class', 'guidat-slider-bg active');
_this.fg.setAttribute('class', 'guidat-slider-fg active');
onDrag(e);
document.addEventListener('mouseup', mouseup, false);
}, false);
var mouseup = function(e) {
_this.domElement.setAttribute('class', 'guidat-slider-bg');
_this.fg.setAttribute('class', 'guidat-slider-fg');
clicked = false;
if (numberController.finishChangeFunction != null) {
numberController.finishChangeFunction.call(this, numberController.getValue());
}
document.removeEventListener('mouseup', mouseup, false);
};
document.addEventListener('mousemove', onDrag, false);
this.value = initValue;
};

View File

@ -67,12 +67,16 @@ div.collapsed h2, div.expanded h2 {
cursor: pointer; cursor: pointer;
} }
.last { margin-bottom: 0px !important; }
.first { margin-top: 0px; }
div.trans { div.trans {
border-top: 1px dotted #ccc; border-top: 1px dotted #ccc;
margin: 0px 0px 20px 0px; margin: 0px 0px 20px 0px;
} }
ol#secrets { ol#secrets {
/* padding: 0px 0px 20px 0px;*/ padding: 0px;
margin: 0px;
} }
div.expanded h2:before { div.expanded h2:before {
content: '-'; content: '-';
@ -102,6 +106,8 @@ div.collapsable {
} }
div.collapsable div { div.collapsable div {
padding-bottom: 20px;
margin-bottom: -20px;
height: auto; height: auto;
} }

View File

@ -1,15 +1,15 @@
function FizzyText(message) { function FizzyText(message) {
var that = this; var that = this;
// These are the variables that we manipulate with gui-dat. // These are the variables that we manipulate with gui-dat.
// Notice they're all defined with "this". That makes them public. // Notice they're all defined with "this". That makes them public.
// Otherwise, gui-dat can't see them. // Otherwise, gui-dat can't see them.
this.growthSpeed = 0.5; // how fast do particles change size? this.growthSpeed = 0.5; // how fast do particles change size?
this.maxSize = 3.2; // how big can they get? this.maxSize = 3.2; // how big can they get?
this.noiseStrength = 10; // how turbulent is the flow? this.noiseStrength = 10; // how turbulent is the flow?
this.speed = 0.4; // how fast do particles move? this.speed = 0.4; // how fast do particles move?
this.displayOutline = false; // should we draw the message as a stroke? this.displayOutline = false; // should we draw the message as a stroke?
this.framesRendered = 0; this.framesRendered = 0;
@ -26,37 +26,37 @@ function FizzyText(message) {
createBitmap(message); createBitmap(message);
}); });
// We can even add functions to the GUI! As long as they have // We can even add functions to the GUI! As long as they have
// 0 arguments, we can call them from the dat-gui panel. // 0 arguments, we can call them from the dat-gui panel.
this.explode = function() { this.explode = function() {
var mag = Math.random()*30+30; var mag = Math.random()*30+30;
for (var i in particles) { for (var i in particles) {
var angle= Math.random()*Math.PI*2; var angle= Math.random()*Math.PI*2;
particles[i].vx = Math.cos(angle)*mag; particles[i].vx = Math.cos(angle)*mag;
particles[i].vy = Math.sin(angle)*mag; particles[i].vy = Math.sin(angle)*mag;
} }
}; };
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
var _this = this; var _this = this;
var width = 550; var width = 550;
var height = 200; var height = 200;
var textAscent = 82; var textAscent = 82;
var textOffsetLeft = 80; var textOffsetLeft = 80;
var noiseScale = 300; var noiseScale = 300;
var frameTime = 30; var frameTime = 30;
var colors = ["#00aeff", "#0fa954", "#54396e", "#e61d5f"]; var colors = ["#00aeff", "#0fa954", "#54396e", "#e61d5f"];
// This is the context we use to get a bitmap of text using // This is the context we use to get a bitmap of text using
// the getImageData function. // the getImageData function.
var r = document.createElement('canvas'); var r = document.createElement('canvas');
var s = r.getContext('2d'); var s = r.getContext('2d');
// This is the context we actually use to draw. // This is the context we actually use to draw.
var c = document.createElement('canvas'); var c = document.createElement('canvas');
var g = c.getContext('2d'); var g = c.getContext('2d');
@ -65,17 +65,17 @@ function FizzyText(message) {
r.setAttribute('height', height); r.setAttribute('height', height);
c.setAttribute('height', height); c.setAttribute('height', height);
// Add our demo to the HTML // Add our demo to the HTML
document.getElementById('helvetica-demo').appendChild(c); document.getElementById('helvetica-demo').appendChild(c);
// Stores bitmap image // Stores bitmap image
var pixels = []; var pixels = [];
// Stores a list of particles // Stores a list of particles
var particles = []; var particles = [];
// Set g.font to the same font as the bitmap canvas, incase we // Set g.font to the same font as the bitmap canvas, incase we
// want to draw some outlines. // want to draw some outlines.
s.font = g.font = "800 " + textAscent + "px helvetica, arial, sans-serif"; s.font = g.font = "800 " + textAscent + "px helvetica, arial, sans-serif";
// Instantiate some particles // Instantiate some particles
@ -83,8 +83,8 @@ function FizzyText(message) {
particles.push(new Particle(Math.random() * width, Math.random() * height)); particles.push(new Particle(Math.random() * width, Math.random() * height));
} }
// This function creates a bitmap of pixels based on your message // This function creates a bitmap of pixels based on your message
// It's called every time we change the message property. // It's called every time we change the message property.
var createBitmap = function (msg) { var createBitmap = function (msg) {
s.fillStyle = "#fff"; s.fillStyle = "#fff";
@ -99,10 +99,10 @@ function FizzyText(message) {
}; };
// Called once per frame, updates the animation. // Called once per frame, updates the animation.
var render = function () { var render = function () {
that.framesRendered ++; that.framesRendered ++;
g.clearRect(0, 0, width, height); g.clearRect(0, 0, width, height);
@ -122,7 +122,7 @@ function FizzyText(message) {
}; };
// Returns x, y coordinates for a given index in the pixel array. // Returns x, y coordinates for a given index in the pixel array.
var getPosition = function (i) { var getPosition = function (i) {
return { return {
x: (i - (width * 4) * Math.floor(i / (width * 4))) / 4, x: (i - (width * 4) * Math.floor(i / (width * 4))) / 4,
@ -130,7 +130,7 @@ function FizzyText(message) {
}; };
}; };
// Returns a color for a given pixel in the pixel array. // Returns a color for a given pixel in the pixel array.
var getColor = function (x, y) { var getColor = function (x, y) {
var base = (Math.floor(y) * width + Math.floor(x)) * 4; var base = (Math.floor(y) * width + Math.floor(x)) * 4;
var c = { var c = {
@ -142,33 +142,33 @@ function FizzyText(message) {
return "rgb(" + c.r + "," + c.g + "," + c.b + ")"; return "rgb(" + c.r + "," + c.g + "," + c.b + ")";
}; };
// This calls the setter we've defined above, so it also calls // This calls the setter we've defined above, so it also calls
// the createBitmap function. // the createBitmap function.
this.message = message; this.message = message;
var loop = function() { var loop = function() {
// Don't render if we don't see it. // Don't render if we don't see it.
// Would be cleaner if I dynamically acquired the top of the canvas. // Would be cleaner if I dynamically acquired the top of the canvas.
if (document.body.scrollTop < height + 20) { if (document.body.scrollTop < height + 20) {
render(); render();
} }
} }
// This calls the render function every 30 milliseconds. // This calls the render function every 30 milliseconds.
setInterval(loop, frameTime); setInterval(loop, frameTime);
// This class is responsible for drawing and moving those little // This class is responsible for drawing and moving those little
// colored dots. // colored dots.
function Particle(x, y, c) { function Particle(x, y, c) {
// Position // Position
this.x = x; this.x = x;
this.y = y; this.y = y;
// Size of particle // Size of particle
this.r = 0; this.r = 0;
// This velocity is used by the explode function. // This velocity is used by the explode function.
this.vx = 0; this.vx = 0;
this.vy = 0; this.vy = 0;
@ -184,12 +184,12 @@ function FizzyText(message) {
// Are we within the boundaries of the image? // Are we within the boundaries of the image?
var onScreen = this.x > 0 && this.x < width && var onScreen = this.x > 0 && this.x < width &&
this.y > 0 && this.y < height; this.y > 0 && this.y < height;
var isBlack = c != "rgb(255,255,255)" && onScreen; var isBlack = c != "rgb(255,255,255)" && onScreen;
// If we're on top of a black pixel, grow. // If we're on top of a black pixel, grow.
// If not, shrink. // If not, shrink.
if (isBlack) { if (isBlack) {
this.r += _this.growthSpeed; this.r += _this.growthSpeed;
} else { } else {

View File

@ -2,72 +2,72 @@
var ImprovedNoise = function () { var ImprovedNoise = function () {
var p = [151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10, var p = [151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,
23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87, 23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,
174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229,122,60,211, 174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,
133,230,220,105,92,41,55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208, 133,230,220,105,92,41,55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208,
89,18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,250,124,123,5, 89,18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,250,124,123,5,
202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,223,183,170,213,119, 202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,223,183,170,213,119,
248,152,2,44,154,163,70,221,153,101,155,167,43,172,9,129,22,39,253,19,98,108,110,79,113,224,232, 248,152,2,44,154,163,70,221,153,101,155,167,43,172,9,129,22,39,253,19,98,108,110,79,113,224,232,
178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249, 178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,
14,239,107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,138,236,205, 14,239,107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,138,236,205,
93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180]; 93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180];
for ( var i = 0; i < 256 ; i++ ) { for ( var i = 0; i < 256 ; i++ ) {
p[ 256 + i ] = p[ i ]; p[ 256 + i ] = p[ i ];
} }
function fade( t ) { function fade( t ) {
return t * t * t * ( t * ( t * 6 - 15 ) + 10 ); return t * t * t * ( t * ( t * 6 - 15 ) + 10 );
} }
function lerp( t, a, b ) { function lerp( t, a, b ) {
return a + t * ( b - a ); return a + t * ( b - a );
} }
function grad( hash, x, y, z ) { function grad( hash, x, y, z ) {
var h = hash & 15; var h = hash & 15;
var u = h < 8 ? x : y, v = h < 4 ? y : h == 12 || h == 14 ? x : z; var u = h < 8 ? x : y, v = h < 4 ? y : h == 12 || h == 14 ? x : z;
return ( ( h & 1 ) == 0 ? u : -u ) + ( ( h & 2 ) == 0 ? v : -v ); return ( ( h & 1 ) == 0 ? u : -u ) + ( ( h & 2 ) == 0 ? v : -v );
} }
return { return {
noise: function ( x, y, z ) { noise: function ( x, y, z ) {
var floorX = Math.floor( x ), floorY = Math.floor( y ), floorZ = Math.floor( z ); var floorX = Math.floor( x ), floorY = Math.floor( y ), floorZ = Math.floor( z );
var X = floorX & 255, Y = floorY & 255, Z = floorZ & 255; var X = floorX & 255, Y = floorY & 255, Z = floorZ & 255;
x -= floorX; x -= floorX;
y -= floorY; y -= floorY;
z -= floorZ; z -= floorZ;
var xMinus1 = x -1, yMinus1 = y - 1, zMinus1 = z - 1; var xMinus1 = x -1, yMinus1 = y - 1, zMinus1 = z - 1;
var u = fade( x ), v = fade( y ), w = fade( z ); var u = fade( x ), v = fade( y ), w = fade( z );
var A = p[ X ] + Y, AA = p[ A ] + Z, AB = p[ A + 1 ] + Z, B = p[ X + 1 ] + Y, BA = p[ B ] + Z, BB = p[ B + 1 ] + Z; var A = p[ X ] + Y, AA = p[ A ] + Z, AB = p[ A + 1 ] + Z, B = p[ X + 1 ] + Y, BA = p[ B ] + Z, BB = p[ B + 1 ] + Z;
return lerp( w, lerp( v, lerp( u, grad( p[ AA ], x, y, z ), return lerp( w, lerp( v, lerp( u, grad( p[ AA ], x, y, z ),
grad( p[ BA ], xMinus1, y, z ) ), grad( p[ BA ], xMinus1, y, z ) ),
lerp( u, grad( p[ AB ], x, yMinus1, z ), lerp( u, grad( p[ AB ], x, yMinus1, z ),
grad( p[ BB ], xMinus1, yMinus1, z ) ) ), grad( p[ BB ], xMinus1, yMinus1, z ) ) ),
lerp( v, lerp( u, grad( p[ AA + 1 ], x, y, zMinus1 ), lerp( v, lerp( u, grad( p[ AA + 1 ], x, y, zMinus1 ),
grad( p[ BA + 1 ], xMinus1, y, z - 1 ) ), grad( p[ BA + 1 ], xMinus1, y, z - 1 ) ),
lerp( u, grad( p[ AB + 1 ], x, yMinus1, zMinus1 ), lerp( u, grad( p[ AB + 1 ], x, yMinus1, zMinus1 ),
grad( p[ BB + 1 ], xMinus1, yMinus1, zMinus1 ) ) ) ); grad( p[ BB + 1 ], xMinus1, yMinus1, zMinus1 ) ) ) );
} }
} }
} }
var currentRandom = Math.random; var currentRandom = Math.random;
@ -77,21 +77,21 @@ function Marsaglia(i1, i2) {
// from http://www.math.uni-bielefeld.de/~sillke/ALGORITHMS/random/marsaglia-c // from http://www.math.uni-bielefeld.de/~sillke/ALGORITHMS/random/marsaglia-c
var z=i1 || 362436069, w= i2 || 521288629; var z=i1 || 362436069, w= i2 || 521288629;
var nextInt = function() { var nextInt = function() {
z=(36969*(z&65535)+(z>>>16)) & 0xFFFFFFFF; z=(36969*(z&65535)+(z>>>16)) & 0xFFFFFFFF;
w=(18000*(w&65535)+(w>>>16)) & 0xFFFFFFFF; w=(18000*(w&65535)+(w>>>16)) & 0xFFFFFFFF;
return (((z&0xFFFF)<<16) | (w&0xFFFF)) & 0xFFFFFFFF; return (((z&0xFFFF)<<16) | (w&0xFFFF)) & 0xFFFFFFFF;
}; };
this.nextDouble = function() { this.nextDouble = function() {
var i = nextInt() / 4294967296; var i = nextInt() / 4294967296;
return i < 0 ? 1 + i : i; return i < 0 ? 1 + i : i;
}; };
this.nextInt = nextInt; this.nextInt = nextInt;
} }
Marsaglia.createRandomized = function() { Marsaglia.createRandomized = function() {
var now = new Date(); var now = new Date();
return new Marsaglia((now / 60000) & 0xFFFFFFFF, now & 0xFFFFFFFF); return new Marsaglia((now / 60000) & 0xFFFFFFFF, now & 0xFFFFFFFF);
}; };
// Noise functions and helpers // Noise functions and helpers
function PerlinNoise(seed) { function PerlinNoise(seed) {
@ -107,75 +107,75 @@ function PerlinNoise(seed) {
for(i=0;i<256;++i) { p[i + 256] = p[i]; } for(i=0;i<256;++i) { p[i + 256] = p[i]; }
function grad3d(i,x,y,z) { function grad3d(i,x,y,z) {
var h = i & 15; // convert into 12 gradient directions var h = i & 15; // convert into 12 gradient directions
var u = h<8 ? x : y, var u = h<8 ? x : y,
v = h<4 ? y : h===12||h===14 ? x : z; v = h<4 ? y : h===12||h===14 ? x : z;
return ((h&1) === 0 ? u : -u) + ((h&2) === 0 ? v : -v); return ((h&1) === 0 ? u : -u) + ((h&2) === 0 ? v : -v);
} }
function grad2d(i,x,y) { function grad2d(i,x,y) {
var v = (i & 1) === 0 ? x : y; var v = (i & 1) === 0 ? x : y;
return (i&2) === 0 ? -v : v; return (i&2) === 0 ? -v : v;
} }
function grad1d(i,x) { function grad1d(i,x) {
return (i&1) === 0 ? -x : x; return (i&1) === 0 ? -x : x;
} }
function lerp(t,a,b) { return a + t * (b - a); } function lerp(t,a,b) { return a + t * (b - a); }
this.noise3d = function(x, y, z) { this.noise3d = function(x, y, z) {
var X = Math.floor(x)&255, Y = Math.floor(y)&255, Z = Math.floor(z)&255; var X = Math.floor(x)&255, Y = Math.floor(y)&255, Z = Math.floor(z)&255;
x -= Math.floor(x); y -= Math.floor(y); z -= Math.floor(z); x -= Math.floor(x); y -= Math.floor(y); z -= Math.floor(z);
var fx = (3-2*x)*x*x, fy = (3-2*y)*y*y, fz = (3-2*z)*z*z; var fx = (3-2*x)*x*x, fy = (3-2*y)*y*y, fz = (3-2*z)*z*z;
var p0 = p[X]+Y, p00 = p[p0] + Z, p01 = p[p0 + 1] + Z, p1 = p[X + 1] + Y, p10 = p[p1] + Z, p11 = p[p1 + 1] + Z; var p0 = p[X]+Y, p00 = p[p0] + Z, p01 = p[p0 + 1] + Z, p1 = p[X + 1] + Y, p10 = p[p1] + Z, p11 = p[p1 + 1] + Z;
return lerp(fz, return lerp(fz,
lerp(fy, lerp(fx, grad3d(p[p00], x, y, z), grad3d(p[p10], x-1, y, z)), lerp(fy, lerp(fx, grad3d(p[p00], x, y, z), grad3d(p[p10], x-1, y, z)),
lerp(fx, grad3d(p[p01], x, y-1, z), grad3d(p[p11], x-1, y-1,z))), lerp(fx, grad3d(p[p01], x, y-1, z), grad3d(p[p11], x-1, y-1,z))),
lerp(fy, lerp(fx, grad3d(p[p00 + 1], x, y, z-1), grad3d(p[p10 + 1], x-1, y, z-1)), lerp(fy, lerp(fx, grad3d(p[p00 + 1], x, y, z-1), grad3d(p[p10 + 1], x-1, y, z-1)),
lerp(fx, grad3d(p[p01 + 1], x, y-1, z-1), grad3d(p[p11 + 1], x-1, y-1,z-1)))); lerp(fx, grad3d(p[p01 + 1], x, y-1, z-1), grad3d(p[p11 + 1], x-1, y-1,z-1))));
}; };
this.noise2d = function(x, y) { this.noise2d = function(x, y) {
var X = Math.floor(x)&255, Y = Math.floor(y)&255; var X = Math.floor(x)&255, Y = Math.floor(y)&255;
x -= Math.floor(x); y -= Math.floor(y); x -= Math.floor(x); y -= Math.floor(y);
var fx = (3-2*x)*x*x, fy = (3-2*y)*y*y; var fx = (3-2*x)*x*x, fy = (3-2*y)*y*y;
var p0 = p[X]+Y, p1 = p[X + 1] + Y; var p0 = p[X]+Y, p1 = p[X + 1] + Y;
return lerp(fy, return lerp(fy,
lerp(fx, grad2d(p[p0], x, y), grad2d(p[p1], x-1, y)), lerp(fx, grad2d(p[p0], x, y), grad2d(p[p1], x-1, y)),
lerp(fx, grad2d(p[p0 + 1], x, y-1), grad2d(p[p1 + 1], x-1, y-1))); lerp(fx, grad2d(p[p0 + 1], x, y-1), grad2d(p[p1 + 1], x-1, y-1)));
}; };
this.noise1d = function(x) { this.noise1d = function(x) {
var X = Math.floor(x)&255; var X = Math.floor(x)&255;
x -= Math.floor(x); x -= Math.floor(x);
var fx = (3-2*x)*x*x; var fx = (3-2*x)*x*x;
return lerp(fx, grad1d(p[X], x), grad1d(p[X+1], x-1)); return lerp(fx, grad1d(p[X], x), grad1d(p[X+1], x-1));
}; };
} }
// these are lifted from Processing.js // these are lifted from Processing.js
// processing defaults // processing defaults
var noiseProfile = { generator: undefined, octaves: 4, fallout: 0.5, seed: undefined}; var noiseProfile = { generator: undefined, octaves: 4, fallout: 0.5, seed: undefined};
function noise(x, y, z) { function noise(x, y, z) {
if(noiseProfile.generator === undefined) { if(noiseProfile.generator === undefined) {
// caching // caching
noiseProfile.generator = new PerlinNoise(noiseProfile.seed); noiseProfile.generator = new PerlinNoise(noiseProfile.seed);
} }
var generator = noiseProfile.generator; var generator = noiseProfile.generator;
var effect = 1, k = 1, sum = 0; var effect = 1, k = 1, sum = 0;
for(var i=0; i<noiseProfile.octaves; ++i) { for(var i=0; i<noiseProfile.octaves; ++i) {
effect *= noiseProfile.fallout; effect *= noiseProfile.fallout;
switch (arguments.length) { switch (arguments.length) {
case 1: case 1:
sum += effect * (1 + generator.noise1d(k*x))/2; break; sum += effect * (1 + generator.noise1d(k*x))/2; break;
case 2: case 2:
sum += effect * (1 + generator.noise2d(k*x, k*y))/2; break; sum += effect * (1 + generator.noise2d(k*x, k*y))/2; break;
case 3: case 3:
sum += effect * (1 + generator.noise3d(k*x, k*y, k*z))/2; break; sum += effect * (1 + generator.noise3d(k*x, k*y, k*z))/2; break;
} }
k *= 2; k *= 2;
} }
return sum; return sum;
}; };

164
gui.css
View File

@ -1,170 +1,166 @@
#guidat { #guidat {
position: fixed; position: fixed;
top: 0; top: 0;
right: 0; right: 0;
width: auto; width: auto;
z-index: 1001; z-index: 1001;
text-align: right; text-align: right;
} }
.guidat { .guidat {
color: #fff; color: #fff;
opacity: 0.97; opacity: 0.97;
text-align: left; text-align: left;
float: right; float: right;
margin-right: 20px; margin-right: 20px;
margin-bottom: 20px; margin-bottom: 20px;
background-color: #fff; background-color: #fff;
} }
.guidat, .guidat,
.guidat input { .guidat input {
font: 9.5px Lucida Grande, sans-serif; font: 9.5px Lucida Grande, sans-serif;
} }
.guidat-controllers { .guidat-controllers {
height: 300px; height: 300px;
overflow-y: auto; overflow-y: auto;
overflow-x: hidden; overflow-x: hidden;
background-color: rgba(0,0,0,0.1); background-color: rgba(0,0,0,0.1);
/*
-moz-transition: height .2s ease-out;
-webkit-transition: height .2s ease-out;
transition: height .2s ease-out;
*/
} }
a.guidat-toggle { a.guidat-toggle {
text-decoration: none; text-decoration: none;
cursor: pointer; cursor: pointer;
color: #fff; color: #fff;
background-color: #222; background-color: #222;
text-align: center; text-align: center;
display: block; display: block;
padding: 5px; padding: 5px;
} }
a.guidat-toggle:hover { a.guidat-toggle:hover {
background-color: #000; background-color: #000;
} }
.guidat-controller { .guidat-controller {
padding: 3px; padding: 3px;
height: 25px; height: 25px;
clear: left; clear: left;
border-bottom: 1px solid #222; border-bottom: 1px solid #222;
background-color: #111; background-color: #111;
} }
.guidat-controller, .guidat-controller,
.guidat-controller input, .guidat-controller input,
.guidat-slider-bg, .guidat-slider-bg,
.guidat-slider-fg { .guidat-slider-fg {
-moz-transition: background-color 0.15s linear; -moz-transition: background-color 0.15s linear;
-webkit-transition: background-color 0.15s linear; -webkit-transition: background-color 0.15s linear;
transition: background-color 0.15s linear; transition: background-color 0.15s linear;
} }
.guidat-controller.boolean:hover, .guidat-controller.boolean:hover,
.guidat-controller.function:hover { .guidat-controller.function:hover {
background-color: #000; background-color: #000;
} }
.guidat-controller input { .guidat-controller input {
float: right; float: right;
outline: none; outline: none;
border: 0; border: 0;
padding: 4px; padding: 4px;
margin-top: 2px; margin-top: 2px;
background-color: #222; background-color: #222;
} }
.guidat-controller select { .guidat-controller select {
margin-top: 4px; margin-top: 4px;
float: right; float: right;
} }
.guidat-controller input:hover { .guidat-controller input:hover.
background-color: #444; .guidat-controller.number.active {
background-color: #444;
} }
.guidat-controller input:focus { .guidat-controller input:focus {
background-color: #555; background-color: #555;
} }
.guidat-controller.number { .guidat-controller.number {
border-left: 5px solid #00aeff ; border-left: 5px solid #00aeff ;
} }
.guidat-controller.string { .guidat-controller.string {
border-left: 5px solid #1ed36f; border-left: 5px solid #1ed36f;
} }
.guidat-controller.string input { .guidat-controller.string input {
border: 0; border: 0;
color: #1ed36f; color: #1ed36f;
margin-right: 2px; margin-right: 2px;
width: 148px; width: 148px;
} }
.guidat-controller.boolean { .guidat-controller.boolean {
border-left: 5px solid #54396e; border-left: 5px solid #54396e;
} }
.guidat-controller.function { .guidat-controller.function {
border-left: 5px solid #e61d5f; border-left: 5px solid #e61d5f;
} }
.guidat-controller.number input[type=text] { .guidat-controller.number input[type=text] {
width: 35px; width: 35px;
margin-left: 5px; margin-left: 5px;
margin-right: 2px; margin-right: 2px;
color: #00aeff; color: #00aeff;
} }
.guidat .guidat-controller.boolean input { .guidat .guidat-controller.boolean input {
margin-top: 6px; margin-top: 6px;
margin-right: 2px; margin-right: 2px;
font-size: 20px; font-size: 20px;
} }
.guidat-controller:last-child { .guidat-controller:last-child {
border-bottom: none; border-bottom: none;
-webkit-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.5); -webkit-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.5);
-moz-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.5); -moz-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.5);
box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.5); box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.5);
} }
.guidat-propertyname { .guidat-propertyname {
padding: 5px; padding: 5px;
padding-top: 7px; padding-top: 7px;
cursor: default; cursor: default;
display: inline-block; display: inline-block;
} }
.guidat-slider-bg:hover, .guidat-slider-bg:hover,
.guidat-slider-bg.active { .guidat-slider-bg.active {
background-color: #444; background-color: #444;
} }
.guidat-slider-bg:hover .guidat-slider-fg, .guidat-slider-bg:hover .guidat-slider-fg,
.guidat-slider-bg.active .guidat-slider-fg { .guidat-slider-bg.active .guidat-slider-fg {
background-color: #52c8ff; background-color: #52c8ff;
} }
.guidat-slider-bg { .guidat-slider-bg {
background-color: #222; background-color: #222;
cursor: ew-resize; cursor: ew-resize;
width: 40%; width: 40%;
margin-top: 2px; margin-top: 2px;
float: right; float: right;
height: 21px; height: 21px;
} }
.guidat-slider-fg { .guidat-slider-fg {
background-color: #00aeff; background-color: #00aeff;
height: 20px; height: 20px;
} }

1046
gui.js

File diff suppressed because it is too large Load Diff

View File

@ -1,34 +1,24 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!doctype html>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<title>gui-dat</title> <title>gui-dat</title>
<link rel="icon" type="image/png" href="demo/assets/favicon.png" /> <link rel="icon" type="image/png" href="demo/assets/favicon.png" />
<link href="demo/demo.css" media="screen" rel="stylesheet" type="text/css" /> <link href="demo/demo.css" media="screen" rel="stylesheet" type="text/css" />
<link href="gui.css" media="screen" rel="stylesheet" type="text/css" /> <link href="gui.css" media="screen" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="gui.js">
</script> <script type="text/javascript" src="gui.js"></script>
<script type="text/javascript" src="controllers/slider.js"> <script type="text/javascript" src="controllers/slider.js"></script>
</script> <script type="text/javascript" src="controllers/controller.js"></script>
<script type="text/javascript" src="controllers/controller.js"> <script type="text/javascript" src="controllers/controller.boolean.js"></script>
</script> <script type="text/javascript" src="controllers/controller.function.js"></script>
<script type="text/javascript" src="controllers/controller.boolean.js"> <script type="text/javascript" src="controllers/controller.number.js"></script>
</script> <script type="text/javascript" src="controllers/controller.string.js"></script>
<script type="text/javascript" src="controllers/controller.function.js"> <script type="text/javascript" src="demo/improvedNoise.js"></script>
</script> <script type="text/javascript" src="demo/prettify.js"></script>
<script type="text/javascript" src="controllers/controller.number.js"> <script type="text/javascript" src="demo/demo.js"></script>
</script>
<script type="text/javascript" src="controllers/controller.string.js">
</script>
<script type="text/javascript" src="demo/improvedNoise.js">
</script>
<script type="text/javascript" src="demo/prettify.js">
</script>
<script type="text/javascript" src="demo/demo.js">
</script>
<script type="text/javascript"> <script type="text/javascript">
//<![CDATA[ //<![CDATA[
window.onload = function() { window.onload = function() {
@ -36,78 +26,78 @@
var fizzyText = new FizzyText("gui-dat"); var fizzyText = new FizzyText("gui-dat");
var gui = new GUI(); var gui = new GUI();
// Text field // Text field
gui.add(fizzyText, "message"); gui.add(fizzyText, "message");
// Sliders with min + max // Sliders with min + max
gui.add(fizzyText, "maxSize", 0.5, 7); gui.add(fizzyText, "maxSize", 0.5, 7);
gui.add(fizzyText, "growthSpeed", 0.01, 1); gui.add(fizzyText, "growthSpeed", 0.01, 1);
gui.add(fizzyText, "speed", 0.1, 2); gui.add(fizzyText, "speed", 0.1, 2);
// Sliders with min, max and increment. // Sliders with min, max and increment.
gui.add(fizzyText, "noiseStrength", 10, 100, 5); gui.add(fizzyText, "noiseStrength", 10, 100, 5);
// Boolean checkbox // Boolean checkbox
gui.add(fizzyText, "displayOutline"); gui.add(fizzyText, "displayOutline");
// Fires a function called "explode" // Fires a function called "explode"
gui.add(fizzyText, "explode").name("Explode!"); // Specify a custom name. gui.add(fizzyText, "explode").name("Explode!"); // Specify a custom name.
// Javascript for documentation // Javascript for documentation
getCollapsables(); getCollapsables();
handleListening(); handleListening();
}; };
function toggle(e) { function toggle(e) {
var collapsable = this.childNodes[3], var collapsable = this.childNodes[3],
wrapper = collapsable.childNodes[1]; wrapper = collapsable.childNodes[1];
if (this.className === 'collapsed') { if (this.className === 'collapsed') {
this.className = 'expanded'; this.className = 'expanded';
collapsable.style.height = wrapper.clientHeight + 'px'; collapsable.style.height = wrapper.clientHeight + 'px';
} else { } else {
this.className = 'collapsed'; this.className = 'collapsed';
collapsable.style.height = '0px'; collapsable.style.height = '0px';
} }
} }
function getCollapsables() { function getCollapsables() {
if (document.getElementsByClassName == undefined) { if (document.getElementsByClassName == undefined) {
document.getElementsByClassName = function(className) document.getElementsByClassName = function(className)
{ {
var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)"); var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
var allElements = document.getElementsByTagName("*"); var allElements = document.getElementsByTagName("*");
var results = []; var results = [];
var element; var element;
for (var i = 0; (element = allElements[i]) != null; i++) { for (var i = 0; (element = allElements[i]) != null; i++) {
var elementClass = element.className; var elementClass = element.className;
if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass)) if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
results.push(element); results.push(element);
} }
return results; return results;
}; };
} }
collapsed = document.getElementsByClassName('collapsed'); collapsed = document.getElementsByClassName('collapsed');
expanded = document.getElementsByClassName('expanded'); expanded = document.getElementsByClassName('expanded');
} }
function handleListening() { function handleListening() {
for(var i = 0; i < collapsed.length; i++) { for(var i = 0; i < collapsed.length; i++) {
collapsed[i].addEventListener('click', toggle, false); collapsed[i].addEventListener('click', toggle, false);
} }
for(var j = 0; j < expanded.length; j++) { for(var j = 0; j < expanded.length; j++) {
expanded[i].addEventListener('click', toggle, false); expanded[i].addEventListener('click', toggle, false);
} }
} }
//]]> //]]>
</script> </script>
@ -116,10 +106,10 @@
<body> <body>
<div id="container"> <div id="container">
<!-- GUIDAT logo --> <!-- GUIDAT logo -->
<div id="helvetica-demo"></div> <div id="helvetica-demo"></div>
<!-- It gives you this! --> <!-- It gives you this! -->
<div id="notifier"></div> <div id="notifier"></div>
<h1><a href="http://twitter.com/guidat"><img src="demo/assets/profile.png" border="0" alt="GUI-DAT flag" /></a></h1> <h1><a href="http://twitter.com/guidat"><img src="demo/assets/profile.png" border="0" alt="GUI-DAT flag" /></a></h1>
@ -177,26 +167,26 @@ window.onload = function() {
<pre class="prettyprint">gui.add(obj, "propName").onChange(function(n) { <pre class="prettyprint">gui.add(obj, "propName").onChange(function(n) {
alert("You changed me to " + n); alert("You changed me to " + n);
});</pre>--> });</pre>-->
<div class="collapsed"> <div class="collapsed">
<h2 class="section">Saving your parameters</h2> <h2 class="section">Saving your parameters</h2>
<div class="collapsable"> <div class="collapsable">
<div> <div>
<p>The simplest way to save your parameters is via <code>GUI.saveURL()</code>. This method directs your browser to a URL containing the current GUI settings.</p> <p>The simplest way to save your parameters is via <code>GUI.saveURL()</code>. This method directs your browser to a URL containing the current GUI settings.</p>
<pre class="prettyprint"> <pre class="prettyprint last">
// Make a button for the url function // Make a button for the url function
gui.add(GUI, "saveURL");</pre> gui.add(GUI, "saveURL");</pre>
</div> </div>
</div> </div>
</div> </div>
<div class="collapsed"> <div class="collapsed">
<h2 class="section">Advanced saving</h2> <h2 class="section">Advanced saving</h2>
<div class="collapsable"> <div class="collapsable">
<div> <div>
<p>Let's say you'd like to share your settings with someone. Instead of sending a long link with lots of parameters stored in it, you can make your saved settings the defaults.</p> <p>Let's say you'd like to share your settings with someone. Instead of sending a long link with lots of parameters stored in it, you can make your saved settings the defaults.</p>
<p>First, add the method <code>GUI.showSaveString()</code> to a gui object:</p> <p>First, add the method <code>GUI.showSaveString()</code> to a gui object:</p>
<pre class="prettyprint">var gui = new GUI(); <pre class="prettyprint">var gui = new GUI();
// Add some stuff (and pretend I change their values); // Add some stuff (and pretend I change their values);
gui.add(someObject, "someProperty"); gui.add(someObject, "someProperty");
@ -205,8 +195,8 @@ gui.add(someObject, "someOtherProperty");
// Make a save button. // Make a save button.
gui.add(GUI, "showSaveString");</pre> gui.add(GUI, "showSaveString");</pre>
<p>Clicking the "showSaveString" button bring up an alert with a string. Copy and paste that string into the method <code>GUI.load()</code> before you instantiate any gui objects.</p> <p>Clicking the "showSaveString" button bring up an alert with a string. Copy and paste that string into the method <code>GUI.load()</code> before you instantiate any gui objects.</p>
<pre class="prettyprint"> <pre class="prettyprint">
// Replace COPIED STRING with the value you got from showSaveString() // Replace COPIED STRING with the value you got from showSaveString()
GUI.load("COPIED STRING"); GUI.load("COPIED STRING");
@ -216,69 +206,69 @@ var gui = new GUI();
gui.add(someObject, "someProperty"); gui.add(someObject, "someProperty");
gui.add(someObject, "someOtherProperty");</pre> gui.add(someObject, "someOtherProperty");</pre>
<p><strong>Save strings won't work if you change the order in which you've added properties to your gui objects, or the order of the gui objects themselves.</strong>. If you want to add more parameters to your gui and use an old save string, make sure they're added after the properties whose values you've saved.</p> <p class = "last"><strong>Save strings won't work if you change the order in which you've added properties to your gui objects, or the order of the gui objects themselves.</strong>. If you want to add more parameters to your gui and use an old save string, make sure they're added after the properties whose values you've saved.</p>
</div> </div>
</div> </div>
</div> </div>
<div class="collapsed"> <div class="collapsed">
<h2 class="section">Choosing from a list of values</h2> <h2 class="section">Choosing from a list of values</h2>
<div class="collapsable"> <div class="collapsable">
<div> <div>
<pre class="prettyprint">gui.add(obj, "propertyName").options(1, 2, 3, 5, 8); <pre class="prettyprint first last">gui.add(obj, "propertyName").options(1, 2, 3, 5, 8);
// Alternatively, you can specify custom labels using object syntax // Alternatively, you can specify custom labels using object syntax
gui.add(obj, "propertyName").options({'Small': 1, 'Medium': 2, 'Large': 3}); gui.add(obj, "propertyName").options({'Small': 1, 'Medium': 2, 'Large': 3});
</pre> </pre>
</div> </div>
</div> </div>
</div> </div>
<div class="collapsed"> <div class="collapsed">
<h2 class="section">Listen for variable changes inside the GUI</h2> <h2 class="section">Listen for variable changes inside the GUI</h2>
<div class="collapsable"> <div class="collapsable">
<div> <div>
<p>To fire a function whenever a user changes a variable via the GUI, use the following syntax:</p> <p>To fire a function whenever a user changes a variable via the GUI, use the following syntax:</p>
<pre class="prettyprint">gui.add(obj, "propertyName").onChange(function(newValue) { <pre class="prettyprint">gui.add(obj, "propertyName").onChange(function(newValue) {
alert("You changed me to " + newValue); alert("You changed me to " + newValue);
});</pre> <p>This can be slightly annoying for types like number or string. You may not want to fire a function while the user is sliding, or while they're typing. To fire a function when the user has <em>finished</em> making changes, use the following:</p> });</pre> <p>This can be slightly annoying for types like number or string. You may not want to fire a function while the user is sliding, or while they're typing. To fire a function when the user has <em>finished</em> making changes, use the following:</p>
<pre class="prettyprint">gui.add(obj, "propertyName").onFinishChange(function(newValue) { <pre class="prettyprint">gui.add(obj, "propertyName").onFinishChange(function(newValue) {
alert("You just finished changing me to " + newValue); alert("You just finished changing me to " + newValue);
});</pre> });</pre>
<p>Finally, if you'd like to do a little something extra when a function is called, use the following:</p> <p>Finally, if you'd like to do a little something extra when a function is called, use the following:</p>
<pre class="prettyprint">gui.add(obj, "functionName").onFire(function() { <pre class="prettyprint last">gui.add(obj, "functionName").onFire(function() {
alert("You called a function with gui-dat"); alert("You called a function with gui-dat");
});</pre> });</pre>
</div> </div>
</div> </div>
</div> </div>
<div class="collapsed"> <div class="collapsed">
<h2 class="section">Listen for variable changes outside of the GUI</h2> <h2 class="section">Listen for variable changes outside of the GUI</h2>
<div class="collapsable"> <div class="collapsable">
<div> <div>
<p>Let's say you have a variable that changes by itself from time to time. If you'd like the GUI to reflect those changes, use the <code>listen()</code> method.</p> <p>Let's say you have a variable that changes by itself from time to time. If you'd like the GUI to reflect those changes, use the <code>listen()</code> method.</p>
<pre class="prettyprint">gui.add(obj, "changingProperty").listen();</pre> <pre class="prettyprint last">gui.add(obj, "changingProperty").listen();</pre>
</div> </div>
</div> </div>
</div> </div>
<div class="collapsed"> <div class="collapsed">
<h2 class="section">Advanced listening</h2> <h2 class="section">Advanced listening</h2>
<div class="collapsable"> <div class="collapsable">
<div> <div>
<p>By default, <strong>gui-dat</strong> will create an internal interval that checks for changes in the values you've marked with <code>listen()</code>. If you'd like to check for these changes in an interval of your own definition, use the following:</p> <p>By default, <strong>gui-dat</strong> will create an internal interval that checks for changes in the values you've marked with <code>listen()</code>. If you'd like to check for these changes in an interval of your own definition, use the following:</p>
<pre class="prettyprint"> <pre class="prettyprint">
gui.autoListen = false; // disables internal interval gui.autoListen = false; // disables internal interval
gui.add(obj, "changingProperty").listen(); gui.add(obj, "changingProperty").listen();
// Make your own loop // Make your own loop
setInterval(function() { setInterval(function() {
gui.listen(); // updates values you've marked with listen() gui.listen(); // updates values you've marked with listen()
}, 1000 / 60);</pre> }, 1000 / 60);</pre>
<p>Alternatively, you can forego calling <code>listen()</code> on individual controllers, and instead choose to monitor changes in <em>all</em> values controlled by your gui.</p> <p>Alternatively, you can forego calling <code>listen()</code> on individual controllers, and instead choose to monitor changes in <em>all</em> values controlled by your gui.</p>
<pre class="prettyprint"> <pre class="prettyprint last">
gui.autoListen = false; // disables internal interval gui.autoListen = false; // disables internal interval
gui.add(obj, "add"); gui.add(obj, "add");
gui.add(obj, "lotsa"); gui.add(obj, "lotsa");
@ -286,26 +276,26 @@ gui.add(obj, "properties");
// Make your own loop // Make your own loop
setInterval(function() { setInterval(function() {
gui.listenAll(); // updates ALL values managed by this gui gui.listenAll(); // updates ALL values managed by this gui
}, 1000 / 60);</pre> }, 1000 / 60);</pre>
</div> </div>
</div> </div>
</div> </div>
<div class="collapsed"> <div class="collapsed">
<h2 class="section">Multiple panels and custom placement</h2> <h2 class="section">Multiple panels and custom placement</h2>
<div class="collapsable"> <div class="collapsable">
<div> <div>
<p>You can instantiate multiple <code>GUI</code> objects and name them however you'd like.</p> <p>You can instantiate multiple <code>GUI</code> objects and name them however you'd like.</p>
<pre class="prettyprint">var gui1 = new GUI(); <pre class="prettyprint">var gui1 = new GUI();
var gui2 = new GUI(); var gui2 = new GUI();
// The name function overwrites the "Show Controls" text. // The name function overwrites the "Show Controls" text.
gui1.name("Utilities"); gui1.name("Utilities");
gui2.name("Camera Placement");</pre> gui2.name("Camera Placement");</pre>
<p>By default, <strong>gui-dat</strong> panels will be automatically added to the HTML document and fixed to the top of the screen. You can disable this behavior / styling and append the gui DOM element to a container of your choosing.</p> <p>By default, <strong>gui-dat</strong> panels will be automatically added to the HTML document and fixed to the top of the screen. You can disable this behavior / styling and append the gui DOM element to a container of your choosing.</p>
<pre class="prettyprint"> <pre class="prettyprint last">
// Notice this belongs to the GUI class (uppercase) // Notice this belongs to the GUI class (uppercase)
// and not an instance thereof. // and not an instance thereof.
GUI.autoPlace = false; GUI.autoPlace = false;
@ -318,26 +308,26 @@ gui.domElement.style.top = "20px";
gui.domElement.style.left = "20px"; gui.domElement.style.left = "20px";
document.getElementById("my-gui-container").appendChild( gui.domElement );</pre> document.getElementById("my-gui-container").appendChild( gui.domElement );</pre>
</div> </div>
</div> </div>
</div> </div>
<div class="collapsed"> <div class="collapsed">
<h2 class="section">Pro tips.</h2> <h2 class="section">Pro tips.</h2>
<div class="collapsable"> <div class="collapsable">
<div> <div>
<ol id="secrets"> <ol id="secrets">
<li><strong>gui-dat</strong> panels are resizeable. Drag the show/hide button.</li> <li><strong>gui-dat</strong> panels are resizeable. Drag the show/hide button.</li>
<li>Pro tip #2 forthcoming.</li> <li>Pro tip #2 forthcoming.</li>
</ol> </ol>
</div> </div>
</div> </div>
</div> </div>
<div class = "trans">&nbsp;</div> <div class = "trans">&nbsp;</div>
<footer class = "trans">Initiated by <a href="http://georgemichaelbrower.com/">George Michael Brower</a> and <a href="http://jonobr1.com/">Jono Brandel</a> of the Data Arts Team, Google Creative Lab. <footer class = "trans">Initiated by <a href="http://georgemichaelbrower.com/">George Michael Brower</a> and <a href="http://jonobr1.com/">Jono Brandel</a> of the Data Arts Team, Google Creative Lab.
</footer> </footer>
</body> </body>
</html> </html>