下面的代码只有在支持html5下的浏览器中运行!!html5写的3d逼真圣诞树效果
<!doctype html public "-//w3c//dtd html 4.01 frameset//en" "/tr/html4/frameset.dtd">
<html>
<head>
<title>html5写的3d逼真圣诞树效果</title>
<meta charset="utf-8" >
<style>
html, body { width: 100%; height: 100%; margin: 0; padding: 0; border: 0; }
p { margin: 0; padding: 0; border: 0; }
.nav {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 27px;
background-color: white;
color: black;
text-align: center;
line-height: 25px;
}
a { color: black; text-decoration: none; border-bottom: 1px dashed black; }
a:hover { border-bottom: 1px solid red; }
.previous { float: left; margin-left: 10px; }
.next { float: right; margin-right: 10px; }
.green { color: green; }
.red { color: red; }
textarea { width: 100%; height: 100%; border: 0; padding: 0; margin: 0; padding-bottom: 20px; }
.block-outer { float: left; width: 22%; height: 100%; padding: 5px; border-left: 1px solid black; margin: 30px 3px 3px 3px; }
.block-inner { height: 68%; }
.one { border: 0; }
</style>
</head>
<body marginwidth="0" marginheight="0">
<canvas id="c" height="356" width="446">
<script>
var collapsed = true;
function toggle() {
var fs = top.document.getelementsbytagname('frameset')[0];
var f = fs.getelementsbytagname('frame');
if (collapsed) {
fs.rows = '250px,*';
// enable resizing of frames in firefox/opera
fs.noresize = false;
f[0].noresize = false;
f[1].noresize = false;
} else {
fs.rows = '30px,*';
// disable resizing of frames in firefox/opera
fs.noresize = true;
f[0].noresize = true;
f[1].noresize = true;
}
collapsed = !collapsed;
}
</script>
<script>
var b = document.body;
var c = document.getelementsbytagname('canvas')[0];
var a = c.getcontext('2d');
document.body.clientwidth; // fix bug in chrome.
</script>
<script>
// start of submission //
m=math;q=m.random;j=[];u=16;t=m.sin;e=m.sqrt;for(o=k=0;x=z=j=i=k<200;)with(m[k]=k?c.clonenode(0):c){width=height=k?32:w=446;with(getcontext('2d'))if(k>10|!k)for(font='60px impact',v='rgba(';i=i*u,fillstyle=k?k==13?v+'205,205,215,.15)':v+(147+i)+','+(k%2?128+i:0)+','+i+',.5)':'#cca',i<7;)beginpath(fill(arc(u-i/3,24-i/2,k==13?4-(i++)/2:8-i++,0,m.pi*2,1)));else for(;x=t(i),y=q()*2-1,d=x*x+y*y,b=e(d-x/.9-1.5*y+1),r=67*(b+1)*(l=k/9+.8)>>1,i++<w;)if(d<1)beginpath(strokestyle=v+r+','+(r+b*l>>0)+',40,.1)'),moveto(u+x*8,u+y*8),lineto(u+x*u,u+y*u),stroke();for(y=h=k+e(k++)*25,r=q()*w;p=3,j<h;)j[o++]=[x+=t(r)*p+q()*6-3,y+=q()*u-8,z+=t(r-11)*p+q()*6-3,j/h*20+((j+=u)>h&q()>.8?q(p=9)*4:0)>>1]}setinterval(function g(m,l){a=t(d-11);if(l)return(m[2]-l[2])*a+(l[0]-m[0])*t(d);a.clearrect(0,0,w,w);j.sort(g);for(i=0;l=j[i++];a.drawimage(m[l[3]+1],207+l[0]*a+l[2]*t(d)>>0,l[1]>>1)){if(i==2e3)a.filltext('merry christmas!',u,345);if(!(i%7))a.drawimage(m[13],((157*(i*i)+t(d*5+i*i)*5)%w)>>0,((113*i+(d*i)/60)%(290+i/99))>>0);}d+=.02},1)
// end of submission //
</script>
</body>
</html>
以上就是分享用html5来实现一个3d逼真的圣诞树的详细内容。