温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

用html5画动态太极图

发布时间:2020-06-12 17:21:33 来源:网络 阅读:4258 作者:desuzh 栏目:移动开发
  1. <!DOCTYPE HTML>  
  2. <html>  
  3. <body>  
  4.   
  5. <canvas id="myCanvas"  width="500" height="500" >your browser does not support the canvas tag </canvas>  
  6.   
  7.  <script type="text/javascript">   
  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.  </script>   
  54.   
  55. </body>  
  56. </html>  


 

用html5画动态太极图

  1. <!DOCTYPE HTML>   
  2. <html>   
  3. <body>   
  4.    
  5. <canvas id="myCanvas"  width="500" height="500" >your browser does not support the canvas tag </canvas>   
  6.    
  7.  <script type="text/javascript">    
  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.  </script>    
  53.    
  54. </body>   
  55. </html>   

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

 

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI