135-1821-9792

用html5画动态太极图

  1.   
  2.   
  3.   
  4.   
  5. your browser does not support the canvas tag   
  6.   
  7.     
  8.     var deg = 0;  
  9.     var r = 30;  
  10.     var rl = 100;  
  11. function drawTaiji() { 
  12. var canvas = document.getElementById('myCanvas'); 
  13. var context = canvas.getContext('2d'); 
  14. var colorA = "rgb(0, 0, 0)"; 
  15. var colorB = "red"; 
  16.  
  17. var px =Math.sin(deg)*r; 
  18. var py =Math.cos(deg)*r; 
  19. context.clearRect(0, 0, 300, 300); 
  20. context.beginPath(); 
  21. context.fillStyle = colorA; 
  22. context.arc(rl, rl, 60, 0.5 * Math.PI +deg, 1.5 * Math.PI +deg, true); 
  23. context.closePath(); 
  24. context.fill(); 
  25. context.fillStyle = colorB; 
  26. context.beginPath(); 
  27. context.arc(rl, rl, 60, 1.5* Math.PI +deg, 0.5 * Math.PI +deg, true); 
  28. context.closePath(); 
  29. context.fill(); 
  30. context.fillStyle = colorB; 
  31. context.beginPath(); 
  32. context.arc(rl+px, rl-py, 30, 0.5 * Math.PI + deg, 1.5 * Math.PI + deg, true); 
  33. context.closePath(); 
  34. context.fill(); 
  35. context.fillStyle = colorA; 
  36. context.beginPath(); 
  37. context.arc(rl-px, rl+py, 30, 1.5 * Math.PI + deg, 0.5 * Math.PI + deg, true); 
  38. context.closePath(); 
  39. context.fill(); 
  40. context.fillStyle = colorA; 
  41. context.beginPath(); 
  42. context.arc(rl+px, rl-py, 8, 0, 2 * Math.PI, true); 
  43. context.closePath(); 
  44. context.fill(); 
  45. context.fillStyle = colorB; 
  46. context.beginPath(); 
  47. context.arc(rl-px, rl+py, 8, 0, 2 * Math.PI, true); 
  48. context.closePath(); 
  49. context.fill(); 
  50. deg +=0.1; 
  51. }  
  52. setInterval(drawTaiji, 100);
  53.     
  54.   
  55.   
  56.   


 

十载的潢川网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都营销网站建设的优势是能够根据用户设备显示端的尺寸不同,自动调整潢川建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联公司从事“潢川网站设计”,“潢川网站推广”以来,每个客户项目都认真落实执行。

用html5画动态太极图

  1.    
  2.    
  3.    
  4.    
  5. your browser does not support the canvas tag    
  6.    
  7.      
  8. var canvas = document.getElementById('myCanvas'); 
  9. var ctx = canvas.getContext("2d"); 
  10. var angle = 0; 
  11. var count = 360; 
  12. var clrA = '#000'; 
  13. var clrB = 'red'; 
  14.  
  15. function taiji(x, y, radius, angle, wise) { 
  16.     angleangle = angle || 0; 
  17.     wisewise = wise ? 1 : -1; 
  18.     ctx.save(); 
  19.     ctx.translate(x, y); 
  20.     ctx.rotate(angle); 
  21.     ctx.fillStyle = clrA; 
  22.     ctx.beginPath(); 
  23.     ctx.arc(0, 0, radius, 0, Math.PI, true); 
  24.     ctx.fill(); 
  25.     ctx.beginPath(); 
  26.     ctx.fillStyle = clrB; 
  27.     ctx.arc(0, 0, radius, 0, Math.PI, false); 
  28.     ctx.fill(); 
  29.     ctx.fillStyle = clrB; 
  30.     ctx.beginPath(); 
  31.     ctx.arc(wise * -0.5 * radius, 0, radius / 2, 0, Math.PI * 2, true); 
  32.     ctx.fill(); 
  33.     ctx.beginPath(); 
  34.     ctx.fillStyle = clrA; 
  35.     ctx.arc(wise * +0.5 * radius, 0, radius / 2, 0, Math.PI * 2, false); 
  36.     ctx.arc(wise * -0.5 * radius, 0, radius / 10, 0, Math.PI * 2, true); 
  37.     ctx.fill(); 
  38.     ctx.beginPath(); 
  39.     ctx.fillStyle = clrB; 
  40.     ctx.arc(wise * +0.5 * radius, 0, radius / 10, 0, Math.PI * 2, true); 
  41.     ctx.fill(); 
  42.     ctx.restore(); 
  43.  
  44. loop = setInterval(function () { 
  45.     beginTag = true; 
  46.     ctx.clearRect(0, 0, canvas.width, canvas.height); 
  47.     taiji(200, 200, 50, Math.PI * (angle / count) * 2, true); 
  48.     //taiji(350, 350, 50, Math.PI * ((count - angle) / count) * 2, false); 
  49.     angle = (angle + 5) % count; 
  50. }, 50); 
  51.  
  52.      
  53.    
  54.    
  55.    

出自:http://www.cnblogs.com/iamzhanglei/archive/2012/03/27/2419268.html

 


分享名称:用html5画动态太极图
当前URL:http://kswsj.com/article/jpdhed.html

其他资讯



Copyright © 2009-2022 www.kswsj.com 成都快上网科技有限公司 版权所有 蜀ICP备19037934号