Last active
January 3, 2018 14:21
-
-
Save mr5z/ba92477bbd20a3d9152b4100ce30a951 to your computer and use it in GitHub Desktop.
not really my code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!function(t,e){var i=document.createElement("canvas");i.id="world",i.style.backgroundColor="transparent",i.style.zIndex="10000",i.style.width=window.innerWidth+"px",i.style.height=window.innerHeight+"px",i.style.position="fixed",i.style.left="0",i.style.top="0",i.style.pointerEvents="none",document.body.appendChild(i);var h=30,s=300,o=3,r=10,n=4e3,a=.5,c=function(t,e){var i,h,s,o,r=null;return function(){if(null!==r)return o=r,r=null,h*o+t;do{i=2*Math.random()-1,h=2*Math.random()-1,s=i*i+h*h}while(s>=1);return r=e*Math.sqrt(-2*Math.log(s)/s),i*r+t}};pointCopy=function(t,e){return e.x=t.x,e.y=t.y,e.z=t.z,e},Trail=function(t,e,i){this.pos={x:0,y:0,z:0},this.start={x:0,y:0,z:0},this.goal={x:0,y:0,z:0},this.anchor_1={x:0,y:0,z:0},this.anchor_2={x:0,y:0,z:0},this.start_time=0,this.take_time=1,this.vertexes=[],this.anchors_1=[],this.anchors_2=[],this.color_f=i,pointCopy(t,this.pos),pointCopy(t,this.start),pointCopy(t,this.goal),this.setNextGoal(e)},Trail.prototype.setNextGoal=function(t,e){pointCopy(this.goal,this.start),this.anchor_1.x=this.start.x+(this.start.x-this.anchor_2.x)*a,this.anchor_1.y=this.start.y+(this.start.y-this.anchor_2.y)*a,this.anchor_1.z=this.start.z+(this.start.z-this.anchor_2.z)*a,e?(this.anchor_2.x=(this.anchor_1.x+e.x)/2+y(),this.anchor_2.y=(this.anchor_1.y+e.y)/2+y(),this.anchor_2.z=(this.anchor_1.z+e.z)/2+y(),this.goal.x=e.x,this.goal.y=e.y,this.goal.z=e.z):(this.anchor_2.x=this.anchor_1.x+y(),this.anchor_2.y=this.anchor_1.y+y(),this.anchor_2.z=this.anchor_1.z+y(),this.goal.x=this.anchor_2.x+y(),this.goal.y=this.anchor_2.y+y(),this.goal.z=this.anchor_2.z+y()),this.start_time=t,this.take_time=200+200*Math.random(),this.vertexes.push(pointCopy(this.start,{x:0,y:0,z:0})),this.anchors_1.push(pointCopy(this.anchor_1,{x:0,y:0,z:0})),this.anchors_2.push(pointCopy(this.anchor_2,{x:0,y:0,z:0})),this.vertexes.length>r&&(this.vertexes.splice(0,this.vertexes.length-r),this.anchors_1.splice(0,this.anchors_1.length-r),this.anchors_2.splice(0,this.anchors_2.length-r))},Trail.prototype.update=function(t,e){bezier3(t-this.start_time,this.start,this.anchor_1,this.anchor_2,this.goal,this.take_time,this.pos),t-this.start_time>this.take_time&&(this.setNextGoal(this.start_time+this.take_time,e),this.update(t,e))},Trail.prototype.draw=function(t,e,i){var h,s,o,a,c,l,y={x:0,y:0,z:0},p={x:0,y:0};t.beginPath(),perspective(this.vertexes[0],e,p)&&t.moveTo(p.x,p.y);p.x;for(c=(i-this.start_time)/this.take_time,h=1;h<this.vertexes.length;h++)for(a=.01,o=0;o<1;o+=a)bezier3(o,this.vertexes[h-1],this.anchors_1[h-1],this.anchors_2[h-1],this.vertexes[h],1,y),perspective(y,e,p)&&(s=y.z-e.z,l=1-(this.vertexes.length-h+1-o+c)/r,this.color_f(t,l,s),t.lineTo(p.x,p.y),t.stroke(),t.beginPath(),t.moveTo(p.x,p.y),a=s/n+.01);for(a=.01,o=0;o<c;o+=a)bezier3(o,this.start,this.anchor_1,this.anchor_2,this.goal,1,y),perspective(y,e,p)&&(s=y.z-e.z,l=1-(1-o+c)/r,this.color_f(t,l,s),t.lineTo(p.x,p.y),t.stroke(),t.beginPath(),t.moveTo(p.x,p.y),a=s/n+.01);perspective(this.pos,e,p)&&(s=this.pos.z-e.z,l=1-1/r,this.color_f(t,l,s),t.lineTo(p.x,p.y),t.stroke())},bezier3=function(t,e,i,h,s,o,r){t/=o,r.x=e.x*(1-t)*(1-t)*(1-t)+3*i.x*t*(1-t)*(1-t)+3*h.x*t*t*(1-t)+s.x*t*t*t,r.y=e.y*(1-t)*(1-t)*(1-t)+3*i.y*t*(1-t)*(1-t)+3*h.y*t*t*(1-t)+s.y*t*t*t,r.z=e.z*(1-t)*(1-t)*(1-t)+3*i.z*t*(1-t)*(1-t)+3*h.z*t*t*(1-t)+s.z*t*t*t},perspective=function(t,e,i){var h=t.x-e.x,o=t.y-e.y,r=t.z-e.z;return r>0&&(i.x=s*h/r,i.y=s*o/r,!0)},updateScene=function(t){var e,i=(u=(new Date).getTime())-z;for(_[0].update(u),e=1;e<_.length;e++)_[e].update(u,_[e-1].pos);d.x+=5e-4*(_[0].pos.x-d.x)*i,d.y+=5e-4*(_[0].pos.y-d.y)*i,d.z+=5e-4*(_[0].pos.z-d.z-100)*i,z=u},drawScene=function(t){var e;for(t.clearRect(-p.width/2,-p.height/2,p.width,p.height),e=0;e<_.length;e++)_[e].draw(t,d,u)};var l,y=c(0,20),p=t.getElementById("world"),x=p.getContext("2d"),_=[],u=(new Date).getTime(),z=u,d={x:0,y:0,z:-200};for(l=0;l<o;l++)_.push(new Trail({x:y(),y:y(),z:y()},u,function(t,e){return"#FFFFFF"}));for(l=0;l<o;l++)switch(l%3){case 0:_[l].color_f=function(t,e,i){var h=i<10?0:e*s/i;h=(h>1?1:h)*(i<30?(i-10)/20:1),t.strokeStyle="rgba(255,"+Math.floor(255*e)+",0,"+h+")",t.lineWidth=s/i,t.lineCap=h>.8?"round":"butt"};break;case 1:_[l].color_f=function(t,e,i){var h=i<10?0:e*s/i;h=(h>1?1:h)*(i<30?(i-10)/20:1),t.strokeStyle="rgba(0, 255,"+Math.floor(255*e)+","+h+")",t.lineWidth=s/i,t.lineCap=h>.8?"round":"butt"};break;default:_[l].color_f=function(t,e,i){var h=i<10?0:e*s/i;h=(h>1?1:h)*(i<30?(i-10)/20:1),t.strokeStyle="rgba("+Math.floor(255*e)+",0,255,"+h+")",t.lineWidth=s/i,t.lineCap=h>.8?"round":"butt"}}p.width=e.innerWidth,p.height=e.innerHeight,x.translate(p.width/2,p.height/2),setInterval(function(){updateScene(),drawScene(x)},1e3/h)}(document,window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Copy paste this to your browser's console