canvas 绘制动态心电图

在网上找一下绘制心电图,但大部分都是需要下载,这里我就直接发给大家,大家可以自取。
链接:https://pan.baidu.com/s/1eV12aRnoXraLpxPDbBCESA
提取码:ijil

上面打开的页面JS功能有点乱,而且还是压缩了的,很不方便查看。所以写了一个简洁版的供大家参考吧。
在这里插入图片描述

我就直接贴代码了

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Echarts实现心电图效果</title>
</head>
<style>
    .box1 {
        position: absolute;
        left: 0px;
        top: 50px;
        width: 1000px;
        height: 1300px;
    }

    .box2 {
        position: absolute;
        left: 0px;
        top: 50px;
        width: 1000px;
        height: 1300px;
    }
</style>

<body>
    <div class="box1">
        <canvas id="ecg" width="751px" height="751px"></canvas>
    </div>
    <div class="box2">
        <canvas id="line" width="751px" height="751px"></canvas>
    </div>
</body>

</html>
<script type="text/javascript">
    function drawSmallGrid(canvas) {
        var context = canvas.getContext("2d");
        context.strokeStyle = "#f1dedf";
        context.strokeWidth = 1;
        context.beginPath();
        for (var x = 0.5; x < 751; x += 3) {
            context.moveTo(x, 0);
            context.lineTo(x, 751);
            context.stroke();
        }
        for (var y = 0.5; y < 751; y += 3) {
            context.moveTo(0, y);
            context.lineTo(751, y);
            context.stroke();
        }
        context.closePath();
        return;
    }

    function drawMediumGrid(canvas) {
        var context = canvas.getContext("2d");
        context.strokeStyle = "#f0adaa";
        context.strokeWidth = 1;
        context.beginPath();
        for (var x = 0.5; x < 751; x += 15) {
            context.moveTo(x, 0);
            context.lineTo(x, 751);
            context.stroke();
        };
        for (var y = 0.5; y < 751; y += 15) {
            context.moveTo(0, y);
            context.lineTo(751, y);


            context.stroke();
        };
        context.closePath();
        return;
    }

    function drawBigGrid(canvas) {
        var context = canvas.getContext("2d");
        context.strokeStyle = "#e0514b";
        context.strokeWidth = 1;
        context.beginPath();
        for (var x = 0.5; x < 751; x += 75) {
            context.moveTo(x, 0);
            context.lineTo(x, 751);
            context.stroke();
        };
        for (var y = 0.5; y < 751; y += 75) {
            context.moveTo(0, y);
            context.lineTo(751, y);
            context.stroke();
        };
        context.closePath();
        return;
    }

    function drawLine(canvas) {
        var ctx = canvas.getContext('2d');
        ctx.strokeStyle = "#e0514b";
        ctx.strokeWidth = 1;
        let x = 2
        setInterval(() => {
            ctx.clearRect(x * 6, 0, 25, 750);
            x = x + 1
            let num = (x % 10 === 0) || (x%10 ===1) ? (Math.random() * 10 - 5) *10 + 200 :  200
            ctx.lineTo(x * 6, num )
            ctx.stroke();
            if (x > (750 / 6)) {
                x = 2
                ctx.beginPath();
            }
        }, 60);
        ctx.stroke();
        ctx.closePath();
    }

    (function() {
        var canvas = document.getElementById("ecg");
        var canvas2 = document.getElementById("line")
        drawSmallGrid(canvas);
        drawMediumGrid(canvas);
        drawBigGrid(canvas);
        drawLine(canvas2);
        return;
    })();
</script>

</script>
  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值