mirror of
https://github.com/dataarts/dat.gui.git
synced 2024-12-12 04:08:27 +00:00
Merged
This commit is contained in:
commit
a58471aa70
@ -4,8 +4,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
padding: 0 20px 20px 20px;
|
|
||||||
font: 9.5px/13px Lucida Grande, sans-serif;
|
font: 9.5px/13px Lucida Grande, sans-serif;
|
||||||
|
padding: 0 20px 20px 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1, h2, h3, h4, h5, h6 {
|
h1, h2, h3, h4, h5, h6 {
|
||||||
@ -18,7 +18,7 @@ h1 {
|
|||||||
font-weight: 800;
|
font-weight: 800;
|
||||||
text-transform: lowercase;
|
text-transform: lowercase;
|
||||||
line-height: 80px;
|
line-height: 80px;
|
||||||
margin: 20px 0 0 0;
|
margin: 20px 0 20px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 a:link, h1 a:visited, h1 a:hover, h1 a:active {
|
h1 a:link, h1 a:visited, h1 a:hover, h1 a:active {
|
||||||
@ -31,11 +31,22 @@ h1 img {
|
|||||||
height: 45px;
|
height: 45px;
|
||||||
-moz-border-radius: 9px;
|
-moz-border-radius: 9px;
|
||||||
border-radius: 9px;
|
border-radius: 9px;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
h2 {
|
h2 {
|
||||||
font-size: 18px;
|
margin-top: 30px;
|
||||||
|
font-size: 18px;
|
||||||
|
margin-bottom: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#helvetica-demo {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
width: 800;
|
||||||
|
height: 300;
|
||||||
|
z-index: -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre {
|
pre {
|
||||||
@ -46,39 +57,62 @@ pre {
|
|||||||
font: 10px Monaco, monospace;
|
font: 10px Monaco, monospace;
|
||||||
}
|
}
|
||||||
|
|
||||||
p { font-size: 125%; max-width: 530px; line-height: 18px; margin-bottom: 36px; }
|
p, ul {
|
||||||
|
font-size: 125%;
|
||||||
|
max-width: 530px;
|
||||||
|
line-height: 18px;
|
||||||
|
margin-bottom: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
li {
|
||||||
|
margin-left: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul#desc {
|
||||||
|
list-style: circle;
|
||||||
|
font-size: 100%;
|
||||||
|
max-width: 380px;
|
||||||
|
}
|
||||||
|
|
||||||
a:link {
|
a:link {
|
||||||
color: #00aeff;
|
color: #00aeff;
|
||||||
}
|
}
|
||||||
|
|
||||||
a:visited {
|
a:visited {
|
||||||
color: #0fa954;
|
color: #0fa954;
|
||||||
}
|
}
|
||||||
|
|
||||||
a:hover {
|
a:hover {
|
||||||
color: #e61d5f;
|
color: #e61d5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
a:active {
|
a:active {
|
||||||
color: #54396e;
|
color: #54396e;
|
||||||
}
|
}
|
||||||
|
|
||||||
footer {
|
footer {
|
||||||
background-color: #eee;
|
background-color: #eee;
|
||||||
width: 510px;
|
width: 510px;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#columns {
|
pre a:link,
|
||||||
position: fixed;
|
pre a:visited,
|
||||||
bottom: 0;
|
pre a:active {
|
||||||
left: 0;
|
color: #ccc;
|
||||||
width: 100%;
|
|
||||||
height: 10px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#columns div {
|
pre a:hover {
|
||||||
float: left;
|
color: #e61d5f;
|
||||||
width : auto;
|
}
|
||||||
height: 10px;
|
|
||||||
|
code {
|
||||||
|
font: 10px Monaco, monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
code strong {
|
||||||
|
font-weight: normal;
|
||||||
|
color: #e61d5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* SPAN elements with the classes below are added by prettyprint. */
|
/* SPAN elements with the classes below are added by prettyprint. */
|
||||||
|
123
demo/demo.js
123
demo/demo.js
@ -1,18 +1,28 @@
|
|||||||
function DynamicText(message, width, height, textAscent) {
|
function FizzyText(message) {
|
||||||
|
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
this.growthSpeed = 0.1;
|
var width = 550;
|
||||||
|
var height = 200;
|
||||||
|
var textAscent = 82;
|
||||||
|
var textLeft = 80;
|
||||||
|
|
||||||
|
|
||||||
|
this.growthSpeed = 0.5;
|
||||||
this.minSize = 0;
|
this.minSize = 0;
|
||||||
this.maxSize = 5;
|
this.maxSize = 3.2;
|
||||||
|
|
||||||
var message = message;
|
this.noiseScale = 300;
|
||||||
|
this.noiseStrength = 10;
|
||||||
|
this.speed = 0.4;
|
||||||
|
|
||||||
this.width = width;
|
this.displayOutline = false;
|
||||||
this.height = height;
|
|
||||||
|
|
||||||
this.textAscent = textAscent;
|
this.textAscent = textAscent;
|
||||||
|
|
||||||
|
|
||||||
|
var colors = ["#00aeff", "#0fa954", "#54396e", "#e61d5f"];
|
||||||
|
|
||||||
var r = document.createElement('canvas');
|
var r = document.createElement('canvas');
|
||||||
var s = r.getContext('2d');
|
var s = r.getContext('2d');
|
||||||
|
|
||||||
@ -29,19 +39,19 @@ function DynamicText(message, width, height, textAscent) {
|
|||||||
var pixels = [];
|
var pixels = [];
|
||||||
var particles = [];
|
var particles = [];
|
||||||
|
|
||||||
s.font = "800 "+textAscent+"px helvetica, arial, sans-serif";
|
s.font = g.font = "800 " + textAscent + "px helvetica, arial, sans-serif";
|
||||||
|
|
||||||
// Set reference onto particles
|
// Set reference onto particles
|
||||||
for (var i = 0; i < 1000; i++) {
|
for (var i = 0; i < 1000; i++) {
|
||||||
particles.push( new Particle(Math.random()*width, Math.random()*height));
|
particles.push(new Particle(Math.random() * width, Math.random() * height));
|
||||||
}
|
}
|
||||||
|
|
||||||
var createBitmap = function(m) {
|
var createBitmap = function (m) {
|
||||||
s.fillStyle = "#fff";
|
s.fillStyle = "#fff";
|
||||||
s.fillRect(0, 0, width, height);
|
s.fillRect(0, 0, width, height);
|
||||||
|
|
||||||
s.fillStyle = "#222";
|
s.fillStyle = "#222";
|
||||||
s.fillText(m, 0, textAscent);
|
s.fillText(m, textLeft, textAscent);
|
||||||
|
|
||||||
// Pull reference
|
// Pull reference
|
||||||
var imageData = s.getImageData(0, 0, width, height);
|
var imageData = s.getImageData(0, 0, width, height);
|
||||||
@ -49,63 +59,108 @@ function DynamicText(message, width, height, textAscent) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var render = function() {
|
var render = function () {
|
||||||
|
|
||||||
g.clearRect(0, 0, width, height);
|
g.clearRect(0, 0, width, height);
|
||||||
|
|
||||||
for (var i = 0; i < particles.length; i++) {
|
if (_this.displayOutline) {
|
||||||
particles[i].update();
|
g.globalCompositeOperation = "source-over";
|
||||||
particles[i].draw();
|
g.strokeStyle = "#000";
|
||||||
|
g.lineWidth = .5;
|
||||||
|
g.strokeText(message, textLeft, textAscent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g.globalCompositeOperation = "darker";
|
||||||
|
|
||||||
|
for (var i = 0; i < particles.length; i++) {
|
||||||
|
g.fillStyle = colors[i % colors.length];
|
||||||
|
particles[i].render();
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var getPosition = function(i) {
|
var getPosition = function (i) {
|
||||||
return { x: (i - (width * 4) * Math.floor(i/(width * 4))) / 4, y: Math.floor(i/(width * 4)) };
|
return {
|
||||||
|
x: (i - (width * 4) * Math.floor(i / (width * 4))) / 4,
|
||||||
|
y: Math.floor(i / (width * 4))
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
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 = { r: pixels[base + 0], g: pixels[base + 1], b: pixels[base + 2], a: pixels[base + 3]};
|
var c = {
|
||||||
|
r: pixels[base + 0],
|
||||||
return "rgb("+c.r+","+c.g+","+c.b+")";
|
g: pixels[base + 1],
|
||||||
|
b: pixels[base + 2],
|
||||||
|
a: pixels[base + 3]
|
||||||
};
|
};
|
||||||
|
|
||||||
this.__defineGetter__("message", function() {
|
return "rgb(" + c.r + "," + c.g + "," + c.b + ")";
|
||||||
|
};
|
||||||
|
|
||||||
|
this.__defineGetter__("message", function () {
|
||||||
return message;
|
return message;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.__defineSetter__("message", function(m) {
|
this.__defineSetter__("message", function (m) {
|
||||||
message = m;
|
message = m;
|
||||||
createBitmap(message);
|
createBitmap(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
createBitmap(message);
|
this.explode = function() {
|
||||||
|
var mag = Math.random()*30+30;
|
||||||
|
for (var i in particles) {
|
||||||
|
var angle= Math.random()*Math.PI*2;
|
||||||
|
particles[i].vx = Math.cos(angle)*mag;
|
||||||
|
particles[i].vy = Math.sin(angle)*mag;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.message = message;
|
||||||
|
|
||||||
setInterval(render, 30);
|
setInterval(render, 30);
|
||||||
|
|
||||||
function Particle(x, y, c) {
|
function Particle(x, y, c) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
|
|
||||||
|
this.vx = 0;
|
||||||
|
this.vy = 0;
|
||||||
this.r = 0;
|
this.r = 0;
|
||||||
this.update = function() {
|
|
||||||
this.x += Math.random() - Math.random();
|
this.render = function () {
|
||||||
this.y += Math.random() - Math.random();
|
|
||||||
}
|
|
||||||
this.draw = function() {
|
|
||||||
var c = getColor(this.x, this.y);
|
var c = getColor(this.x, this.y);
|
||||||
if (c == "rgb(255,255,255)") {
|
var angle = noise(this.x / _this.noiseScale, this.y / _this.noiseScale) * _this.noiseStrength;
|
||||||
this.r -= _this.growthSpeed;
|
|
||||||
} else {
|
var onScreen = this.x > 0 && this.x < width &&
|
||||||
|
this.y > 0 && this.y < height;
|
||||||
|
var isBlack = c != "rgb(255,255,255)" &&
|
||||||
|
onScreen;
|
||||||
|
|
||||||
|
if (isBlack) {
|
||||||
this.r += _this.growthSpeed;
|
this.r += _this.growthSpeed;
|
||||||
|
} else {
|
||||||
|
this.r -= _this.growthSpeed;
|
||||||
}
|
}
|
||||||
|
this.vx *= 0.5;
|
||||||
|
this.vy *= 0.5;
|
||||||
|
this.x += Math.cos(angle) * _this.speed + this.vx;
|
||||||
|
this.y += -Math.sin(angle) * _this.speed + this.vy;
|
||||||
this.r = constrain(this.r, _this.minSize, _this.maxSize);
|
this.r = constrain(this.r, _this.minSize, _this.maxSize);
|
||||||
|
if (this.r <= _this.minSize) {
|
||||||
|
this.x = Math.random() * width;
|
||||||
|
this.y = Math.random() * height;
|
||||||
|
}
|
||||||
|
if (this.r <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
g.beginPath();
|
g.beginPath();
|
||||||
g.arc(this.x, this.y, this.r, 0, Math.PI*2, false);
|
g.arc(this.x, this.y, this.r, 0, Math.PI * 2, false);
|
||||||
g.fill();
|
g.fill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var constrain = function (v, o1, o2) {
|
||||||
var constrain = function(v, o1, o2) {
|
|
||||||
if (v < o1) v = o1;
|
if (v < o1) v = o1;
|
||||||
else if (v > o2) v = o2;
|
else if (v > o2) v = o2;
|
||||||
return v;
|
return v;
|
||||||
|
181
demo/improvedNoise.js
Normal file
181
demo/improvedNoise.js
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
// http://mrl.nyu.edu/~perlin/noise/
|
||||||
|
|
||||||
|
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,
|
||||||
|
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,
|
||||||
|
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,
|
||||||
|
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,
|
||||||
|
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,
|
||||||
|
93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180];
|
||||||
|
|
||||||
|
for ( var i = 0; i < 256 ; i++ ) {
|
||||||
|
|
||||||
|
p[ 256 + i ] = p[ i ];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function fade( t ) {
|
||||||
|
|
||||||
|
return t * t * t * ( t * ( t * 6 - 15 ) + 10 );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function lerp( t, a, b ) {
|
||||||
|
|
||||||
|
return a + t * ( b - a );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function grad( hash, x, y, z ) {
|
||||||
|
|
||||||
|
var h = hash & 15;
|
||||||
|
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 {
|
||||||
|
|
||||||
|
noise: function ( x, y, z ) {
|
||||||
|
|
||||||
|
var floorX = Math.floor( x ), floorY = Math.floor( y ), floorZ = Math.floor( z );
|
||||||
|
|
||||||
|
var X = floorX & 255, Y = floorY & 255, Z = floorZ & 255;
|
||||||
|
|
||||||
|
x -= floorX;
|
||||||
|
y -= floorY;
|
||||||
|
z -= floorZ;
|
||||||
|
|
||||||
|
var xMinus1 = x -1, yMinus1 = y - 1, zMinus1 = z - 1;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
return lerp( w, lerp( v, lerp( u, grad( p[ AA ], x, y, z ),
|
||||||
|
grad( p[ BA ], xMinus1, y, z ) ),
|
||||||
|
lerp( u, grad( p[ AB ], x, yMinus1, z ),
|
||||||
|
grad( p[ BB ], xMinus1, yMinus1, z ) ) ),
|
||||||
|
lerp( v, lerp( u, grad( p[ AA + 1 ], x, y, zMinus1 ),
|
||||||
|
grad( p[ BA + 1 ], xMinus1, y, z - 1 ) ),
|
||||||
|
lerp( u, grad( p[ AB + 1 ], x, yMinus1, zMinus1 ),
|
||||||
|
grad( p[ BB + 1 ], xMinus1, yMinus1, zMinus1 ) ) ) );
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var currentRandom = Math.random;
|
||||||
|
|
||||||
|
// Pseudo-random generator
|
||||||
|
function Marsaglia(i1, i2) {
|
||||||
|
// from http://www.math.uni-bielefeld.de/~sillke/ALGORITHMS/random/marsaglia-c
|
||||||
|
var z=i1 || 362436069, w= i2 || 521288629;
|
||||||
|
var nextInt = function() {
|
||||||
|
z=(36969*(z&65535)+(z>>>16)) & 0xFFFFFFFF;
|
||||||
|
w=(18000*(w&65535)+(w>>>16)) & 0xFFFFFFFF;
|
||||||
|
return (((z&0xFFFF)<<16) | (w&0xFFFF)) & 0xFFFFFFFF;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.nextDouble = function() {
|
||||||
|
var i = nextInt() / 4294967296;
|
||||||
|
return i < 0 ? 1 + i : i;
|
||||||
|
};
|
||||||
|
this.nextInt = nextInt;
|
||||||
|
}
|
||||||
|
Marsaglia.createRandomized = function() {
|
||||||
|
var now = new Date();
|
||||||
|
return new Marsaglia((now / 60000) & 0xFFFFFFFF, now & 0xFFFFFFFF);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Noise functions and helpers
|
||||||
|
function PerlinNoise(seed) {
|
||||||
|
var rnd = seed !== undefined ? new Marsaglia(seed) : Marsaglia.createRandomized();
|
||||||
|
var i, j;
|
||||||
|
// http://www.noisemachine.com/talk1/17b.html
|
||||||
|
// http://mrl.nyu.edu/~perlin/noise/
|
||||||
|
// generate permutation
|
||||||
|
var p = new Array(512);
|
||||||
|
for(i=0;i<256;++i) { p[i] = i; }
|
||||||
|
for(i=0;i<256;++i) { var t = p[j = rnd.nextInt() & 0xFF]; p[j] = p[i]; p[i] = t; }
|
||||||
|
// copy to avoid taking mod in p[0];
|
||||||
|
for(i=0;i<256;++i) { p[i + 256] = p[i]; }
|
||||||
|
|
||||||
|
function grad3d(i,x,y,z) {
|
||||||
|
var h = i & 15; // convert into 12 gradient directions
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
function grad2d(i,x,y) {
|
||||||
|
var v = (i & 1) === 0 ? x : y;
|
||||||
|
return (i&2) === 0 ? -v : v;
|
||||||
|
}
|
||||||
|
|
||||||
|
function grad1d(i,x) {
|
||||||
|
return (i&1) === 0 ? -x : x;
|
||||||
|
}
|
||||||
|
|
||||||
|
function lerp(t,a,b) { return a + t * (b - a); }
|
||||||
|
|
||||||
|
this.noise3d = function(x, y, z) {
|
||||||
|
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);
|
||||||
|
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;
|
||||||
|
return lerp(fz,
|
||||||
|
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(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))));
|
||||||
|
};
|
||||||
|
|
||||||
|
this.noise2d = function(x, y) {
|
||||||
|
var X = Math.floor(x)&255, Y = Math.floor(y)&255;
|
||||||
|
x -= Math.floor(x); y -= Math.floor(y);
|
||||||
|
var fx = (3-2*x)*x*x, fy = (3-2*y)*y*y;
|
||||||
|
var p0 = p[X]+Y, p1 = p[X + 1] + Y;
|
||||||
|
return lerp(fy,
|
||||||
|
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)));
|
||||||
|
};
|
||||||
|
|
||||||
|
this.noise1d = function(x) {
|
||||||
|
var X = Math.floor(x)&255;
|
||||||
|
x -= Math.floor(x);
|
||||||
|
var fx = (3-2*x)*x*x;
|
||||||
|
return lerp(fx, grad1d(p[X], x), grad1d(p[X+1], x-1));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// these are lifted from Processing.js
|
||||||
|
// processing defaults
|
||||||
|
var noiseProfile = { generator: undefined, octaves: 4, fallout: 0.5, seed: undefined};
|
||||||
|
|
||||||
|
function noise(x, y, z) {
|
||||||
|
if(noiseProfile.generator === undefined) {
|
||||||
|
// caching
|
||||||
|
noiseProfile.generator = new PerlinNoise(noiseProfile.seed);
|
||||||
|
}
|
||||||
|
var generator = noiseProfile.generator;
|
||||||
|
var effect = 1, k = 1, sum = 0;
|
||||||
|
for(var i=0; i<noiseProfile.octaves; ++i) {
|
||||||
|
effect *= noiseProfile.fallout;
|
||||||
|
switch (arguments.length) {
|
||||||
|
case 1:
|
||||||
|
sum += effect * (1 + generator.noise1d(k*x))/2; break;
|
||||||
|
case 2:
|
||||||
|
sum += effect * (1 + generator.noise2d(k*x, k*y))/2; break;
|
||||||
|
case 3:
|
||||||
|
sum += effect * (1 + generator.noise3d(k*x, k*y, k*z))/2; break;
|
||||||
|
}
|
||||||
|
k *= 2;
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
};
|
489
gui-tobeminified.js
Normal file
489
gui-tobeminified.js
Normal file
@ -0,0 +1,489 @@
|
|||||||
|
// This version of gui.js appends the style definitions via javascript.
|
||||||
|
var GUI = new function() {
|
||||||
|
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
|
var controllers = [];
|
||||||
|
|
||||||
|
var style = '#guidat{color:#fff;position:fixed;width:280px;z-index:200;opacity:.97;top:0;left:100%;margin-left:-300px;background-color:#fff;-moz-transition:margin-top .2s ease-out;-webkit-transition:margin-top .2s ease-out;transition:margin-top .2s ease-out;-webkit-box-shadow:0 0 10px rgba(0,0,0,0.3);-moz-box-shadow:0 0 10px rgba(0,0,0,0.3);box-shadow:0 0 10px rgba(0,0,0,0.3)}#guidat,#guidat input{font:9.5px Lucida Grande,sans-serif}#guidat-controllers{height:300px;overflow-y:auto;overflow-x:hidden;background-color:rgba(0,0,0,0.1)}#guidat-toggle{text-decoration:none;cursor:pointer;color:#fff;background-color:#222;text-align:center;display:block;padding:5px}#guidat-toggle:hover{background-color:#000}.guidat-controller{padding:3px;height:25px;clear:left;border-bottom:1px solid #222;background-color:#111}.guidat-controller,.guidat-controller input,.guidat-slider-bg,.guidat-slider-fg{-moz-transition:background-color .15s linear;-webkit-transition:background-color .15s linear;transition:background-color .15s linear}.guidat-controller.boolean:hover,.guidat-controller.function:hover{background-color:#000}.guidat-controller input{float:right;outline:none;border:0;padding:4px;margin-top:2px;background-color:#222}.guidat-controller input:hover{background-color:#444}.guidat-controller input:focus{background-color:#555}.guidat-controller.number{border-left:5px solid #00aeff}.guidat-controller.string{border-left:5px solid #1ed36f}.guidat-controller.string input{border:0;color:#1ed36f;margin-right:2px;width:148px}.guidat-controller.boolean{border-left:5px solid #54396e}.guidat-controller.function{border-left:5px solid #e61d5f}.guidat-controller.number input[type=text]{width:35px;margin-left:5px;margin-right:2px;color:#00aeff}#guidat .guidat-controller.boolean input{margin-top:6px;margin-right:2px;font-size:20px}.guidat-controller:last-child{border-bottom:none;-webkit-box-shadow:0 1px 3px rgba(0,0,0,0.5);-moz-box-shadow:0 1px 3px rgba(0,0,0,0.5);box-shadow:0 1px 3px rgba(0,0,0,0.5)}.guidat-propertyname{padding:5px;padding-top:7px;cursor:default;display:inline-block}.guidat-slider-bg:hover,.guidat-slider-bg.active{background-color:#444}.guidat-slider-bg:hover .guidat-slider-fg,.guidat-slider-bg.active .guidat-slider-fg{background-color:#52c8ff}.guidat-slider-bg{background-color:#222;cursor:ew-resize;width:40%;margin-top:2px;float:right;height:21px}.guidat-slider-fg{background-color:#00aeff;height:20px}'
|
||||||
|
|
||||||
|
|
||||||
|
this.add = function() {
|
||||||
|
|
||||||
|
// We need to call GUI.start() before .add()
|
||||||
|
if (!started) {
|
||||||
|
error("Make sure to call GUI.start() in the window.onload function");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var object = arguments[0];
|
||||||
|
var propertyName = arguments[1];
|
||||||
|
|
||||||
|
// Have we already added this?
|
||||||
|
if (alreadyControlled(object, propertyName)) {
|
||||||
|
error("Controller for \"" + propertyName+"\" already added.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var value = object[propertyName];
|
||||||
|
|
||||||
|
// Does this value exist? Is it accessible?
|
||||||
|
if (value == undefined) {
|
||||||
|
error(object + " either has no property \""+propertyName+"\", or the property is inaccessible.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var type = typeof value;
|
||||||
|
var handler = addHandlers[type];
|
||||||
|
|
||||||
|
// Do we know how to deal with this data type?
|
||||||
|
if (handler == undefined) {
|
||||||
|
error("Cannot create controller for data type \""+type+"\"");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var controllerObject = handler.apply(this, arguments);
|
||||||
|
|
||||||
|
// Were we able to make the controller?
|
||||||
|
if (!controllerObject) {
|
||||||
|
error("Error creating controller for \""+propertyName+"\".");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Success.
|
||||||
|
controllerContainer.appendChild(controllerObject.domElement);
|
||||||
|
controllers.push(controllerObject);
|
||||||
|
|
||||||
|
return controllerObject;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var addHandlers = {
|
||||||
|
|
||||||
|
"number": function() {
|
||||||
|
return construct(NumberController, arguments);
|
||||||
|
},
|
||||||
|
|
||||||
|
"string": function() {
|
||||||
|
return construct(StringController, arguments);
|
||||||
|
},
|
||||||
|
|
||||||
|
"boolean": function() {
|
||||||
|
return construct(BooleanController, arguments);
|
||||||
|
},
|
||||||
|
|
||||||
|
"function": function() {
|
||||||
|
return construct(FunctionController, arguments);
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
var alreadyControlled = function(object, propertyName) {
|
||||||
|
for (var i in controllers) {
|
||||||
|
if (controllers[i].object == object &&
|
||||||
|
controllers[i].propertyName == propertyName) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
var error = function(str) {
|
||||||
|
if (typeof console.log == 'function') {
|
||||||
|
console.error("[GUI ERROR] " + str);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var construct = function(constructor, args) {
|
||||||
|
function F() {
|
||||||
|
return constructor.apply(this, args);
|
||||||
|
}
|
||||||
|
F.prototype = constructor.prototype;
|
||||||
|
return new F();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// GUI ... GUI
|
||||||
|
|
||||||
|
this.domElement = null;
|
||||||
|
var controllerContainer;
|
||||||
|
var started = false;
|
||||||
|
var open = false;
|
||||||
|
|
||||||
|
// TODO: obtain this dynamically?
|
||||||
|
var domElementMarginTop = 300;
|
||||||
|
|
||||||
|
this.start = function() {
|
||||||
|
|
||||||
|
var styleSheet = document.createElement('style');
|
||||||
|
styleSheet.setAttribute('type', 'text/css');
|
||||||
|
styleSheet.innerHTML = style;
|
||||||
|
document.getElementsByTagName('head')[0].appendChild(styleSheet);
|
||||||
|
|
||||||
|
|
||||||
|
this.domElement = document.createElement('div');
|
||||||
|
this.domElement.setAttribute('id', 'guidat');
|
||||||
|
|
||||||
|
controllerContainer = document.createElement('div');
|
||||||
|
controllerContainer.setAttribute('id', 'guidat-controllers');
|
||||||
|
|
||||||
|
toggleButton = document.createElement('a');
|
||||||
|
toggleButton.setAttribute('id', 'guidat-toggle');
|
||||||
|
toggleButton.setAttribute('href', '#');
|
||||||
|
toggleButton.innerHTML = "Show Controls";
|
||||||
|
toggleButton.addEventListener('click', function(e) {
|
||||||
|
_this.toggle();
|
||||||
|
e.preventDefault();
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
this.domElement.appendChild(controllerContainer);
|
||||||
|
this.domElement.appendChild(toggleButton);
|
||||||
|
|
||||||
|
this.domElement.style.marginTop = -domElementMarginTop+"px";
|
||||||
|
|
||||||
|
document.body.appendChild(this.domElement);
|
||||||
|
|
||||||
|
started = true;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
this.toggle = function() {
|
||||||
|
|
||||||
|
if (open) {
|
||||||
|
this.hide();
|
||||||
|
} else {
|
||||||
|
this.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
this.show = function() {
|
||||||
|
this.domElement.style.marginTop = 0+"px";
|
||||||
|
toggleButton.innerHTML = "Hide Controls";
|
||||||
|
open = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.hide = function() {
|
||||||
|
this.domElement.style.marginTop = -domElementMarginTop+"px";
|
||||||
|
toggleButton.innerHTML = "Show Controls";
|
||||||
|
open = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
// TODO: Leaving the window while dragging the slider and then removing the mouse
|
||||||
|
// still leaves slider in focus.
|
||||||
|
// TODO: Problem with multiple sliders.
|
||||||
|
var 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.fg = document.createElement('div');
|
||||||
|
this.domElement.setAttribute('class', 'guidat-slider-bg');
|
||||||
|
this.fg.setAttribute('class', 'guidat-slider-fg');
|
||||||
|
|
||||||
|
this.domElement.appendChild(this.fg);
|
||||||
|
|
||||||
|
var map = function(v, i1, i2, o1, o2) {
|
||||||
|
var v = o1 + (o2 - o1) * ((v - i1) / (i2 - i1));
|
||||||
|
if (v < o1) v = o1;
|
||||||
|
else if (v > o2) v = o2;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = 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 = map(e.pageX, pos[0], pos[0] + _this.domElement.offsetWidth, min, max);
|
||||||
|
val = Math.round(val/step)*step;
|
||||||
|
numberController.updateValue(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);
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
|
||||||
|
document.addEventListener('mouseup', function(e) {
|
||||||
|
_this.domElement.setAttribute('class', 'guidat-slider-bg');
|
||||||
|
_this.fg.setAttribute('class', 'guidat-slider-fg');
|
||||||
|
clicked = false;
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
document.addEventListener('mousemove', onDrag, false);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
this.value = initValue;
|
||||||
|
|
||||||
|
}
|
||||||
|
var Controller = function() {
|
||||||
|
|
||||||
|
var onChange = null;
|
||||||
|
|
||||||
|
this.setName = function(n) {
|
||||||
|
this.propertyNameElement.innerHTML = n;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setValue = function(n) {
|
||||||
|
this.object[this.propertyName] = n;
|
||||||
|
if (onChange != null) {
|
||||||
|
onChange.call(this, n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getValue = function() {
|
||||||
|
return this.object[this.propertyName];
|
||||||
|
}
|
||||||
|
|
||||||
|
this.onChange = function(fnc) {
|
||||||
|
onChange = fnc;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.makeUnselectable = function(elem) {
|
||||||
|
elem.onselectstart = function() { return false; };
|
||||||
|
elem.style.MozUserSelect = "none";
|
||||||
|
elem.style.KhtmlUserSelect = "none";
|
||||||
|
elem.unselectable = "on";
|
||||||
|
}
|
||||||
|
|
||||||
|
this.makeSelectable = function(elem) {
|
||||||
|
elem.onselectstart = function() { };
|
||||||
|
elem.style.MozUserSelect = "auto";
|
||||||
|
elem.style.KhtmlUserSelect = "auto";
|
||||||
|
elem.unselectable = "off";
|
||||||
|
}
|
||||||
|
|
||||||
|
this.domElement = document.createElement('div');
|
||||||
|
this.domElement.setAttribute('class', 'guidat-controller ' + this.type);
|
||||||
|
|
||||||
|
this.object = arguments[0];
|
||||||
|
this.propertyName = arguments[1];
|
||||||
|
|
||||||
|
this.propertyNameElement = document.createElement('span');
|
||||||
|
this.propertyNameElement.setAttribute('class', 'guidat-propertyname');
|
||||||
|
this.setName(this.propertyName);
|
||||||
|
this.domElement.appendChild(this.propertyNameElement);
|
||||||
|
|
||||||
|
this.makeUnselectable(this.domElement);
|
||||||
|
|
||||||
|
};
|
||||||
|
var BooleanController = function() {
|
||||||
|
this.type = "boolean";
|
||||||
|
Controller.apply(this, arguments);
|
||||||
|
|
||||||
|
var _this = this;
|
||||||
|
var input = document.createElement('input');
|
||||||
|
input.setAttribute('type', 'checkbox');
|
||||||
|
|
||||||
|
this.domElement.addEventListener('click', function(e) {
|
||||||
|
input.checked = !input.checked;
|
||||||
|
e.preventDefault();
|
||||||
|
_this.setValue(input.checked);
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
input.addEventListener('mouseup', function(e) {
|
||||||
|
input.checked = !input.checked; // counteracts default.
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
this.domElement.style.cursor = "pointer";
|
||||||
|
this.propertyNameElement.style.cursor = "pointer";
|
||||||
|
this.domElement.appendChild(input);
|
||||||
|
|
||||||
|
};
|
||||||
|
BooleanController.prototype = new Controller();
|
||||||
|
BooleanController.prototype.constructor = BooleanController;
|
||||||
|
var FunctionController = function() {
|
||||||
|
this.type = "function";
|
||||||
|
var _this = this;
|
||||||
|
Controller.apply(this, arguments);
|
||||||
|
this.domElement.addEventListener('click', function() {
|
||||||
|
_this.object[_this.propertyName].call(_this.object);
|
||||||
|
}, false);
|
||||||
|
this.domElement.style.cursor = "pointer";
|
||||||
|
this.propertyNameElement.style.cursor = "pointer";
|
||||||
|
};
|
||||||
|
FunctionController.prototype = new Controller();
|
||||||
|
FunctionController.prototype.constructor = FunctionController;
|
||||||
|
// TODO: Provide alternate controllers for non-html5 browsers?
|
||||||
|
var NumberController = function() {
|
||||||
|
|
||||||
|
this.type = "number";
|
||||||
|
|
||||||
|
Controller.apply(this, arguments);
|
||||||
|
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
|
// 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
|
||||||
|
var draggedNumberField = false;
|
||||||
|
|
||||||
|
var clickedNumberField = false;
|
||||||
|
|
||||||
|
var y = py = 0;
|
||||||
|
|
||||||
|
var min = arguments[2];
|
||||||
|
var max = arguments[3];
|
||||||
|
var step = arguments[4];
|
||||||
|
|
||||||
|
if (!step) {
|
||||||
|
if (min && max) {
|
||||||
|
step = (max-min)*0.01;
|
||||||
|
} else {
|
||||||
|
step = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var numberField = document.createElement('input');
|
||||||
|
numberField.setAttribute('id', this.propertyName);
|
||||||
|
|
||||||
|
// Little up and down arrows are pissing me off.
|
||||||
|
numberField.setAttribute('type', 'text');
|
||||||
|
numberField.setAttribute('value', this.getValue());
|
||||||
|
|
||||||
|
if (step) numberField.setAttribute('step', step);
|
||||||
|
|
||||||
|
this.domElement.appendChild(numberField);
|
||||||
|
|
||||||
|
var slider;
|
||||||
|
|
||||||
|
if (min != undefined && max != undefined) {
|
||||||
|
slider = new Slider(this, min, max, step, this.getValue());
|
||||||
|
this.domElement.appendChild(slider.domElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
numberField.addEventListener('blur', function(e) {
|
||||||
|
var val = parseFloat(this.value);
|
||||||
|
if (!isNaN(val)) {
|
||||||
|
_this.updateValue(val);
|
||||||
|
} else {
|
||||||
|
this.value = _this.getValue();
|
||||||
|
}
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
numberField.addEventListener('mousewheel', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
this.updateValue(_this.getValue() + Math.abs(e.wheelDeltaY)/e.wheelDeltaY*step);
|
||||||
|
return false;
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
numberField.addEventListener('mousedown', function(e) {
|
||||||
|
py = y = e.pageY;
|
||||||
|
clickedNumberField = true;
|
||||||
|
document.addEventListener('mousemove', dragNumberField, false);
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
document.addEventListener('mouseup', function(e) {
|
||||||
|
document.removeEventListener('mousemove', dragNumberField, false);
|
||||||
|
_this.makeSelectable(GUI.domElement);
|
||||||
|
_this.makeSelectable(numberField);
|
||||||
|
if (clickedNumberField && !draggedNumberField) {
|
||||||
|
numberField.focus();
|
||||||
|
numberField.select();
|
||||||
|
}
|
||||||
|
draggedNumberField = false;
|
||||||
|
clickedNumberField = false;
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
// Kinda nast
|
||||||
|
if (navigator.appVersion.indexOf('chrome') != -1) {
|
||||||
|
document.addEventListener('mouseout', function(e) {
|
||||||
|
document.removeEventListener('mousemove', dragNumberField, false);
|
||||||
|
}, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
var dragNumberField = function(e) {
|
||||||
|
draggedNumberField = true;
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
_this.makeUnselectable(GUI.domElement);
|
||||||
|
_this.makeUnselectable(numberField);
|
||||||
|
|
||||||
|
py = y;
|
||||||
|
y = e.pageY;
|
||||||
|
var dy = py - y;
|
||||||
|
var newVal = _this.getValue() + dy*step;
|
||||||
|
_this.updateValue(newVal);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateValue = function(val) {
|
||||||
|
|
||||||
|
val = parseFloat(val);
|
||||||
|
|
||||||
|
if (min != undefined && val <= min) {
|
||||||
|
val = min;
|
||||||
|
} else if (max != undefined && val >= max) {
|
||||||
|
val = max;
|
||||||
|
}
|
||||||
|
_this.setValue(val);
|
||||||
|
|
||||||
|
numberField.value = _this.getValue();
|
||||||
|
if (slider) slider.value = _this.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
NumberController.prototype = new Controller();
|
||||||
|
NumberController.prototype.constructor = NumberController;
|
||||||
|
var StringController = function() {
|
||||||
|
|
||||||
|
this.type = "string";
|
||||||
|
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
|
Controller.apply(this, arguments);
|
||||||
|
|
||||||
|
var input = document.createElement('input');
|
||||||
|
|
||||||
|
var initialValue = this.getValue();
|
||||||
|
|
||||||
|
input.setAttribute('value', initialValue);
|
||||||
|
input.setAttribute('spellcheck', 'false');
|
||||||
|
this.domElement.addEventListener('mouseup', function() {
|
||||||
|
input.focus();
|
||||||
|
input.select();
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
input.addEventListener('keyup', function() {
|
||||||
|
_this.setValue(input.value);
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
this.domElement.appendChild(input);
|
||||||
|
};
|
||||||
|
StringController.prototype = new Controller();
|
||||||
|
StringController.prototype.constructor = StringController;
|
2
gui.css
2
gui.css
@ -94,7 +94,7 @@
|
|||||||
border: 0;
|
border: 0;
|
||||||
color: #1ed36f;
|
color: #1ed36f;
|
||||||
margin-right: 2px;
|
margin-right: 2px;
|
||||||
width: 53%;
|
width: 148px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.guidat-controller.boolean {
|
.guidat-controller.boolean {
|
||||||
|
1
gui.min.js
vendored
Normal file
1
gui.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
118
index.html
118
index.html
@ -1,63 +1,36 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<head>
|
<head>
|
||||||
<title>GUI-DAT</title>
|
<title>gui-dat</title>
|
||||||
|
|
||||||
<link rel="icon" type="image/gif" href="demo/assets/favicon.gif">
|
<link rel="icon" type="image/gif" href="demo/assets/favicon.gif">
|
||||||
|
|
||||||
<link href="gui.css" media="screen" rel="stylesheet" type="text/css" />
|
|
||||||
<link href="demo/demo.css" media="screen" rel="stylesheet" type="text/css" />
|
<link href="demo/demo.css" media="screen" rel="stylesheet" type="text/css" />
|
||||||
<script type="text/javascript" src="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js"></script>
|
<script type="text/javascript" src="gui.min.js"></script>
|
||||||
|
<script type="text/javascript" src="demo/improvedNoise.js"></script>
|
||||||
|
|
||||||
<script type="text/javascript" src="controllers/slider.js"></script>
|
|
||||||
<script type="text/javascript" src="controllers/controller.js"></script>
|
|
||||||
<script type="text/javascript" src="controllers/controller.string.js"></script>
|
|
||||||
<script type="text/javascript" src="controllers/controller.number.js"></script>
|
|
||||||
<script type="text/javascript" src="controllers/controller.boolean.js"></script>
|
|
||||||
<script type="text/javascript" src="controllers/controller.function.js"></script>
|
|
||||||
<script type="text/javascript" src="gui.js"></script>
|
|
||||||
<script type="text/javascript" src="demo/demo.js"></script>
|
<script type="text/javascript" src="demo/demo.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var controllableObject =
|
|
||||||
{
|
|
||||||
numberProperty: 20,
|
|
||||||
constrainedNum: 0,
|
|
||||||
notchedNum: 240,
|
|
||||||
pageTitle: "gui-dat",
|
|
||||||
anotherTextProperty: "another string",
|
|
||||||
booleanProperty: false,
|
|
||||||
anotherBooleanProperty: false,
|
|
||||||
functionProperty: function() {
|
|
||||||
alert("I am a function!");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
|
|
||||||
var testDisplay = new DynamicText("gui-dat", 600, 300, 160);
|
|
||||||
|
|
||||||
prettyPrint();
|
var fizzyText = new FizzyText("gui-dat");
|
||||||
|
|
||||||
GUI.start();
|
GUI.start();
|
||||||
|
|
||||||
// Creates a number box
|
// Text field
|
||||||
GUI.add(testDisplay, "minSize", 0, 1);
|
GUI.add(fizzyText, "message");
|
||||||
|
|
||||||
// Creates a number box
|
// Sliders with min and max
|
||||||
GUI.add(testDisplay, "maxSize", 1, 20);
|
GUI.add(fizzyText, "maxSize", 0.5, 7);
|
||||||
|
GUI.add(fizzyText, "growthSpeed", 0.01, 1);
|
||||||
|
GUI.add(fizzyText, "speed", 0.1, 2);
|
||||||
|
|
||||||
// Creates a slider (min, max)
|
// Sliders with min, max and increment.
|
||||||
GUI.add(testDisplay, "growthSpeed", 0.01, 0.5);
|
GUI.add(fizzyText, "noiseStrength", 10, 100, 5);
|
||||||
|
|
||||||
// Creates a text field
|
// Boolean checkbox
|
||||||
GUI.add(testDisplay, "message");
|
GUI.add(fizzyText, "displayOutline");
|
||||||
|
|
||||||
// Creates a checkbox
|
// Fires a function called "explode"
|
||||||
GUI.add(controllableObject, "booleanProperty");
|
GUI.add(fizzyText, "explode")
|
||||||
|
|
||||||
// Creates a button
|
|
||||||
GUI.add(controllableObject, "functionProperty")
|
|
||||||
.setName("Fire a Function");
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -73,61 +46,24 @@
|
|||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1><a href = "http://twitter.com/guidat"><img src = "demo/assets/favicon.gif" border = "0" alt = "GUI-DAT flag" /></a><span id = "helvetica-demo"></span></h1>
|
<div id = "helvetica-demo"></div>
|
||||||
|
<h1><a href = "http://twitter.com/guidat"><img src = "demo/assets/favicon.gif" border = "0" alt = "GUI-DAT flag" /></a></h1>
|
||||||
<div id = "helvetica-test"></div>
|
|
||||||
<p>
|
<p>
|
||||||
<strong>gui-dat</strong> is a lightweight controller library for JavaScript. It allows you to easily manipulate variables and fire functions on the fly.
|
<strong>gui-dat</strong> is a lightweight controller library for JavaScript. It allows you to easily manipulate variables and fire functions on the fly.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>• <a href="#"><strong>Download the minified source</strong></a> <small>[2.3kb]</small><br/>
|
<ul>
|
||||||
• <a href="http://github.com/jonobr1/GUI-DAT">Contribute on GitHub!</a></p>
|
<li><a href=""><strong>Download the minified source</strong></a> <small>[9.8kb]</small></li>
|
||||||
|
<li><a href="http://github.com/jonobr1/GUI-DAT">Contribute on GitHub!</a></p></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
<h2>Basic Usage</h2>
|
<h2>Basic Usage</h2>
|
||||||
|
<pre id="demo-pre" class="prettyprint"><span class="tag"><script</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"text/javascript"</span><span class="pln"> </span><span class="atn">src</span><span class="pun">=</span><span class="atv">"gui.min.js"</span><span class="tag">></script></span><span class="pln"><br></span><span class="tag"><script</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"text/javascript"</span><span class="tag">></span><span class="pln"><br><br>window</span><span class="pun">.</span><span class="pln">onload </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br><br> </span><span class="kwd">var</span><span class="pln"> fizzyText </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ"><a href="demo/demo.js">FizzyText</a></span><span class="pun">(</span><span class="str">"gui-dat"</span><span class="pun">);</span><span class="pln"><br><br> GUI</span><span class="pun">.</span><span class="pln">start</span><span class="pun">();</span><span class="pln"><br> <br> </span><span class="com">// Adds a text field</span><span class="pln"><br> GUI</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">fizzyText</span><span class="pun">,</span><span class="pln"> </span><span class="str">"message"</span><span class="pun">);</span><span class="pln"><br> <br> </span><span class="com">// Adds sliders with min and max</span><span class="pln"><br> GUI</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">fizzyText</span><span class="pun">,</span><span class="pln"> </span><span class="str">"maxSize"</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0.5</span><span class="pun">,</span><span class="pln"> </span><span class="lit">7</span><span class="pun">);</span><span class="pln"><br> GUI</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">fizzyText</span><span class="pun">,</span><span class="pln"> </span><span class="str">"growthSpeed"</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0.01</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">);</span><span class="pln"><br> GUI</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">fizzyText</span><span class="pun">,</span><span class="pln"> </span><span class="str">"speed"</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0.1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">);</span><span class="pln"><br> <br> </span><span class="com">// Adds sliders with min, max and increment.</span><span class="pln"><br> GUI</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">fizzyText</span><span class="pun">,</span><span class="pln"> </span><span class="str">"noiseStrength"</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">,</span><span class="pln"> </span><span class="lit">100</span><span class="pun">,</span><span class="pln"> </span><span class="lit">5</span><span class="pun">);</span><span class="pln"><br> <br> </span><span class="com">// Adds a boolean checkbox</span><span class="pln"><br> GUI</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">fizzyText</span><span class="pun">,</span><span class="pln"> </span><span class="str">"displayOutline"</span><span class="pun">);</span><span class="pln"><br><br> </span><span class="com">// Adds a function button</span><span class="pln"><br> GUI</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">fizzyText</span><span class="pun">,</span><span class="pln"> </span><span class="str">"explode"</span><span class="pun">)</span><span class="pln"><br> <br></span><span class="pun">};</span><span class="pln"><br><br></span><span class="tag"></script></span></pre>
|
||||||
|
|
||||||
<pre id="demo-pre" class="prettyprint">
|
<ul id="desc">
|
||||||
<script type="text/javascript" src="gui.min.js"></script>
|
<li><strong>gui-dat</strong> will infer the type of the property you're trying to add<br/>(based on its initial value) and create the corresponding control.</li>
|
||||||
<script type="text/javascript">
|
<li>The properties must be public, i.e. defined by <code><strong>this</strong>.prop = value</code>.</li>
|
||||||
|
</ul>
|
||||||
var controllableObject =
|
|
||||||
{
|
|
||||||
numberProperty: 20,
|
|
||||||
constrainedNum: 0,
|
|
||||||
notchedNum: 240,
|
|
||||||
textProperty: "a string",
|
|
||||||
anotherTextProperty: "another string",
|
|
||||||
booleanProperty: false,
|
|
||||||
anotherBooleanProperty: false,
|
|
||||||
functionProperty: function() {
|
|
||||||
alert("I am a function!");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.onload = function() {
|
|
||||||
|
|
||||||
GUI.start();
|
|
||||||
|
|
||||||
// Creates a number box
|
|
||||||
GUI.add(controllableObject, "numberProperty");
|
|
||||||
|
|
||||||
// Creates a slider (min, max)
|
|
||||||
GUI.add(controllableObject, "constrainedNum", -100, 100)
|
|
||||||
|
|
||||||
// Creates a slider with notches
|
|
||||||
GUI.add(controllableObject, "notchedNum", 0, 800, 100)
|
|
||||||
|
|
||||||
// Creates a text field
|
|
||||||
GUI.add(controllableObject, "textProperty");
|
|
||||||
|
|
||||||
// Creates a checkbox
|
|
||||||
GUI.add(controllableObject, "booleanProperty");
|
|
||||||
|
|
||||||
// Creates a button
|
|
||||||
GUI.add(controllableObject, "functionProperty").setName("Fire a Function");
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
</script></pre>
|
|
||||||
<footer>
|
<footer>
|
||||||
By <a href="http://georgemichaelbrower.com/">George Michael Brower</a>, <a href="http://jonobr1.com/">Jono Brandel</a>, and <a href="http://github.com/jonobr1/GUI-DAT">you</a>.
|
By <a href="http://georgemichaelbrower.com/">George Michael Brower</a>, <a href="http://jonobr1.com/">Jono Brandel</a>, and <a href="http://github.com/jonobr1/GUI-DAT">you</a>.
|
||||||
</footer>
|
</footer>
|
||||||
|
Loading…
Reference in New Issue
Block a user