桜の季节になって、1つの简単な桜の木H 5を分かち合って制作します.


直接JSコードへ
効果をクリックして表示
(function($,win,dom,undef) {
	
	// var bos_html = $('
'); // bos_html.appendTo("body") // canvas var tree = dom.getElementById("tree"); var box =$("#box"); console.log(tree); tree.width = 500;//$("#box").width(); tree.height = 350//$("#box").height() ; var tCxt = tree.getContext("2d"); var flower = document.getElementById("flower"); flower.width = 500;//$("#box").width(); flower.height = 350;//$("#box").height(); var cxt = flower.getContext("2d"); var flowerList = [];// var rootTop = 350 ;// var flowerColor = "rgba(255,192,203,.3)" ;// var flowerColorDeep = "rgba(241,158,194,.5)" ;// var treeColor2 = "rgba(255,192,203,.5)" ;// var treeColor = "#8B7355" ;// var fallList = [];// var g = 0.01 ;// var gWind = 0.005;// var limitSpeedY = 1;// var limitSpeedX = 1 ;// cxt.shadowColor= "#FFF" ; cxt.shadowBlur = 10 ; function drawTree(x,y,deg,step,type){ var deg1 = step%2 == 0 ? 0.1 : -0.1 ; var x1 = x + Math.cos(deg+deg1) * (step+4) * 0.8 ;// x var y1 = y + Math.sin(deg+deg1) * (step-1) * 0.8 ;// Y tCxt.beginPath(); tCxt.lineWidth = step/3; tCxt.moveTo(x,y); tCxt.lineTo(x1,y1); tCxt.strokeStyle = (step > 5 ) ? treeColor : treeColor2 ;// tCxt.stroke(); if(step > 10){// , tCxt.fillStyle = treeColor ; tCxt.arc(x,y,step/6,0,Math.PI*2); tCxt.fill(); } if( step < 3 || (step < 20 && Math.random() > 0.4)){ // var color = [flowerColorDeep,flowerColor,flowerColor][Math.round(Math.random()+0.2)] ; var r = 2+Math.random()*2 tCxt.fillStyle = color ; tCxt.arc(x1+Math.random()*3,y1+Math.random()*3,r,0,Math.PI) tCxt.fill(); flowerList.push({x:x,y:y,sx:(Math.random()-0.5),sy:0,color:color,r:r,deg:deg});// } step -- ; if(step > 0){ drawTree(x1,y1,deg,step,type); if(step%3 == 1 && step > 0 && step < 30) drawTree(x1,y1,deg+0.2 + 0.3 * Math.random(),Math.round(step/1.13));// if(step%3 == 0 && step > 0 && step < 30) drawTree(x1,y1,deg-0.2 - 0.3 * Math.random(),Math.round(step/1.13));// } } drawTree(tree.width/2,rootTop,-Math.PI/2,30,1);// var len = flowerList.length ; function step(){ if(Math.random() > 0.3) fallList.push(flowerList[Math.floor(Math.random()*len)]);// , cxt.clearRect(0,0,tree.width,tree.height); for(var i = 0 ;i < fallList.length ; i ++){ if(fallList[i].sy < limitSpeedY) fallList[i].sy += g ; fallList[i].sx += gWind ; fallList[i].x += fallList[i].sx ; fallList[i].y += fallList[i].sy ; if(fallList[i].y > rootTop){// fallList.splice(i,1); i -- ; continue ; } cxt.beginPath(); cxt.fillStyle = fallList[i].color ; fallList[i].deg += fallList[i].sx*0.05 ;// cxt.arc(fallList[i].x,fallList[i].y,fallList[i].r,fallList[i].deg,fallList[i].deg+Math.PI*1.3); cxt.fill(); } requestAnimationFrame(step); } requestAnimationFrame(step); })(jQuery,window,document);

効果をクリックして表示