• 前端——一些js的代码


    1. html>
    2. <html lang="en-us">
    3. <head>
    4. <meta charset="utf-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <title>Simple DOM exampletitle>
    7. <style>
    8. body {
    9. margin: 0;
    10. overflow: hidden;
    11. }
    12. style>
    13. <canvas class="myCanvas">
    14. <p>添加恰当的反馈信息。p>
    15. canvas>
    16. <script>
    17. var canvas = document.querySelector('.myCanvas');
    18. var width = canvas.width = window.innerWidth;
    19. var height = canvas.height = window.innerHeight;
    20. var ctx = canvas.getContext('2d');
    21. ctx.fillStyle = 'rgb(0, 0, 0)';
    22. ctx.fillRect(0, 0, width, height);
    23. ctx.fillStyle = 'rgb(255, 0, 0)';
    24. ctx.fillRect(50, 50, 100, 150);
    25. ctx.fillStyle = 'rgb(0, 255, 0)';
    26. ctx.fillRect(75, 75, 100, 100);
    27. ctx.fillStyle = 'rgba(255, 0, 255, 0.75)';
    28. ctx.fillRect(25, 100, 175, 50);
    29. ctx.strokeStyle = 'rgb(255, 255, 255)';
    30. ctx.strokeRect(25, 25, 175, 200);
    31. ctx.lineWidth = 5;
    32. ctx.fillStyle = 'rgb(255, 0, 0)';
    33. ctx.beginPath();
    34. ctx.moveTo(50, 50);
    35. // 绘制路径
    36. ctx.fill();
    37. function degToRad(degrees) {
    38. return degrees * Math.PI / 180;
    39. };
    40. ctx.fillStyle = 'rgb(255, 0, 0)';
    41. ctx.beginPath();
    42. ctx.moveTo(50, 50);
    43. ctx.lineTo(150, 50);
    44. var triHeight = 50 * Math.tan(degToRad(60));
    45. ctx.lineTo(100, 50+triHeight);
    46. ctx.lineTo(50, 50);
    47. ctx.fill();
    48. ctx.fillStyle = 'rgb(0, 0, 255)';
    49. ctx.beginPath();
    50. ctx.arc(150, 106, 50, degToRad(0), degToRad(360), false);
    51. ctx.fill();
    52. var image = new Image();
    53. image.src = '22.png';
    54. image.onload = function() {
    55. ctx.drawImage(image, 50, 50);
    56. }
    57. // ctx.drawImage(image, 20, 20, 185, 175, 50, 50, 185, 175);
    58. ctx.translate(width/2, height/2);
    59. function degToRad(degrees) {
    60. return degrees * Math.PI / 180;
    61. };
    62. function rand(min, max) {
    63. return Math.floor(Math.random() * (max-min+1)) + (min);
    64. }
    65. var length = 250;
    66. var moveOffset = 20;
    67. for(var i = 0; i < length; i++) {
    68. ctx.fillStyle = 'rgba(' + (255-length) + ', 0, ' + (255-length) + ', 0.9)';
    69. ctx.beginPath();
    70. ctx.moveTo(moveOffset, moveOffset);
    71. ctx.lineTo(moveOffset+length, moveOffset);
    72. var triHeight = length/2 * Math.tan(degToRad(60));
    73. ctx.lineTo(moveOffset+(length/2), moveOffset+triHeight);
    74. ctx.lineTo(moveOffset, moveOffset);
    75. ctx.fill();
    76. length--;
    77. moveOffset += 0.7;
    78. ctx.rotate(degToRad(5));
    79. }
    80. script>
    81. head>
    82. <body>
    83. body>
    84. html>

  • 相关阅读:
    实操演练 | 使用 Navicat 对 MySQL 表进行分区
    框架之SpringBoot基础(一)
    WPF数据模板
    中仑网络全站 Dubbo 2 迁移 Dubbo 3 总结
    java对mysql的json字段的新增或修改
    POSTGIS数据库操作
    tomcat-8.5.55 cluster配置session共享实现不停机部署
    java基于springboot同城绘本馆图书借阅报名系统
    php生成个性二维码
    Gradle【扫盲】使用简易教程
  • 原文地址:https://blog.csdn.net/qqqweiweiqq/article/details/128118531