cav={front:0,back:1,double:2,svgns:"http://www.w3.org/2000/svg"};cav.array=typeof float32array==="function"?float32array:array;cav.utils={isnumber:function(a){return!isnan(parsefloat(a))&&isfinite(a)}}; (function(){for(var a=0,b=["ms","moz","webkit","o"],c=0;cb&&(a[0]=b);a[1]>b&&(a[1]=b);a[2]>b&&(a[2]=b);return this},clamp:function(a,b,c){this.min(a,b);this.max(a,c);return this},limit:function(a,b,c){var d=this.length(a);b!==null&&dc&&this.setlength(a,c);return this},dot:function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},normalise:function(a){return this.dividescalar(a,this.length(a))},negate:function(a){return this.multiplyscalar(a, -1)},distancesquared:function(a,b){var c=a[0]-b[0],d=a[1]-b[1],e=a[2]-b[2];return c*c+d*d+e*e},distance:function(a,b){return math.sqrt(this.distancesquared(a,b))},lengthsquared:function(a){return a[0]*a[0]+a[1]*a[1]+a[2]*a[2]},length:function(a){return math.sqrt(this.lengthsquared(a))},setlength:function(a,b){var c=this.length(a);c!==0&&b!==c&&this.multiplyscalar(a,b/c);return this}}; cav.vector4={create:function(a,b,c){var d=new cav.array(4);this.set(d,a,b,c);return d},set:function(a,b,c,d,e){a[0]=b||0;a[1]=c||0;a[2]=d||0;a[3]=e||0;return this},setx:function(a,b){a[0]=b||0;return this},sety:function(a,b){a[1]=b||0;return this},setz:function(a,b){a[2]=b||0;return this},setw:function(a,b){a[3]=b||0;return this},add:function(a,b){a[0]+=b[0];a[1]+=b[1];a[2]+=b[2];a[3]+=b[3];return this},multiplyvectors:function(a,b,c){a[0]=b[0]*c[0];a[1]=b[1]*c[1];a[2]=b[2]*c[2];a[3]=b[3]*c[3];return this}, multiplyscalar:function(a,b){a[0]*=b;a[1]*=b;a[2]*=b;a[3]*=b;return this},min:function(a,b){a[0]b&&(a[0]=b);a[1]>b&&(a[1]=b);a[2]>b&&(a[2]=b);a[3]>b&&(a[3]=b);return this},clamp:function(a,b,c){this.min(a,b);this.max(a,c);return this}};cav.color=function(a,b){this.rgba=cav.vector4.create();this.hex=a||"#000000";this.opacity=cav.utils.isnumber(b)?b:1;this.set(this.hex,this.opacity)}; cav.color.prototype={set:function(a,b){var a=a.replace("#",""),c=a.length/3;this.rgba[0]=parseint(a.substring(c*0,c*1),16)/255;this.rgba[1]=parseint(a.substring(c*1,c*2),16)/255;this.rgba[2]=parseint(a.substring(c*2,c*3),16)/255;this.rgba[3]=cav.utils.isnumber(b)?b:this.rgba[3];return this},hexify:function(a){a=math.ceil(a*255).tostring(16);a.length===1&&(a="0"+a);return a},format:function(){var a=this.hexify(this.rgba[0]),b=this.hexify(this.rgba[1]),c=this.hexify(this.rgba[2]);return this.hex="#"+ a+b+c}};cav.object=function(){this.position=cav.vector3.create()};cav.object.prototype={setposition:function(a,b,c){cav.vector3.set(this.position,a,b,c);return this}};cav.light=function(a,b){cav.object.call(this);this.ambient=new cav.color(a||"#ffffff");this.diffuse=new cav.color(b||"#ffffff");this.ray=cav.vector3.create()};cav.light.prototype=object.create(cav.object.prototype);cav.vertex=function(a,b,c){this.position=cav.vector3.create(a,b,c)}; cav.vertex.prototype={setposition:function(a,b,c){cav.vector3.set(this.position,a,b,c);return this}}; cav.triangle=function(a,b,c){this.a=a||new cav.vertex;this.b=b||new cav.vertex;this.c=c||new cav.vertex;this.vertices=[this.a,this.b,this.c];this.u=cav.vector3.create();this.v=cav.vector3.create();this.centroid=cav.vector3.create();this.normal=cav.vector3.create();this.color=new cav.color;this.polygon=document.createelementns(cav.svgns,"polygon");this.polygon.setattributens(null,"stroke-linejoin","round");this.polygon.setattributens(null,"stroke-miterlimit","1");this.polygon.setattributens(null,"stroke-width", "1");this.computecentroid();this.computenormal()}; cav.triangle.prototype={computecentroid:function(){this.centroid[0]=this.a.position[0]+this.b.position[0]+this.c.position[0];this.centroid[1]=this.a.position[1]+this.b.position[1]+this.c.position[1];this.centroid[2]=this.a.position[2]+this.b.position[2]+this.c.position[2];cav.vector3.dividescalar(this.centroid,3);return this},computenormal:function(){cav.vector3.subtractvectors(this.u,this.b.position,this.a.position);cav.vector3.subtractvectors(this.v,this.c.position,this.a.position);cav.vector3.crossvectors(this.normal, this.u,this.v);cav.vector3.normalise(this.normal);return this}};cav.geometry=function(){this.vertices=[];this.triangles=[];this.dirty=false};cav.geometry.prototype={update:function(){if(this.dirty){var a,b;for(a=this.triangles.length-1;a>=0;a--)b=this.triangles[a],b.computecentroid(),b.computenormal();this.dirty=false}return this}}; cav.plane=function(a,b,c,d){cav.geometry.call(this);this.width=a||100;this.height=b||100;this.segments=c||4;this.slices=d||4;this.segmentwidth=this.width/this.segments;this.sliceheight=this.height/this.slices;var e,f,g,c=[];e=this.width*-0.5;f=this.height*0.5;for(a=0;a<=this.segments;a++){c.push([]);for(b=0;b<=this.slices;b++)d=new cav.vertex(e+a*this.segmentwidth,f-b*this.sliceheight),c[a].push(d),this.vertices.push(d)}for(a=0;a=0;c--){d=this.geometry.triangles[c];cav.vector4.set(d.color.rgba);for(e=a.length-1;e>=0;e--)f=a[e],cav.vector3.subtractvectors(f.ray,f.position,d.centroid),cav.vector3.normalise(f.ray),g=cav.vector3.dot(d.normal,f.ray),this.side===cav.front?g=math.max(g,0):this.side===cav.back?g=math.abs(math.min(g,0)):this.side===cav.double&&(g=math.max(math.abs(g),0)),cav.vector4.multiplyvectors(this.material.slave.rgba, this.material.ambient.rgba,f.ambient.rgba),cav.vector4.add(d.color.rgba,this.material.slave.rgba),cav.vector4.multiplyvectors(this.material.slave.rgba,this.material.diffuse.rgba,f.diffuse.rgba),cav.vector4.multiplyscalar(this.material.slave.rgba,g),cav.vector4.add(d.color.rgba,this.material.slave.rgba);cav.vector4.clamp(d.color.rgba,0,1)}return this};cav.scene=function(){this.meshes=[];this.lights=[]}; cav.scene.prototype={add:function(a){a instanceof cav.mesh&&!~this.meshes.indexof(a)?this.meshes.push(a):a instanceof cav.light&&!~this.lights.indexof(a)&&this.lights.push(a);return this},remove:function(a){a instanceof cav.mesh&&~this.meshes.indexof(a)?this.meshes.splice(this.meshes.indexof(a),1):a instanceof cav.light&&~this.lights.indexof(a)&&this.lights.splice(this.lights.indexof(a),1);return this}};cav.renderer=function(){this.halfheight=this.halfwidth=this.height=this.width=0}; cav.renderer.prototype={setsize:function(a,b){if(!(this.width===a&&this.height===b))return this.width=a,this.height=b,this.halfwidth=this.width*0.5,this.halfheight=this.height*0.5,this},clear:function(){return this},render:function(){return this}};cav.canvasrenderer=function(){cav.renderer.call(this);this.element=document.createelement("canvas");this.element.style.display="block";this.context=this.element.getcontext("2d");this.setsize(this.element.width,this.element.height)}; cav.canvasrenderer.prototype=object.create(cav.renderer.prototype);cav.canvasrenderer.prototype.setsize=function(a,b){cav.renderer.prototype.setsize.call(this,a,b);this.element.width=a;this.element.height=b;this.context.settransform(1,0,0,-1,this.halfwidth,this.halfheight);return this};cav.canvasrenderer.prototype.clear=function(){cav.renderer.prototype.clear.call(this);this.context.clearrect(-this.halfwidth,-this.halfheight,this.width,this.height);return this}; cav.canvasrenderer.prototype.render=function(a){cav.renderer.prototype.render.call(this,a);var b,c,d,e,f;this.clear();this.context.linejoin="round";this.context.linewidth=1;for(b=a.meshes.length-1;b>=0;b--)if(c=a.meshes[b],c.visible){c.update(a.lights,true);for(d=c.geometry.triangles.length-1;d>=0;d--)e=c.geometry.triangles[d],f=e.color.format(),this.context.beginpath(),this.context.moveto(e.a.position[0],e.a.position[1]),this.context.lineto(e.b.position[0],e.b.position[1]),this.context.lineto(e.c.position[0], e.c.position[1]),this.context.closepath(),this.context.strokestyle=f,this.context.fillstyle=f,this.context.stroke(),this.context.fill()}return this}; function victor(container, anitout){ if (!!document.createelement("canvas").getcontext) { var t = { width: 1.5, height: 1.5, depth: 50, segments: 12, slices: 6, xrange: 0.8, yrange: 0.1, zrange: 1, ambient: "#525252", diffuse: "#ffffff", speed: 0.0002 }; var g = { count: 2, xyscalar: 1, zoffset: 100, ambient: "#002c4a", diffuse: "#005584", speed: 0.001, gravity: 1200, dampening: 0.95, minlimit: 10, maxlimit: null, mindistance: 20, maxdistance: 400, autopilot: false, draw: false, bounds: cav.vector3.create(), step: cav.vector3.create(math.randominrange(0.2, 1), math.randominrange(0.2, 1), math.randominrange(0.2, 1)) }; var m = "canvas"; var e = "svg"; var x = { renderer: m }; var i, n = date.now(); var l = cav.vector3.create(); var k = cav.vector3.create(); var z = document.getelementbyid(container || "container"); var w = document.getelementbyid(anitout || "anitout"); var d, i, h, q, y; var g; var r; function c() { f(); p(); s(); b(); v(); k(z.offsetwidth, z.offsetheight); o() } function f() { g = new cav.canvasrenderer(); h(x.renderer) } function h(n) { if (d) { w.removechild(d.element) } switch (n) { case m: d = g; break } d.setsize(z.offsetwidth, z.offsetheight); w.appendchild(d.element) } function p() { i = new cav.scene() } function s() { i.remove(h); d.clear(); q = new cav.plane(t.width * d.width, t.height * d.height, t.segments, t.slices); y = new cav.material(t.ambient, t.diffuse); h = new cav.mesh(q, y); i.add(h); var n, o; for (n = q.vertices.length - 1; n >= 0; n--) { o = q.vertices[n]; o.anchor = cav.vector3.clone(o.position); o.step = cav.vector3.create(math.randominrange(0.2, 1), math.randominrange(0.2, 1), math.randominrange(0.2, 1)); o.time = math.randominrange(0, math.pim2) } } function b() { var o, n; for (o = i.lights.length - 1; o >= 0; o--) { n = i.lights[o]; i.remove(n) } d.clear(); for (o = 0; o < g.count; o++) { n = new cav.light(g.ambient, g.diffuse); n.ambienthex = n.ambient.format(); n.diffusehex = n.diffuse.format(); i.add(n); n.mass = math.randominrange(0.5, 1); n.velocity = cav.vector3.create(); n.acceleration = cav.vector3.create(); n.force = cav.vector3.create() } } function k(o, n) { d.setsize(o, n); cav.vector3.set(l, d.halfwidth, d.halfheight); s() } function o() { i = date.now() - n; u(); m(); requestanimationframe(o) } function u() { var q, p, o, r, t, v, u, s = t.depth / 2; cav.vector3.copy(g.bounds, l); cav.vector3.multiplyscalar(g.bounds, g.xyscalar); cav.vector3.setz(k, g.zoffset); for (r = i.lights.length - 1; r >= 0; r--) { t = i.lights[r]; cav.vector3.setz(t.position, g.zoffset); var n = math.clamp(cav.vector3.distancesquared(t.position, k), g.mindistance, g.maxdistance); var w = g.gravity * t.mass / n; cav.vector3.subtractvectors(t.force, k, t.position); cav.vector3.normalise(t.force); cav.vector3.multiplyscalar(t.force, w); cav.vector3.set(t.acceleration); cav.vector3.add(t.acceleration, t.force); cav.vector3.add(t.velocity, t.acceleration); cav.vector3.multiplyscalar(t.velocity, g.dampening); cav.vector3.limit(t.velocity, g.minlimit, g.maxlimit); cav.vector3.add(t.position, t.velocity) } for (v = q.vertices.length - 1; v >= 0; v--) { u = q.vertices[v]; q = math.sin(u.time + u.step[0] * i * t.speed); p = math.cos(u.time + u.step[1] * i * t.speed); o = math.sin(u.time + u.step[2] * i * t.speed); cav.vector3.set(u.position, t.xrange * q.segmentwidth * q, t.yrange * q.sliceheight * p, t.zrange * s * o - s); cav.vector3.add(u.position, u.anchor) } q.dirty = true } function m() { d.render(i) } function j(o) { var q, n, s = o; var p = function(t) { for (q = 0, l = i.lights.length; q < l; q++) { n = i.lights[q]; n.ambient.set(t); n.ambienthex = n.ambient.format() } }; var r = function(t) { for (q = 0, l = i.lights.length; q < l; q++) { n = i.lights[q]; n.diffuse.set(t); n.diffusehex = n.diffuse.format() } }; return { set: function() { p(s[0]); r(s[1]) } } } function v() { window.addeventlistener("resize", j) } function a(n) { cav.vector3.set(k, n.x, d.height - n.y); cav.vector3.subtract(k, l) } function j(n) { k(z.offsetwidth, z.offsetheight); m() } c(); } return j; }