123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991 |
- "use strict";
- var WeatherIcon = (function(){
- function WeatherIcon(container,stroke,shadow) {
-
- this.isPlaying = false;
- this.canvas = new WeatherIcon.Canvas(container);
- this.canvas.setCanvasSize(128,128);
- this.fps = 30;
- this.particlesBorder = 20;
- this.spf = 1000/this.fps;
- this.objects = [];
- this.particles = [];
- this.timer = false;
-
-
- this.canvas.ctx.fillStyle = '#fff';
-
-
- if (stroke) {
- this.stroke = true;
- this.canvas.ctx.lineWidth = 2;
- this.canvas.ctx.strokeStyle = '#000';
- } else {
- this.stroke = false;
- this.canvas.ctx.strokeStyle = 'transparent';
- }
-
-
- if(shadow) {
- this.canvas.ctx.shadowOffsetX = 0;
- this.canvas.ctx.shadowOffsetY = 0;
- this.canvas.ctx.shadowBlur = 5;
- this.canvas.ctx.shadowColor = "black";
- }
- };
-
-
-
- WeatherIcon.Canvas = (function(){
-
-
- function Canvas(obj,id) {
-
- if (obj) {
- if (obj.nodeName=='CANVAS') {
- this.canvas = obj;
- } else {
- this.canvas = document.createElement("canvas");
- if(id) this.canvas.id = id;
- obj.appendChild(this.canvas);
-
-
- if (Canvas.ieMode) G_vmlCanvasManager.initElement(this.canvas);
- }
- } else {
- this.canvas = document.createElement("canvas");
- if (Canvas.ieMode) G_vmlCanvasManager.initElement(this.canvas);
- }
-
-
- this.ctx = this.canvas.getContext('2d');
-
- }
-
- Canvas.prototype = {
- setSize:function(w,h) {
- this.setCanvasSize(w,h);
- this.setHtmlSize(w+'px',h+'px');
- },
-
- setCanvasSize:function(w,h) {
- this.canvas.width = w;
- this.canvas.height = h;
- },
-
- setHtmlSize:function(w,h) {
-
- this.canvas.style.width = w;
- this.canvas.style.height = h;
- },
- drawBox:function(w,h,rad) {
-
- this.ctx.beginPath();
- this.ctx.moveTo(rad, 0);
-
- this.ctx.lineTo(w-rad, 0);
- this.ctx.bezierCurveTo(w, 0, w, 0, w, rad);
-
- this.ctx.lineTo(w, h-rad);
- this.ctx.bezierCurveTo(w, h, w, h, w-rad, h);
-
- this.ctx.lineTo(rad, h);
- this.ctx.bezierCurveTo(0, h, 0, h, 0, h-rad);
-
- this.ctx.lineTo(0, rad);
- this.ctx.bezierCurveTo(0, 0, 0, 0, rad, 0);
-
- this.ctx.fill();
- },
- clear:function(){
- this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height);
- }
- }
-
- Canvas.supported = function() {
-
- var canvas = document.createElement("canvas");
- return (canvas.getContext) ? true:false;
- }
-
-
-
- var
- rv = -1,
- ua = navigator.userAgent,
- re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
- if (re.exec(ua) != null) rv = parseFloat( RegExp.$1 );
- Canvas.ieMode = (rv>-1&&rv<9);
- return Canvas;}());
-
-
-
- WeatherIcon.Point = (function(){
-
- function Point(x, y){ this.x = x || 0; this.y = y || 0; };
- Point.prototype.add = function(p){ this.x+=p.x;this.y+=p.y };
- Point.prototype.set = function(x,y){ this.x=x;this.y=y };
- Point.prototype.prod = function(n){ this.x*=n;this.y*=n };
- Point.prototype.clone = function() { return new WeatherIcon.Point(this.x, this.y); };
- Point.prototype.rotate = function(r) {var x = this.x;var y = this.y;this.x = x*r.x-y*r.y;this.y = x*r.y+y*r.x;};
-
- return Point;}());
-
-
-
- WeatherIcon.Circle = function( center , r ){ this.center=center;this.r=r };
-
-
-
- WeatherIcon.prototype = {
- draw:function(){
-
- var n;
- this.canvas.clear();
-
- n = this.particles.length;
- while(n--) {
- this.particles[n].update(10);
- this.particles[n].draw(this.canvas.ctx);
- }
-
- n = this.objects.length;
- while(n--) {
- this.objects[n].update(10);
- this.objects[n].draw(this.canvas.ctx);
- }
- },
-
- update:function() {
- this.isPlaying = true;
- this.draw();
- this.timer = setTimeout(this.update.bind(this),this.spf);
- },
-
- play:function() {
- this.stop();
- this.update();
- },
-
- stop:function(){
- this.isPlaying=false;
- if (this.timer) {
- clearTimeout(this.timer);
- this.timer = false;
- }
- },
-
- setBody:function(body){
- this.body = body;
- },
-
- setIcon:function(icon){
- this.icon = icon;
- },
-
- toggle:function() {
- this.isPlaying?this.stop():this.play();
- },
- change:function(icon,mode){
-
- this.icon = icon;
- this.setIcon(icon);
- this.setBody(mode===WeatherIcon.NIGHT?WeatherIcon.NIGHT:WeatherIcon.DAY);
- this.build();
- this.draw();
- },
- addRain:function(type){
- type = type==WeatherIcon.LIGHT?WeatherIcon.LIGHT:WeatherIcon.HEAVY;
- var
- speed = 0.2,
- angle = 0.2,
- yo = 60,
- n = WeatherIcon.particles[type].length;
- while(n--) this.particles.push(new WeatherIcon.Drop(WeatherIcon.particles[type][n],speed,angle,yo));
- },
-
- addSnow:function(type){
- type = type==WeatherIcon.LIGHT?WeatherIcon.LIGHT:WeatherIcon.HEAVY;
- var
- speed = 0.2,
- angle = 0.2,
- yo = 60,
- n = WeatherIcon.particles[type].length;
-
- while(n--) this.particles.push(new WeatherIcon.Snow(WeatherIcon.particles[type][n],speed,angle,yo));
- },
-
- addSleet:function(){
-
- var
- type = WeatherIcon.LIGHT,
- speed = 0.2,
- angle = 0.2,
- yo = 60,
- n = WeatherIcon.particles[type].length;
-
- while(n--) {
- var drop = (n%2) ? new WeatherIcon.Drop(WeatherIcon.particles[type][n],speed,angle,yo):new WeatherIcon.Snow(WeatherIcon.particles[type][n],speed,angle,yo);
- this.particles.push(drop);
- }
- },
- build:function(){
-
- this.objects = [];
- this.particles = [];
-
- switch(this.icon) {
-
- case WeatherIcon.SUN:
- this.objects.push(this.body==WeatherIcon.DAY?new WeatherIcon.Sun(64,64,30):new WeatherIcon.Moon(64,64,30));
- break;
-
- case WeatherIcon.LIGHTCLOUD:
- this.objects.push(new WeatherIcon.Cloud(80,100,40));
- this.objects.push(this.body==WeatherIcon.DAY?new WeatherIcon.Sun(64,64,30):new WeatherIcon.Moon(64,64,30));
- break;
-
- case WeatherIcon.PARTLYCLOUD:
- this.objects.push(new WeatherIcon.Cloud(68,90,80));
- this.objects.push(this.body==WeatherIcon.DAY?new WeatherIcon.Sun(64,54,30):new WeatherIcon.Moon(64,54,30));
- break;
-
- case WeatherIcon.CLOUD:
- this.objects.push(new WeatherIcon.Cloud(90,80,40));
- this.objects.push(new WeatherIcon.Cloud(68,60,80));
- break;
-
- case WeatherIcon.LIGHTRAINSUN:
- this.objects.push(new WeatherIcon.Cloud(68,60,80));
- this.objects.push(this.body==WeatherIcon.DAY?new WeatherIcon.Sun(40,30,20):new WeatherIcon.Moon(40,30,20));
- this.addRain(WeatherIcon.LIGHT);
- break;
-
- case WeatherIcon.SLEETSUN:
- this.objects.push(new WeatherIcon.Cloud(68,60,80));
- this.objects.push(this.body==WeatherIcon.DAY?new WeatherIcon.Sun(40,30,20):new WeatherIcon.Moon(40,30,20));
- this.addSleet();
- break;
-
- case WeatherIcon.SNOWSUN:
- this.objects.push(new WeatherIcon.Cloud(68,60,80));
- this.objects.push(this.body==WeatherIcon.DAY?new WeatherIcon.Sun(40,30,20):new WeatherIcon.Moon(40,30,20));
- this.addSnow(WeatherIcon.LIGHT);
- break;
-
- case WeatherIcon.SNOW:
- this.objects.push(new WeatherIcon.Cloud(68,50,80));
- this.addSnow();
- break;
-
- case WeatherIcon.SNOWTHUNDER:
- this.objects.push(new WeatherIcon.Cloud(68,50,80));
- this.addSnow(WeatherIcon.LIGHT);
- this.objects.push(new WeatherIcon.Thunder(55,82,0.8));
- break;
-
- case WeatherIcon.THUNDER:
- this.objects.push(new WeatherIcon.Cloud(68,50,80));
- this.objects.push(new WeatherIcon.Thunder(30,75,0.6));
- this.objects.push(new WeatherIcon.Thunder(60,80,0.7));
- this.objects.push(new WeatherIcon.Thunder(90,75,0.6));
- break;
-
- case WeatherIcon.SLEETSUNTHUNDER:
- this.objects.push(new WeatherIcon.Cloud(68,60,80));
- this.objects.push(this.body==WeatherIcon.DAY?new WeatherIcon.Sun(40,30,20):new WeatherIcon.Moon(40,30,20));
- this.addSleet();
- this.objects.push(new WeatherIcon.Thunder(95,85,0.7));
- this.objects.push(new WeatherIcon.Thunder(58,88,0.8));
- break;
-
- case WeatherIcon.LIGHTRAINTHUNDERSUN:
- this.objects.push(new WeatherIcon.Cloud(68,60,80));
- this.objects.push(this.body==WeatherIcon.DAY?new WeatherIcon.Sun(40,30,20):new WeatherIcon.Moon(40,30,20));
- this.addRain(WeatherIcon.LIGHT);
- this.objects.push(new WeatherIcon.Thunder(30,75,0.6));
- this.objects.push(new WeatherIcon.Thunder(58,90,0.7));
- break;
-
- case WeatherIcon.SNOWSUNTHUNDER:
- this.objects.push(new WeatherIcon.Cloud(68,60,80));
- this.objects.push(this.body==WeatherIcon.DAY?new WeatherIcon.Sun(40,30,20):new WeatherIcon.Moon(40,30,20));
- this.addSnow(WeatherIcon.LIGHT);
- this.objects.push(new WeatherIcon.Thunder(30,75,0.6));
- this.objects.push(new WeatherIcon.Thunder(58,90,0.7));
- break;
-
- case WeatherIcon.LIGHTRAIN:
- this.objects.push(new WeatherIcon.Cloud(68,50,80));
- this.addRain(WeatherIcon.LIGHT);
- break;
-
- case WeatherIcon.RAIN:
- this.objects.push(new WeatherIcon.Cloud(68,50,80));
- this.addRain();
- break;
-
- case WeatherIcon.FOG:
- this.objects.push(new WeatherIcon.Fog(68,90,80));
- this.objects.push(this.body==WeatherIcon.DAY?new WeatherIcon.Sun(64,54,30):new WeatherIcon.Moon(64,54,30));
- break;
-
- case WeatherIcon.LIGHTRAINTHUNDER:
- this.objects.push(new WeatherIcon.Cloud(68,50,80));
- this.addRain(WeatherIcon.LIGHT);
- this.objects.push(new WeatherIcon.Thunder(30,72,0.7));
- this.objects.push(new WeatherIcon.Thunder(58,88,0.8));
- break;
-
- case WeatherIcon.RAINTHUNDER:
- this.objects.push(new WeatherIcon.Cloud(68,50,80));
- this.addRain();
- this.objects.push(new WeatherIcon.Thunder(30,72,0.7));
- this.objects.push(new WeatherIcon.Thunder(58,88,0.8));
- break;
-
- case WeatherIcon.SLEETTHUNDER:
- this.objects.push(new WeatherIcon.Cloud(68,50,80));
- this.addSleet();
- this.objects.push(new WeatherIcon.Thunder(95,85,0.7));
- this.objects.push(new WeatherIcon.Thunder(58,88,0.8));
- break;
-
- case WeatherIcon.EXTREME:
- case WeatherIcon.SLEET:
- this.objects.push(new WeatherIcon.Cloud(68,50,80));
- this.addSleet();
- break;
-
- }
- }
-
-
- };
-
-
-
-
- WeatherIcon.Cloud = (function(){
-
- var Cloud = function(xo,yo,w) {
-
- xo=xo?xo:68;
- yo=yo?yo:50;
- w=w?w:80;
-
- var h = w*0.5;
- var center = new WeatherIcon.Point(xo,yo);
- var size = new WeatherIcon.Point(w,h)
- var sizeMed = new WeatherIcon.Point(w>>1,h>>1)
-
-
-
- this.size = size;
- this.po = new WeatherIcon.Point( center.x - sizeMed.x , center.y );
- this.p1 = this.po.clone();
- this.p1.x += size.x;
-
- this.cl = new WeatherIcon.Circle(new WeatherIcon.Point( center.x - sizeMed.x , center.y ),w*0.14);
- this.cr = new WeatherIcon.Circle(new WeatherIcon.Point( center.x + sizeMed.x , center.y + w*0.03 ),w*0.1);
-
- this.ca = new WeatherIcon.Circle(new WeatherIcon.Point(center.x - sizeMed.x*0.42 , center.y ),w*0.35);
- this.cb = new WeatherIcon.Circle(new WeatherIcon.Point(center.x + sizeMed.x*0.45 , center.y ),w*0.25);
- this.cc = new WeatherIcon.Circle(new WeatherIcon.Point(center.x - sizeMed.x*0.20 , center.y ),w*0.28);
-
-
-
- this.pi = Math.PI;
- this.pi2 = this.pi/2;
-
- this.p2 = new WeatherIcon.Point( +this.w , this.h );
-
- }
-
- Cloud.prototype = {
-
- update:function(dt) {},
-
- draw:function(ctx) {
-
-
- ctx.beginPath();
- ctx.arc(this.cl.center.x,this.cl.center.y, this.cl.r , 0, 2*this.pi );
- ctx.arc(this.cl.center.x+this.cl.r,this.cl.center.y, this.cl.r , 0, 2*this.pi );
- ctx.arc(this.cc.center.x,this.cc.center.y, this.cc.r , 0 , 2*this.pi );
- ctx.arc(this.ca.center.x,this.ca.center.y, this.ca.r , this.pi , 0 );
- ctx.arc(this.cb.center.x,this.cb.center.y, this.cb.r , 0 , 2*this.pi );
- ctx.arc(this.cr.center.x,this.cr.center.y, 1.3*this.cr.r , 0, 2*this.pi );
- ctx.closePath();
- ctx.stroke();
- ctx.fill();
- }
-
- };
- return Cloud;}());
-
-
-
- WeatherIcon.Snow = (function(){
-
- var Snow = function(posIni,speed,angle_,yo) {
-
- this.angle = angle_;
- this.speed = speed;
- this.posIni = posIni;
- this.w = 3;
- this.dy = this.w*4;
- this.pos = this.posIni.clone();
- this.rot = new WeatherIcon.Point(Math.cos(this.angle),Math.sin(this.angle));
-
- this.v = new WeatherIcon.Point(0,this.speed);
- this.v.rotate(this.rot);
-
- this.po = new WeatherIcon.Point( );
- this.po.add(this.pos);
-
-
- var dy = this.po.y - yo;
- var m = this.rot.y/this.rot.x;
-
- this.pr = new WeatherIcon.Point( this.po.x+dy*m , yo );
-
- this.angle = Math.PI/3.5;
- this.angle2 = 2*this.angle;
- this.r = (this.w>>1);
-
- };
-
-
- Snow.prototype = {
-
- reset:function(){
- this.po.set(0,0);
- this.po.add(this.pr);
- },
-
-
- update:function(dt) {
-
- var dPos = new WeatherIcon.Point(this.v.x*dt,this.v.y*dt);
- this.po.add(dPos);
- if (this.po.y>128) { this.reset(); }
- },
-
- draw:function(ctx) {
-
- ctx.beginPath();
- ctx.arc(this.po.x,this.po.y + this.dy , this.w , 0, 6.28 );
- ctx.closePath();
- ctx.stroke();
- ctx.fill();
-
-
- }
- }
-
-
- return Snow;}());
-
-
- WeatherIcon.Drop = (function(){
-
- var Drop = function(posIni,speed,angle_,yo) {
-
- this.angle = angle_;
- this.speed = speed;
- this.posIni = posIni;
- this.isFreeze = false;
-
- this.elongation = 2;
- this.w = 10;
- this.h = this.w*this.elongation;
-
- this.pos = this.posIni.clone();
- this.rot = new WeatherIcon.Point(Math.cos(this.angle),Math.sin(this.angle));
-
- this.v = new WeatherIcon.Point(0,this.speed);
- this.v.rotate(this.rot);
-
- this.po = new WeatherIcon.Point( );
- this.p1 = new WeatherIcon.Point( -this.w , this.h );
- this.p2 = new WeatherIcon.Point( +this.w , this.h );
-
- this.p1.rotate(this.rot);
- this.p2.rotate(this.rot);
- this.po.add(this.pos);
- this.p1.add(this.pos);
- this.p2.add(this.pos);
-
-
- var dy = this.po.y - yo;
- var m = this.rot.y/this.rot.x;
- var xo = this.po.x+dy*m;
-
- this.pr = new WeatherIcon.Point( xo , yo );
-
- };
-
-
- Drop.prototype = {
-
- freeze:function(){
- this.isFreeze = true;
- this.angle = Math.PI/3.5;
- this.r = (this.w>>1);
- },
-
-
- reset:function(){
-
- this.po.set(0,0);
- this.p1.set( -this.w , this.h );
- this.p2.set( +this.w , this.h );
-
- this.p1.rotate(this.rot);
- this.p2.rotate(this.rot);
-
- this.po.add(this.pr);
- this.p1.add(this.pr);
- this.p2.add(this.pr);
- },
-
-
- update:function(dt) {
-
- var dPos = new WeatherIcon.Point(this.v.x*dt,this.v.y*dt);
-
- this.po.add(dPos);
- this.p1.add(dPos);
- this.p2.add(dPos);
-
- if (this.po.y>128) { this.reset(); }
- },
-
-
- draw:function(ctx) {
-
- ctx.beginPath();
-
- if (this.isFreeze) {
-
-
- ctx.save();
- ctx.translate( this.po.x,this.po.y );
- ctx.rect(-this.r , 0 , this.w , 1);
- ctx.restore();
-
- ctx.save();
- ctx.translate( this.po.x,this.po.y );
- ctx.rotate(this.angle);
- ctx.rect(-this.r , 0 , this.w , 1);
- ctx.restore();
-
- ctx.save();
- ctx.translate( this.po.x,this.po.y );
- ctx.rotate(-this.angle);
- ctx.rect(-this.r , 0 , this.w , 1);
- ctx.restore();
-
-
- } else {
- ctx.moveTo(this.po.x,this.po.y);
- ctx.bezierCurveTo(this.p1.x,this.p1.y,this.p2.x,this.p2.y,this.po.x,this.po.y+1e-5);
- }
- ctx.closePath();
- ctx.stroke();
- ctx.fill();
- }
-
- }
-
- return Drop;}());
-
- WeatherIcon.Thunder = (function(){
-
- function Thunder(x,y,s){
- this.so = s||1;
- this.s = this.so;
- this.x = x;
- this.y = y;
- this.ti = 500*Math.random();
-
- this.p = [];
- this.n = Thunder.points.length;
- };
-
-
- Thunder.prototype.update = function() {
-
- if (!this.t) {
- this.t = new Date().getTime() + this.ti;
- this.s = this.so;
- return;
- }
-
- var t = new Date().getTime();
- var dt = t - this.t - this.ti;
-
- this.s = 0;
-
- if (dt>2000) {this.s = 0;this.t = t;}
- else if (dt>1000) this.s = this.so;
- else if (dt>700) this.s = (Math.random()<0.5)?this.so:0;
- }
-
-
- Thunder.prototype.draw = function(ctx) {
-
- ctx.beginPath();
- ctx.save();
- ctx.translate( this.x , this.y );
- ctx.scale(this.s,this.s);
-
- ctx.moveTo(Thunder.points[0].x,Thunder.points[0].y);
- var n = this.n;
- while (n--) ctx.lineTo(Thunder.points[n].x,Thunder.points[n].y);
- ctx.stroke();
-
- ctx.fill();
- ctx.restore();
- }
-
-
- Thunder.size = { w:30 , h:45 }
- Thunder.points = [{x:0,y:0},{x:0,y:22},{x:13,y:20},{x:3,y:43},{x:28,y:15},{x:12,y:13},{x:21,y:0}];
-
-
- return Thunder;}());
-
-
- WeatherIcon.Sun = (function(){
-
- var Sun = function(xo,yo,ri,re) {
-
- xo = xo?xo:64;
- yo = yo?yo:64;
- ri = ri?ri:20;
- re = re?re:ri*1.25;
-
- var center = new WeatherIcon.Point(xo,yo);
-
- this.rotation = { val:0 , inc:0.001 };
- this.center = center;
- this.points = [];
- this.pointsExt = [];
-
- var n = 20;
- var angle = 0;
- var dAngle = Math.PI/n;
-
- while(n--){
-
- var x = ri*Math.cos(angle);
- var y = ri*Math.sin(angle);
- this.points.push(new WeatherIcon.Point(x,y));
-
- angle += dAngle;
-
- var x = re*Math.cos(angle);
- var y = re*Math.sin(angle);
- this.pointsExt.push(new WeatherIcon.Point(x,y));
-
- angle += dAngle
- }
- };
- Sun.prototype = {
-
- update:function(dt) {},
-
- draw:function(ctx) {
-
- var nMax = this.points.length;
- var n = 0;
-
- ctx.save();
- ctx.translate( this.center.x , this.center.y );
- ctx.rotate( this.rotation.val+=this.rotation.inc );
- ctx.beginPath();
- ctx.moveTo(this.pointsExt[nMax-1].x,this.pointsExt[nMax-1].y);
- for (n=0;n<nMax;n++) ctx.quadraticCurveTo(this.points[n].x,this.points[n].y,this.pointsExt[n].x,this.pointsExt[n].y);
-
- ctx.stroke();
- ctx.fill();
- ctx.restore();
- }
- }
-
- return Sun;}());
-
-
- WeatherIcon.Fog = (function(){
- var Fog = function() { this.angle = 0; }
-
- Fog.PI2 = Math.PI*2;
-
- Fog.prototype = {
-
- update:function(dt) { this.angle += 0.01;},
-
- draw:function(ctx) {
-
- var dx;
-
-
- dx = 0.2*Math.cos(this.angle)
- ctx.beginPath();
- ctx.save();
- ctx.translate( 85,62 );
- ctx.scale(13,1);
- ctx.arc(dx,0, 2 , 0, Fog.PI2 );
- ctx.closePath();
- ctx.restore();
- ctx.stroke();
- ctx.fill();
-
- dx = 0.2*Math.cos(this.angle+0.5)
- ctx.beginPath();
- ctx.save();
- ctx.translate( 40,70 );
- ctx.scale(6,0.5);
- ctx.arc(dx,0, 5 , 0, Fog.PI2 );
- ctx.closePath();
- ctx.restore();
- ctx.stroke();
- ctx.fill();
-
- dx = 0.3*Math.cos(this.angle)
- ctx.beginPath();
- ctx.save();
- ctx.translate( 80,80 );
- ctx.scale(6,0.5);
- ctx.arc(dx,0, 7 , 0, Fog.PI2 );
- ctx.closePath();
- ctx.restore();
- ctx.stroke();
- ctx.fill();
-
- dx = 0.4*Math.cos(this.angle+0.9)
- ctx.beginPath();
- ctx.save();
- ctx.translate( 56,92 );
- ctx.scale(10,1);
- ctx.arc(dx,0, 5 , 0, Fog.PI2 );
- ctx.closePath();
- ctx.restore();
- ctx.stroke();
- ctx.fill();
-
- dx = 0.2*Math.cos(this.angle)
- ctx.beginPath();
- ctx.save();
- ctx.translate( 100,104 );
- ctx.scale(7,1);
- ctx.arc(dx,0, 3 , 0, Fog.PI2 );
- ctx.closePath();
- ctx.restore();
- ctx.stroke();
- ctx.fill();
- }
- }
-
- return Fog;}());
-
-
- WeatherIcon.Moon = (function(){
- function Moon(x,y,r){ this.x = x||0; this.y = y||0; this.r=r||20;
- this.rotDirection = 1;
- this.rotAngle = 0;
- this.angleMax = 10*Math.PI/180;
- };
- Moon.prototype = {
-
- update:function() {
-
- if(this.rotAngle>this.angleMax) this.rotDirection = -1;
- else if(this.rotAngle<-this.angleMax)this.rotDirection = 1;
-
- this.rotAngle += 0.002*this.rotDirection;
- },
- draw:function(ctx) {
- ctx.save();
- ctx.translate( this.x , this.y );
- ctx.rotate( -0.6 + this.rotAngle );
-
- var a = 0.31*Math.PI;
- ctx.beginPath();
- ctx.arc(0,0, this.r , a , -a );
- ctx.arc(this.r,0, this.r , Math.PI+a , Math.PI-a , true);
- ctx.stroke();
- ctx.fill();
-
- ctx.restore();
- }
- };
- return Moon;}());
-
-
- WeatherIcon.particles = {
- heavy:[
- new WeatherIcon.Point(22,96),
- new WeatherIcon.Point(22,116),
- new WeatherIcon.Point(36,71),
- new WeatherIcon.Point(47,95),
- new WeatherIcon.Point(47,115),
- new WeatherIcon.Point(57,64),
- new WeatherIcon.Point(66,88),
- new WeatherIcon.Point(66,108),
- new WeatherIcon.Point(78,61),
- new WeatherIcon.Point(83,94),
- new WeatherIcon.Point(83,114),
- new WeatherIcon.Point(95,72),
- new WeatherIcon.Point(104,88),
- new WeatherIcon.Point(104,108)
- ],light:[
- new WeatherIcon.Point(22,96),
- new WeatherIcon.Point(36,71),
- new WeatherIcon.Point(47,110),
- new WeatherIcon.Point(66,88),
- new WeatherIcon.Point(78,61),
- new WeatherIcon.Point(83,110),
- new WeatherIcon.Point(104,88),
- ]};
-
-
-
-
-
- WeatherIcon.DAY = 'Sun';
- WeatherIcon.NIGHT = 'Moon';
-
-
- WeatherIcon.LIGHT = 'light';
- WeatherIcon.HEAVY = 'heavy';
-
- WeatherIcon.SUN = 1;
- WeatherIcon.LIGHTCLOUD = 2;
- WeatherIcon.PARTLYCLOUD = 3;
- WeatherIcon.CLOUD = 4;
- WeatherIcon.LIGHTRAINSUN = 5;
- WeatherIcon.LIGHTRAINTHUNDERSUN = 6;
- WeatherIcon.SLEETSUN = 7;
- WeatherIcon.SNOWSUN = 8;
- WeatherIcon.LIGHTRAIN = 9;
- WeatherIcon.RAIN = 10;
- WeatherIcon.RAINTHUNDER = 11;
- WeatherIcon.SLEET = 12;
- WeatherIcon.SNOW = 13;
- WeatherIcon.SNOWTHUNDER = 14;
- WeatherIcon.FOG = 15;
- WeatherIcon.SLEETSUNTHUNDER = 20
- WeatherIcon.SNOWSUNTHUNDER = 21;
- WeatherIcon.LIGHTRAINTHUNDER = 22;
- WeatherIcon.SLEETTHUNDER = 23;
-
-
- WeatherIcon.DARKDAY_SUN = 16;
- WeatherIcon.DARKDAY_LIGHTCLOUD = 17;
- WeatherIcon.DARKDAY_LIGHTRAINSUN = 18;
- WeatherIcon.DARKDAY_SNOWSUN = 19;
-
-
- WeatherIcon.THUNDER = 50;
- WeatherIcon.EXTREME = 99;
-
-
-
- WeatherIcon.add = function(dom,icon,param) {
-
- if(typeof dom=='string') dom = document.getElementById(dom);
-
- if (param==undefined) param = {};
-
- var weatherIcon = new WeatherIcon(dom,param.stroke===false?false:true,param.shadow===true?true:false);
-
- weatherIcon.setIcon(icon);
- weatherIcon.setBody(param.mode===WeatherIcon.NIGHT?WeatherIcon.NIGHT:WeatherIcon.DAY);
- weatherIcon.build();
- weatherIcon.draw();
-
- if(param.animated===true) weatherIcon.update();
-
- return weatherIcon;
- };
- return WeatherIcon;}());
|