Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8"/>
- <title>LapisSea</title>
- <link rel="shortcut icon" href="favicon.ico">
- <link href='https://fonts.googleapis.com/css?family=Comfortaa' rel='stylesheet' type='text/css'>
- <style type="text/css">
- body{
- font-family: Comfortaa;
- background-color: #555;
- }
- msg{
- display: block;
- font-size: 50px;
- position: fixed;
- top: 30px;
- left: 30px;
- }
- .canv{
- background-color: transparent;
- position: fixed;
- top: 0;
- left: 0;
- z-index: -1;
- }
- body,html,.canv{
- width: 100%;
- height: 100%;
- padding: 0;
- margin: 0;
- }
- .invi{
- display: none;
- }
- .canv,msg{
- user-select: none;
- -moz-user-select: none;
- -khtml-user-select: none;
- -webkit-user-select: none;
- -o-user-select: none;
- }
- a{
- color: inherit;
- border-bottom: 1px solid transparent;
- transition: text-shadow 0.3s,color 0.3s;
- text-decoration: none;
- text-shadow: 1px 1px 1px transparent;
- }
- .Sign{
- position: fixed;
- top: 65%;
- border-top: 6px solid rgb(10,10,10);
- background-color: rgba(120,120,120,0.1);
- max-width: 21.428%;
- opacity: 0.01;
- }
- .Title{
- padding: 4px 15px;
- font-size: 18px;
- font-weight: bold;
- }
- .txt{
- padding: 10px;
- font-size: 16px;
- }
- </style>
- <style type="text/css" id="jsStyle"></style>
- </head>
- <body onload="lod()" onresize="res()" onclick="clck(window.event)">
- <canvas class="canv" id="bkg"></canvas>
- <canvas class="canv" id="tre"></canvas>
- <msg></msg>
- <!-- <img class="invi" id="gitImg" src="images/git.svg"> -->
- <img class="invi" id="glintImg" src="images/Glint.png">
- <img class="invi" id="ambientParticle" src="images/explosion_stages.png">
- <div class="Sign" style="left: 7.142%">
- <div class="Title">Author:</div>
- <div class="txt">
- · Me, LapisSea
- </div>
- </div>
- <div class="Sign" style="left: 28.571%">
- <div class="Title">Contact me by:</div>
- <div class="txt">
- <a target="_blank" href="http://t.me/LapisSea">Telegram</a><br>
- <a target="_blank" href="https://discord.gg/rHmFGMz">Discord</a><br>
- <a target="_blank" href="mailto:officiallapisseamail@gmail.com">eMail</a><br>
- </div>
- </div>
- <div class="Sign" style="left: 50%">
- <div class="Title">I am a:</div>
- <div class="txt">
- · Computer science enthusiast<br>
- · Web, game developer<br>
- · Human <span style="font-size: 3px">(yes I know it's crazy)</span>
- </div>
- </div>
- <script type="text/javascript" id="util">
- devMode=false;
- "use strict";
- function time(){return new Date().getTime();}
- function syso(){
- if(arguments.length==1)console.log(arguments[0]);
- else if(arguments.length==2)console.log(arguments[0],arguments[1]);
- else console.log(arguments);
- }
- function fillQuad(ctx,p1x,p1y,p2x,p2y,p3x,p3y,p4x,p4y){
- ctx.beginPath();
- ctx.moveTo(p1x,p1y);
- ctx.lineTo(p2x,p2y);
- ctx.lineTo(p3x,p3y);
- ctx.lineTo(p4x,p4y);
- ctx.fill();
- }
- </script>
- <script src="https://cdn.rawgit.com/mourner/suncalc/b08d1f6f/suncalc.js"></script>
- <script src="common/CommonUtil.js?v=1"></script>
- <script src="common/GetURLContent.js?v=1"></script>
- <script src="common/CookieGetterSetter.js?v=1"></script>
- <script src="common/ClearAreaMaker.js?v=1"></script>
- <script src="common/PerlinNoise.js?v=1"></script>
- <script src="common/CubicBezier.js?v=1"></script>
- <script type="text/javascript" id="sunScript">
- geoData={latitude:0,longitude:0,ip:0,isNull:true};
- function initGeo(json){
- geoData={
- latitude:json.latitude,
- longitude:json.longitude,
- ip:json.ip
- };
- }
- debugSunVal=-1;
- function debugSun(brightness){
- debugSunVal=brightness;
- updateSun();
- debugSunVal=-1;
- }
- sunBrightness=NaN;
- function updateSun(){
- var prev=sunBrightness;
- calcSunBrightness();
- bkgCol=Math.round(sunBrightness*200+29);
- terrainCol=Math.round(sunBrightness*70+10);
- trunkCol=Math.round((1-sunBrightness*sunBrightness)*50+80);
- document.body.style.color=bkgCol<126?"white":"black";
- document.body.style.backgroundColor="rgb("+bkgCol+","+bkgCol+","+bkgCol+")";
- if(sunBrightness==prev)return;
- var c=document.body.style.color,a=bkgCol<126?"#AAA":"#555";
- jsStyle.innerHTML=`
- .Sign{opacity: 1; border-top-color:rgb(`+terrainCol+","+terrainCol+","+terrainCol+`);}
- a:hover{text-shadow: 0px 0.5px 0px `+c+`, -0.5px 0px 0px `+c+`, 0px -0.5px 0px `+c+`, 0.5px 0px 0px `+c+`;}
- a:active{color:`+a+`;text-shadow: 0px 0.5px 0px `+a+`, -0.5px 0px 0px `+a+`, 0px -0.5px 0px `+a+`, 0.5px 0px 0px `+a+`;}
- `;
- if(typeof res!="undefined"){
- res();
- if(!local)ambientParticle.src=filterImage(function(pixels) {
- var d = pixels.data;
- for (var i=0; i<d.length; i+=4){
- d[i]=d[i+1]=d[i+2]=trunkCol;
- }
- return pixels;
- },ambientParticle);
- }
- }
- function calcSunBrightness(){
- if(debugSunVal>=0){
- sunBrightness=debugSunVal;
- return;
- }
- var date=new Date();
- var tim=date.getTime();
- sun=SunCalc.getTimes(date, geoData.latitude, geoData.longitude);
- genSun();
- var start=sun.nightEnd.getTime();
- var end=sun.dawn.getTime();
- if(start>tim){
- sunBrightness=0;
- return;
- }
- if(start<tim&&tim<end){
- var diff=end-start;
- sunBrightness=(tim-start)/diff;
- return;
- }
- start=sun.dusk.getTime();
- end=sun.night.getTime();
- if(start<tim&&tim<end){
- var diff=end-start;
- sunBrightness=1-(tim-start)/diff;
- return;
- }
- if(end<tim)sunBrightness=0;
- else sunBrightness=1;
- }
- fetchingGeo=false;
- function genSun(){
- var geo=getCookie("geo");
- if(typeof geo=="undefined"||geo==""){
- if(typeof fetchingGeoScript=="undefined")fetchGeo();
- }else if(geoData.isNull){
- initGeo(geo);
- }
- }
- function fetchGeoReceve(json){
- json={
- latitude:json.geoplugin_latitude,
- longitude:json.geoplugin_longitude,
- ip:json.geoplugin_request
- };
- initGeo(json);
- setCookie("geo",json,1);
- genSun();
- syso("Geo data fetched!");
- fetchingGeoScript.parentNode.removeChild(fetchingGeoScript);
- delete fetchingGeoScript;
- updateSun();
- }
- function fetchGeo(){
- syso("Fetching geo data...");
- fetchingGeoScript=document.createElement("script");
- fetchingGeoScript.src="http://www.geoplugin.net/json.gp?jsoncallback=fetchGeoReceve";
- document.body.appendChild(fetchingGeoScript);
- }
- </script>
- <!-- <script type="text/javascript" src="http://www.geoplugin.net/json.gp?jsoncallback=initGeo"></script> -->
- <script type="text/javascript" id="openTyping">
- helloText=["Hello, ","Welcome..."];
- wops="abcdefghijklmnopqrstuvwxyz";
- mistake=false;
- typed="";
- function w(){
- return helloText[0];
- }
- function type(){
- if(devMode){
- msg.innerHTML=helloText.join("<br>");
- startTim=1;
- return;
- }
- setTimeout(function(){
- if(w().length==0){
- helloText.shift();
- if(helloText.length>0){
- typed+="<br>";
- msg.innerHTML=typed;
- type();
- }else{
- msg.innerHTML=typed;
- type=helloText=wops=typed=undefined;
- startTim=time();
- }
- return;
- }
- if(mistake){
- mistake=false;
- typed=typed.substring(0,typed.length-1);
- }
- else if(Math.random()>0.7){
- mistake=true;
- var correctId=wops.indexOf(w().charAt(0).toLowerCase());
- if(correctId==-1)mistake=false;
- else{
- var misId;
- do{misId=Math.round(Math.random()*wops.length);}while(correctId==misId);
- typed+=wops.charAt(misId);
- }
- }
- if(!mistake){
- typed+=w().charAt(0);
- helloText[0]=w().substring(1);
- }
- msg.innerHTML=typed;
- type();
- },Math.round(20+(mistake?0:Math.random()*50)));
- }
- </script>
- <script type="text/javascript" id="tree">
- maxPar=0;
- function Vec2(x=0,y=0){
- this.x=x;
- this.y=y;
- };
- sqrtOf2=Math.sqrt(2);
- function Segment(parent,pos,length,width){
- this.parent=parent;
- this.pos=pos;
- this.length=length;
- this.width=width;
- this.topWidth=width;
- this.child=[];
- this.sp=0;
- this.shock=0;
- this.parentCount=this.parent.parentCount+1;
- this.anglePref=0;
- this.org=function(){
- var mul=(1/(this.width*this.width))*50;
- if(mul>1.5)mul=Math.sqrt(mul);
- this.origigi=(1-Math.random()*2)*mul+this.anglePref;
- this.origigi=(this.origigi+this.parent.origigi*2)/3;
- this.shock=1.5;
- }
- this.org();
- this.angle=Math.PI+this.origigi;
- this.rand=Math.random();
- this.topL=new Vec2();
- this.topR=new Vec2();
- if(this.width>2){
- this.childPos=[];
- for(var i=0,j=1+Math.round(Math.random()*2);i<j;i++){
- var sg=new Segment(this,new Vec2(0,0),this.length*(0.67+Math.random()*0.2),width*(0.4+Math.random()*0.5));
- maxPar=Math.max(maxPar,sg.parentCount);
- this.child.push(sg);
- }
- if(this.width>4){
- while(Math.random()>0.6){
- var sg=new Segment(this,new Vec2(0,0),this.length*(0.2+Math.random()*0.2),1+Math.random()+0.9);
- maxPar=Math.max(maxPar,sg.parentCount);
- this.child.push(sg);
- }
- }
- var chl=this.child.length;
- var total=0;
- for(var i=0;i<chl;i++)total+=this.child[i].width;
- this.topWidth=Math.min(this.topWidth,total);
- var xD=0;
- for(var i=0;i<chl;i++){
- var ch=this.child[i];
- ch.anglePref=chl<2?0:((i-(chl-1)/2)/(chl-1))/ch.width*2;
- ch.org();
- ch.angle=Math.PI+ch.origigi;
- xD+=ch.width;
- var start=ch.width/2,end=this.topWidth-ch.width/2;
- if(i==0)this.childPos[i]=start;
- else if(i==chl-1)this.childPos[i]=end;
- else{
- var percent=(xD-ch.width/2)/total;
- this.childPos[i]=Math.max(start, Math.min(this.topWidth*percent, end));
- }
- this.childPos[i]-=this.topWidth/2;
- }
- }
- this.update=function(){
- if(sec%10==0&&Math.random()>0.99){
- this.org();
- if(Math.random()>0.98)this.drop();
- }
- var lower=100+this.width*10;
- lower+=(1-sunBrightness)*100;
- this.angle+=nois.noise(this.rand,tim/20000)/lower;
- this.angle=(this.angle*99+Math.PI+this.origigi)/100;
- //this.angle=Math.PI+this.origigi*10;
- this.s90=Math.sin(this.angle+Math.PI/2);
- this.cs90=Math.cos(this.angle+Math.PI/2);
- var s=Math.sin(this.angle),cs=Math.cos(this.angle);
- this.endX=this.pos.x+s*this.actualLeng;
- this.endY=this.pos.y+cs*this.actualLeng;
- this.actualLeng=Math.min(1,(grow-1)/this.parentCount);
- if(this.actualLeng<1)this.actualLeng=UnitBezier.calcCubicBezier(.73,.01,.5,.99,this.actualLeng);
- if(this.width<2)this.shock*=0.99;
- if(this.child.length>0){
- for(var i=0;i<this.child.length;i++){
- var ch=this.child[i];
- // ch.pos.x=this.endX;
- // ch.pos.y=this.endY;
- ch.pos.x=this.endX+this. s90*this.childPos[i];
- ch.pos.y=this.endY+this.cs90*this.childPos[i];
- // var difAng=Math.abs(this.angle-ch.angle);
- // ch.pos.x-=ch.width*cs*Math.sin(difAng)/2;
- // ch.pos.y-=ch.width*s*Math.cos(difAng)/2;
- ch.update();
- }
- }
- }
- this.draw=function(ctx){
- if(this.actualLeng<=0)return;
- var cubeS=0;
- if(this.width<2){
- cubeS=Math.max(this.actualLeng-0.8,0)*5;
- }
- this.actualLeng*=this.length;
- ctx.addRad(this.endX,this.endY,20);
- // o1 o4
- // o2 o3
- ctx.fillStyle="rgb("+trunkCol+","+trunkCol+","+trunkCol+")";
- this.topL.x=this.endX+this. s90*this.topWidth/2;
- this.topL.y=this.endY+this.cs90*this.topWidth/2;
- this.topR.x=this.endX-this. s90*this.topWidth/2;
- this.topR.y=this.endY-this.cs90*this.topWidth/2;
- var
- blx=this.pos.x+this.s90*this.width/2,bly=this.pos.y+this.cs90*this.width/2,
- brx=this.pos.x-this.s90*this.width/2,bry=this.pos.y-this.cs90*this.width/2;
- fillQuad(ctx,
- this.topL.x,this.topL.y,
- blx,bly,
- brx,bry,
- this.topR.x,this.topR.y
- );
- if(this.parentCount>1){
- //ctx.fillStyle="rgba("+trunkCol+","+trunkCol+","+trunkCol+",0.2)";
- fillQuad(ctx,
- blx,bly-1,
- this.parent.topL.x,this.parent.topL.y+1,
- this.parent.topR.x,this.parent.topR.y+1,
- brx,bry-1
- );
- }
- // ctx.beginPath();
- // ctx.moveTo(this.pos.x,this.pos.y);
- // ctx.lineTo(endX,endY);
- // ctx.stroke();
- if(cubeS>0&&this.shock>-1){
- var lol=nois.noise(this.rand,tim/2000);
- cubeS*=(0.5+(lol/2+1)*0.5)*Math.max(0,1+this.shock);
- cubeS*=12;
- var r=lol<0?-lol:0,b=Math.max(0,lol);
- ctx.fillStyle="rgba("+Math.round(r*120+50)+",50,"+Math.round(b*120+50)+",0.4)";
- ctx.save();
- ctx.translate(this.endX,this.endY);
- ctx.rotate(lol/3+Math.sin(this.shock*5)/2);
- ctx.fillRect(-cubeS/2,-cubeS/2, cubeS,cubeS);
- var glow=((this.shock-0.2)/0.8)/2;
- glow*=1-sunBrightness;
- if(glow>0){
- glow-=(nois.noise(this.rand,tim/100)/2+0.5)*0.03;
- }
- if(glow>0){
- glintData.push(this.endX);
- glintData.push(this.endY);
- glintData.push(glow);
- glintData.push(r);
- }else ctx.addRad(this.endX,this.endY,cubeS*sqrtOf2);
- ctx.restore();
- }
- if(this.child.length>0){
- for(var i=0;i<this.child.length;i++){
- this.child[i].draw(ctx);
- }
- }
- }
- this.getClicks=function(arr){
- if(this.width<2)arr.push(this);
- for(var i=0;i<this.child.length;i++)this.child[i].getClicks(arr);
- return arr;
- }
- this.drop=function(){
- if(this.shock>=-0.05){
- var lol=nois.noise(this.rand,tim/2000);
- spawnParticle(LeafParticle,this.endX,this.endY,lol<0?-lol:0,Math.max(0,lol));
- }
- this.org();
- this.shock=-4;
- }
- };
- rootSeg=new Segment({parentCount:0,origigi:0},new Vec2(300,500),100,20,1);
- startTim=0;
- clickabals=rootSeg.getClicks([]);
- function updateGrow(){
- grow=Math.min(1,(tim-startTim)/6000);
- if(grow==1){
- grow=maxPar;
- updateGrow=function(){};
- }
- grow*=grow;
- grow*=maxPar;
- }
- function drawTree(ctx){
- ctx.clear();
- if(startTim==0)return;
- updateGrow();
- sec=Math.round(tim/1000);
- if(grow>1){
- ctx.fillStyle="rgb("+trunkCol+","+trunkCol+","+trunkCol+")";
- rootSeg.update();
- rootSeg.draw(ctx);
- if(trunkCol!=terrainCol){
- ctx.fillStyle="rgb("+terrainCol+","+terrainCol+","+terrainCol+")";
- var mul=20/groundPartWidth;
- var p1=heightMap[heightMap.length-3];
- var p2=heightMap[heightMap.length-2];
- var p3=heightMap[heightMap.length-1];
- var h1=(p2-p3)*tre.height*mul;
- var h2=(p2-p1)*tre.height*mul;
- fillQuad(ctx,
- rootSeg.pos.x ,rootSeg.pos.y-10,
- rootSeg.pos.x ,rootSeg.pos.y+10,
- rootSeg.pos.x+20,rootSeg.pos.y+10,
- rootSeg.pos.x+20,rootSeg.pos.y-10-h1
- );
- fillQuad(ctx,
- rootSeg.pos.x+1 ,rootSeg.pos.y-10,
- rootSeg.pos.x+1 ,rootSeg.pos.y+10,
- rootSeg.pos.x-20,rootSeg.pos.y+10,
- rootSeg.pos.x-20,rootSeg.pos.y-10-h2
- );
- }
- ctx.addRad(rootSeg.pos.x,rootSeg.pos.y,20);
- }else{
- ctx.font="50px Comfortaa";
- ctx.fillStyle=document.body.style.color;
- var msgBound=msg.getBoundingClientRect();
- var x1=msgBound.right;
- var y1=msgBound.bottom;
- var x2=rootSeg.pos.x;
- var y2=rootSeg.pos.y;
- var grow0=grow*1.2;
- if(grow0>1)return;
- var x=x1+(x2-x1)*grow0,y=y1+(y2-y1)*grow0*grow0-12;
- ctx.addRad(x,y,10);
- ctx.fillText(".",x,y);
- }
- }
- function clck(e){
- updateGrow();
- if(grow<3)return;
- var clX=e.clientX,clY=e.clientY;
- var closest=69,minDistance=0xFFFFFFFF,posX=-1,posY=-1;
- for(var i=0;i<clickabals.length;i++){
- var cl=clickabals[i];
- if(cl.width>=2)continue;
- var difX=cl.endX-clX;
- var difY=cl.endY-clY;
- var dist=Math.sqrt(difX*difX+difY*difY);
- if(minDistance>dist){
- minDistance=dist;
- closest=cl;
- posX=cl.endX;
- posY=cl.endY;
- }
- }
- if(closest!=69&&minDistance<20){
- closest.drop();
- }
- }
- </script>
- <script type="text/javascript" id="particles">
- glintData=[];
- particles=[];
- particlePool={
- pool:{},
- get:function(type, args){
- var arr=this.pool[type.getId()];
- if(typeof arr=="undefined"||arr.length==0){
- var t=new type();
- t.init(args);
- return t;
- }
- var t=arr.shift();
- t.init(args);
- return t;
- },
- put:function(dead){
- dead=dead[0];
- var type=dead.constructor;
- var arr=this.pool[type.getId()];
- if(typeof this.pool[type.getId()]=="undefined")this.pool[type.getId()]=[];
- this.pool[type.getId()].push(dead);
- }
- };
- function LeafParticle(){
- this.pos=new Vec2();
- this.init=function(args){
- this.pos.x=args[0];
- this.pos.y=args[1];
- this.r=args[2];
- this.b=args[3];
- this.rand=Math.random()*Math.PI;
- this.cubeS=12;
- this.alpha=1;
- }
- this.update=function(){
- var xWobl=nois.noise(this.rand,tim/2000);
- this.pos.y+=Math.random()*0.7-xWobl*xWobl/1.5;
- this.pos.x+=wind*(1.05-Math.random()*0.05)+xWobl*xWobl;
- if(this.pos.x<=0||this.pos.x>tre.width)return true;
- var h=getTerH(this.pos.x);
- var w=this.cubeS*sqrtOf2;
- h+=w/2;
- h-=this.pos.y;
- this.alpha=Math.min(1,(h/w)/2);
- return h<0;
- };
- this.draw=function(ctx){
- if(this.pos.x==0)return;
- ctx.fillStyle="rgba("+Math.round(this.r*120+50)+",50,"+Math.round(this.b*120+50)+",0.4)";
- ctx.globalAlpha=this.alpha;
- ctx.save();
- ctx.translate(this.pos.x,this.pos.y);
- ctx.rotate((tim/1000+this.rand)%Math.PI*2);
- ctx.fillRect(-this.cubeS/2,-this.cubeS/2, this.cubeS,this.cubeS);
- ctx.restore();
- glintData.push(this.pos.x);
- glintData.push(this.pos.y);
- glintData.push(this.alpha*(0.2+Math.random()*0.1));
- glintData.push(this.r/2);
- };
- }
- function AmbientParticle(){
- this.pos=new Vec2();
- this.init=function(args){
- this.pos.x=args[0];
- this.pos.y=args[1];
- this.start=time();
- this.frame=0;
- this.rand=Math.random()*Math.PI*2;
- }
- this.update=function(){
- this.frame=Math.floor((time()-this.start)*20/1000);
- return this.frame>15;
- };
- this.draw=function(ctx){
- if(this.pos.x==0)return;
- var x=Math.floor(this.frame/4),y=Math.floor(this.frame%4);
- ctx.globalAlpha=0.2+Math.random()*0.8;
- ctx.save();
- ctx.translate(this.pos.x,this.pos.y);
- ctx.rotate(this.rand);
- ctx.translate(-32,-32)
- ctx.drawImage(ambientParticle,x*64,y*64,64,64,0,0,64,64);
- ctx.restore();
- ctx.addRad(this.pos.x,this.pos.y,32*sqrtOf2);
- ctx.globalAlpha=1;
- };
- }
- LeafParticle.getId=function(){return 0;};
- AmbientParticle.getId=function(){return 1;};
- function spawnParticle(type, ...args){
- particles.push(particlePool.get(type,args));
- }
- function drawPs(ctx){
- for(var i=0;i<particles.length;i++){
- var p=particles[i];
- if(p.update()){
- particlePool.put(particles.splice(i, 1))
- i--;
- }
- else p.draw(ctx);
- }
- if(glintData.length>1/256){
- while(glintData.length>0){
- ctx.globalAlpha=glintData[2];
- ctx.globalCompositeOperation="screen";
- var glintImg=glintImgs.get(glintData[3]);
- var x=glintData[0];
- var y=glintData[1];
- var imgH=glintImg.naturalHeight/2,imgW=glintImg.naturalWidth/2;
- ctx.addRect(x-imgW,y-imgH,x+imgW,y+imgH);
- ctx.drawImage(glintImg,x-imgW,y-imgH,imgW*2,imgH*2);
- glintData.splice(0,4);
- }
- ctx.globalAlpha=1;
- ctx.globalCompositeOperation="source-over";
- }
- }
- </script>
- <script type="text/javascript" id="main">
- nois=new SimplexNoise(Math);
- heightMap=[];
- heightMap.length=8;
- for(var i=0;i<heightMap.length;i++){
- heightMap[i]=1-(Math.random()*0.08+0.25-((heightMap.length-i)/heightMap.length)*0.1);
- }
- function filterImage(filter, image){
- if(typeof imgDraw=="undefined"){
- imgDraw = document.createElement('canvas');
- imgDraw.ctx=imgDraw.getContext("2d");
- }
- imgDraw.width = image.width;
- imgDraw.height = image.height;
- imgDraw.ctx.drawImage(image,0,0);
- imgDraw.ctx.putImageData(filter(imgDraw.ctx.getImageData(0,0,imgDraw.width,imgDraw.height)), 0, 0);
- return imgDraw.toDataURL('image/png');
- };
- function lod(){
- devMode=window.location.href.endsWith("?dev");
- local=window.location.href.startsWith("file:///");
- msg=document.querySelector("msg");
- bkg=document.querySelector("#bkg");
- tre=document.querySelector("#tre");
- gitImg=document.querySelector("#gitImg");
- signs=document.querySelectorAll(".Sign");
- jsStyle=document.querySelector("#jsStyle");
- bkg.ctx=bkg.getContext("2d");
- tre.ctx=tre.getContext("2d");
- injectClearAreaMaker(tre.ctx);
- processGlint();
- updateSun();
- setTimeout(function(){
- res();
- updateSun();
- type();
- setInterval(updateSun, 30*1000);
- },50)
- requestAnimationFrame(rend);
- rend();
- res();
- }
- function processGlint(){
- imgDraw=document.createElement("canvas");
- imgDraw.ctx=imgDraw.getContext("2d");
- glintImg=document.querySelector("#glintImg");
- glintImg.parentNode.removeChild(glintImg);
- glintImg.id="";
- glintImg.className="";
- ambientParticle=document.querySelector("#ambientParticle");
- ambientParticle.parentNode.removeChild(ambientParticle);
- glintImgs={
- arr:[],
- get:function(r){
- return this.arr[Math.round(r*(glintImgs.arr.length-1))];
- }
- };
- glintImgs.arr[0]=glintImg;
- if(!local){
- var fine=32;
- for(var i=0;i<fine;i++){
- abc=i;
- glintImgs.arr[i]=document.createElement("img");
- glintImgs.arr[i].src=filterImage(function(pixels) {
- var d = pixels.data;
- var trans=(abc/fine);
- for (var i=0; i<d.length; i+=4){
- d[i]=50+trans*120;
- d[i+2]=50+(1-trans)*120;
- }
- return pixels;
- },glintImg);
- }
- }
- delete glintImg;
- }
- function res(){
- tre.width=tre.clientWidth;
- tre.height=tre.clientHeight;
- bkg.width=bkg.clientWidth;
- bkg.height=bkg.clientHeight;
- groundPartWidth=bkg.width-bkg.width/(heightMap.length-1)*(heightMap.length-2);
- rootSeg.pos.x=bkg.width-groundPartWidth;
- rootSeg.pos.y=bkg.height*heightMap[heightMap.length-2]+10;
- bkg.width=bkg.clientWidth;
- bkg.height=bkg.clientHeight;
- var ctx=bkg.ctx,trc="rgb("+terrainCol+","+terrainCol+","+terrainCol+")";
- ctx.fillStyle=trc;
- var w=bkg.width/(heightMap.length-1);
- for(var i=0;i<heightMap.length-1;i++){
- ctx.beginPath();
- ctx.moveTo( i *w-1,bkg.height*heightMap[i]);
- ctx.lineTo( i *w-1,bkg.height);
- ctx.lineTo((i+1)*w ,bkg.height);
- ctx.lineTo((i+1)*w ,bkg.height*heightMap[i+1]);
- ctx.fill();
- }
- for(var i=0;i<signs.length;i++){
- var s=signs[i];
- var b=s.getBoundingClientRect();
- var y=tre.height,mid=(b.left+b.right)/2,midH=getTerH(mid);
- y=Math.min(y,getTerH(b.left));
- y=Math.min(y,getTerH(b.right));
- y=Math.min(y,midH);
- y-=b.height+35;
- s.style.top=y+"px";
- b=s.getBoundingClientRect();
- ctx.fillStyle=trc;
- ctx.beginPath();
- ctx.arc((b.left+b.right)/2, midH, 10, 0, 2 * Math.PI, false);
- ctx.fill();
- ctx.fillStyle="rgba(120,120,120,0.1)";
- ctx.beginPath();
- ctx.moveTo(mid,midH);
- ctx.lineTo(b.left,b.bottom);
- ctx.lineTo(b.right,b.bottom);
- ctx.fill();
- if(typeof ctx.createLinearGradient!="undefined"){
- var grd=ctx.createLinearGradient(0,midH,0,b.bottom);
- grd.addColorStop(0.1,trc);
- grd.addColorStop(0.8,"transparent");
- ctx.strokeStyle=grd;
- ctx.beginPath();
- ctx.moveTo(mid,midH);
- ctx.lineTo(b.left,b.bottom);
- ctx.moveTo(mid,midH);
- ctx.lineTo(b.right,b.bottom);
- ctx.stroke();
- }
- }
- }
- function getTerH(x){
- var index=x/groundPartWidth;
- var partId=Math.floor(index);
- index-=partId;
- var p1=heightMap[partId],p2=heightMap[partId+1];
- return (p1+(p2-p1)*index)*tre.height;
- }
- function rend(){
- tim=time();
- if(Math.random()>0.995){
- var x=Math.random()*tre.width;
- spawnParticle(AmbientParticle,x,Math.random()*getTerH(x));
- }
- drawTree(tre.ctx);
- wind=Math.sin(rootSeg.angle);
- drawPs(tre.ctx);
- //ctx.drawImage(gitImg,100,100,200,200);
- requestAnimationFrame(rend);
- }
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment