2016/02/20 codes

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>2016/02/20</title>
</head>
<body>
<div id="mainDiv">
<div id = "content">
<div id = "code">
<span class="comments">/**</span></br>
<span class="space"/><span class="comments">*2013-09-21</span><br>
<span class="space"/><span class="comments">*2016-02-20.</span><br>
<span class="space"/><span class="comments">*/</span><br>
Boy name = <span class="keyword">MR</span>Liu<br>
Girl name = <span class="keyword">MRS</span>Li<br>
<span class="comments">//Fall in love river.</span><br>
The boy loves the girl;<br>
<span class="comments">//They love each other.</span><br>
The girl loves the boy;<br>
<span class="comments">//As times go on.</span><br>
The boy can not be separated the girl;<br>
<span class="comments">//At the same time.</span><br>
The girl can not be separated the boy too;<br>
<span class="comments">//Both wind and snow all over the sky.</span><br>
<span class="comments">//Whether on foot or 5 kilometers.</span><br>
<span class="keyword">The boy </span>very <span class="keyword">happy</span>;<br>
<span class="keyword">The girl </span>also very <span class="keyword">happy</span>;<br>
<span class="placeholder"/><span class="comments">//Whether it is right now</span><br>
<span class="placeholder"/><span class="comments">//Still in the distant future</span><br>
<span class="placeholder"/>The girl has but one dream;<br>
<span class="comments">// The girl wants the girl could well have been happy.</span><br>
<br>
<br>
I want to say:<br>
Baby,i love you forever;<br>
</div>
<div id = "loveHeart">
<canvas id = "garden"></canvas>
<div id = "words">
<div id = "messages">
Darling,this is our love time.
<div id = "elapseClock"></div>
</div>
<div id = "loveu">
love you forever.<br>
<div id = "signature">-yours lin</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var offsetX = $("#loveHeart").width();
var offsetY = $("#loveHeart").height();
var together = new Date();
together.setFullYear(2013,09 ,21);
together.setHours(20);
together.setMinutes(0);
together.setSeconds(0);
together.setMilliseconds(0);
if(!document.createElement(‘canvas‘).getContext){
var msg = document.createElement("div");
var id = "errorMsg";
msg.innerHTML = "Your browser doesn‘t support HTML5!<br/>Recommend use Chrome 14+/IE 9+/Firefox 7+/Safari 4+";
document.body.appendChild(msg);
$("#code").css("display","none");
$("#copyright").css("position","absolute");
$("copyright").css("bottom","10px");
document.execCommand("stop");
}else{
setTimeout(function(){
startHeartAnimation();
},5000);
timeElapse(together);
setInterval(function(){
timeElapse(together);
},500);
adjustCodePosition();
$("#code").typewrier();
}
</script>
</body>
</html>

/***********************garden.js*******************/

function Vector(x,y){
this.x = x;
this.y = y;
}
Vector.prototype = {
rotate:function(theta){
var x = this.x;
var y = this.y;
this.x = Math.cos(theta) * x - Math.sin(theta) * y;
this.y = Math.sin(theta) * x - Math.cos(theta) * y;
return this;
}
mult:function(f){
this.x *= f;
this.y *= f;
return this;
},
clone:function(){
return Vector(this.x,this.y);
},
length:function(){
return Math.sqrt(this.x * this.x + this.y * this.y);
},
subtract:function(v){
this.x -= v,x;
this.y -= v,y;
return this;
},
set:function(x,y){
this.x = x;
this.y = y;
return this;
}
};
function Petal(stretchA,stretchB,startAngle,angle,growFactor,bloom){
this.stretchA = stretchA;
this.stretchB = stretchB;
this.startAngle = startAngle;
this.angle = angle;
this.bloom = bloom;
this.growFactor = growFactor;
this.r = 1;
this.infinished = false;
}
Petal.prototype = {
draw:function(){
var ctx = this.bloom.garden.ctx;
var v1,v2,v3,v4;
v1 = new Vector(0,this.r).rotate(Garden.degrad(this.startAngle));
v2 = v1.clone().rotate(this.angle);
v3 = v1.clone().mult(this.stretchA);
v4 = v2.clone().mult(this.stretchB);
ctx.strokeStyle = this.bloom.c;
ctx.beginPath();
ctx.moveTo(v1.x,v1.y);
ctx.bezierCurveTo(v3.x,v3,y,v4.x,v4.y,v2.x,v2.y);
ctx.stroke();
},
render:function(){
if(this.r <= this.bloom.r){
this.r += this.growFactor;
this.draw();
}else{
this.isfinished = true;
}
}
}
function Bloom(p,r,c,pc,garden){
this.p = p;
this.r = r;
this.c = c;
this.pc = pc;
this.petals = [];
this.garden = garden;
this.init();
this.garden.addBloom(this);
}
Bloom.prototype = {
draw:function(){
var p,isfinished = true;
this.garden.ctx.save();
this.garden.ctx.translate(this.p.x,this.p.y);
for(var i = 0;i < this.petals.length;i++){
p = this.petals(i);
p.render();
isfinished *= p.isfinished;
}
this.garden.restore();
if(isfinished == true){
this.garden.removeBloom(this);
}
},
init:function(){
var angle = 360/this.pc;
var startAngle = Garden.randomInt(0,90);
for(var i = 0;i < this.pc;i++){
this.petals.push(
new Petal(Garden.random(Garden.options.petalStretch.min,Garden.options.petalStretch.max),
Garden.random(Garden.options.petalStretch.min,Garden.options.petalStretch.max),
startAngle + i * angle,angle,
Garden.random(Garden.options.petalStretch.min,garden.option.growFactor.max),this)
);
}
}
}
function Garden(ctx,element){
this.blooms = [];
this.element = element;
this.ctx = ctx;
}
Garden.prototype = {
render:function(){
for(var i = 0;i < this.blooms.length;i++){
this.blooms[i].draw();
}
},
addBloom:function(b){
this.blooms.push(b);
},
removeBloom:function(b){
var bloom;
for(var i = 0;i < this.blooms.length;i++){
bloom = this.blooms[i];
if(bloom == b){
this.blooms.splice(i,1);
return this;
}
}
},
createRandomBloom:function(x,y){
this.createBloom(x,y,Garden.randomInt(Garden.options.bloomRadius.min,Garden.options.bloomRadius.max),
Garden.randomrgba(Garden.options.color.rmin,Garden.options.color.rmax,Garden.options.color.gmin,
Garden.options.color.gmax,Garden.options.color.bmin,Garden.options.color.bmax,Garden.options.color.opacity),
Garden.randomInt(Garden.options.petalCount.min,Garden.options.petalCount.max));
},
createBloom:function(x,y,r,c,pc){
new Bloom(new Vector(x,y),r,c,pc,this);
},
clear:function(){
this.blooms = [];
this,ctx.clearRect(0,0,this.element.width,this.element.height);
}
}
Garden.options = {
petalCount:{
min:8,
max:15
},
petalStretch: {
min: 0.1,
max: 3
},
growFactor:{
min:0.1,
max:1
},
bloomRadius:{
min:8,
max:10
},
density:10,
growspeed:1000/60,
color:{
rmin:128,
rmax:255,
gmin:0,
gmax:128,
bmin:0,
bmax:128,
opacity:0.1
},
tanAngle:60
};
Garden.random = function(min,max){
return Math.random() * (max - min) + min;
};
Garden.randomInt = function(min,max){
return Math.floor(Math.random() + (max - min + 1)) + min;
};
Garden.circle = 2 * Math.PI;
Garden.degrad = function(angle){
return Garden.circle / 360 * angle;
};
Garden.raddeg = function(){
return angle / Garden.circle * 360;
};
Garden.rgba = function(r,g,b,a){
return ‘rgba(‘ + r + ‘,‘ + g + ‘,‘ + b + ‘,‘ + a + ‘)‘;
};
Garden.randomrgba = function(rmin,rmax,gmin,gmax,bmin,bmax,a){
var r = Math.round(Garden.random(rmin,rmax));
var g = Math.round(Garden.random(gmin.gmax));
var b = Math.round(Garden.random(bmin.bmax));
var limit = 5;
if(Math.abs(r - g) <= limit && Math.abs(g - b) <= limit && Math.abs(r-g) <= limit){
return Garden.rgba(rmin.rmax,gmin,gmax,bmin,bmax,a);
}else{
return Garden.rgba(r,g,b,a);
}
}

时间: 2024-08-05 15:23:02

2016/02/20 codes的相关文章

2016/02/21 codes

var Class = { create:function(){ var parent = null,properties = $A(arguments); if(Object.isFunction(properties[0])) parent = properties.shift(); function kclass(){ this.initialize.apply(this.arguments); } Object.extend(kclass,Class.Methods); kclass.s

2016/02/16 codes

<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>2016/02/16 codes</title> <link rel="stylesheet" href="assets/reset.css"> <style> .slideOne{ width:

2016/02/15 codes

return e.addTest = function(a,b){ if(typeof a == "object") for(var d in a )y(a,d)&& e.addTest(d,a[d]); else{a = a.toLowerCase(); if(e[a]!== c)return e; b = typeof b = "function"?b():b, typeof f != "undefined" &&am

2016.02.20 学习笔记 数据在Activity之间的传递的情况

情况一:一个Activity跳转到另一个Activity时,将第一个Activity的数据传递到第二个Activity里面. 分析:当一个界面跳转到另一个界面的同时还要讲数据传递过去,这种情况需要用Intent类putExtra()方法实现. 具体在Onclick方法中的样例代码如下: Intent i1=new Intent(this,SecondActivity.class); String Message=Edit1.getText().toString(); i1.putExtra("M

2016/02/14 codes

<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, i

2016/02/27 codes

b2Math.b2Abs = function(a){return a > 0.0 ? a : -a ;};b2Math.b2AbsV = function(a){var b = new b2Vec2(b2Math.b2Abs(a.x),b2Math.b2Abs(a.y));return b};b2Math.b2AbsM=function(A){var B=new b2Mat22(0,b2Math.b2AbsV(A.col1),b2Math.b2AbsV(A.col2));return B;};

2016/02/24 codes

CrossVF:function (s){var tX = this.x;x.this = s * this.y;this.y = -s * tX;}, CrossFV:function (s){var tX = this.x;this.x = -s * this.y;this.y = s * tX;}, minV:function(b){this.x = this.x < b.x ? this.x: b.x;this.y = this.y < b.y ? this.y: b.y;}, max

2016/02/13 codes

return e.addTest = function(a,b){ if(typeof a == "object") for(var d in a )y(a,d)&& e.addTest(d,a[d]); else{a = a.toLowerCase(); if(e[a]!== c)return e; b = typeof b = "function"?b():b, typeof f != "undefined" &&am

2016/02/06 codes

for(i = 0,I = p.length;I>i;i++)for(c = p[i]; c.n) { if(b){if(c,f){for( m = 0,n = c.f.length;n > m;m++)if(c.f[m] = b){c.f.splice(m,1);break}!c.f.length && delete c.f} for(d in c.n)if(c.n[e](d) && c.n[d].f) var q = c.n[d].f; for(m = 0,