前端——一些js的代码

<!DOCTYPE html>
<html lang="en-us">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Simple DOM example</title>
    <style>
        body {
            margin: 0;
            overflow: hidden;
        }
    </style>
    <canvas class="myCanvas">
        <p>添加恰当的反馈信息。</p>
    </canvas>
    <script>
        var canvas = document.querySelector('.myCanvas');
        var width = canvas.width = window.innerWidth;
        var height = canvas.height = window.innerHeight;
        var ctx = canvas.getContext('2d');
        ctx.fillStyle = 'rgb(0, 0, 0)';
        ctx.fillRect(0, 0, width, height);
        ctx.fillStyle = 'rgb(255, 0, 0)';
        ctx.fillRect(50, 50, 100, 150);
        ctx.fillStyle = 'rgb(0, 255, 0)';
        ctx.fillRect(75, 75, 100, 100);
        ctx.fillStyle = 'rgba(255, 0, 255, 0.75)';
        ctx.fillRect(25, 100, 175, 50);
        ctx.strokeStyle = 'rgb(255, 255, 255)';
        ctx.strokeRect(25, 25, 175, 200);
        ctx.lineWidth = 5;
        ctx.fillStyle = 'rgb(255, 0, 0)';
        ctx.beginPath();
        ctx.moveTo(50, 50);
        // 绘制路径
        ctx.fill();
        function degToRad(degrees) {
            return degrees * Math.PI / 180;
        };
        ctx.fillStyle = 'rgb(255, 0, 0)';
        ctx.beginPath();
        ctx.moveTo(50, 50);
        ctx.lineTo(150, 50);
        var triHeight = 50 * Math.tan(degToRad(60));
        ctx.lineTo(100, 50+triHeight);
        ctx.lineTo(50, 50);
        ctx.fill();


        ctx.fillStyle = 'rgb(0, 0, 255)';
        ctx.beginPath();
        ctx.arc(150, 106, 50, degToRad(0), degToRad(360), false);
        ctx.fill();


        var image = new Image();
        image.src = '22.png';
        image.onload = function() {
            ctx.drawImage(image, 50, 50);
        }
        // ctx.drawImage(image, 20, 20, 185, 175, 50, 50, 185, 175);
        ctx.translate(width/2, height/2);
        function degToRad(degrees) {
            return degrees * Math.PI / 180;
        };

        function rand(min, max) {
            return Math.floor(Math.random() * (max-min+1)) + (min);
        }

        var length = 250;
        var moveOffset = 20;

        for(var i = 0; i < length; i++) {
            ctx.fillStyle = 'rgba(' + (255-length) + ', 0, ' + (255-length) + ', 0.9)';
            ctx.beginPath();
            ctx.moveTo(moveOffset, moveOffset);
            ctx.lineTo(moveOffset+length, moveOffset);
            var triHeight = length/2 * Math.tan(degToRad(60));
            ctx.lineTo(moveOffset+(length/2), moveOffset+triHeight);
            ctx.lineTo(moveOffset, moveOffset);
            ctx.fill();

            length--;
            moveOffset += 0.7;
            ctx.rotate(degToRad(5));
        }
    </script>
</head>
<body>


</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qqqweiweiqq

你的鼓励将是我最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值