zoukankan      html  css  js  c++  java
  • Canvas路径、描边、填充

    <script>
        var context = document.getElementById('canvas').getContext('2d');
        context.font = '48pt Helvetica';
        context.strokeStyle = 'blue';//边框颜色
        context.fillStyle = 'red';//填充颜色
        context.lineWidth = '2';
    
        //画文字
        context.strokeText('边框', 60, 110);
        context.fillText('填充', 440, 110);
    
        context.strokeText('边框和填充', 650, 110);
        context.fillText('边框和填充', 650, 110);
        //画矩形
        context.lineWidth = '5';
        context.beginPath();//边框 矩形
        context.rect(80, 150, 150, 100);
        context.stroke();
    
        context.beginPath();//填充 矩形
        context.rect(400, 150, 150, 100);
        context.fill();
    
        context.beginPath();//边框和填充
        context.rect(750, 150, 150, 100);
        context.stroke();
        context.fill();
    
        //画弧度
        context.beginPath();
        context.arc(150, 370, 60, 0, 1.5 * Math.PI);
        context.stroke();
    
        context.beginPath();
        context.arc(475, 370, 60, 0, Math.PI * 3 / 2);
        context.fill();
    
        context.beginPath();
        context.arc(820, 370, 60, 0, Math.PI * 3 / 2);
        context.stroke();
        context.fill();
        //closePath()方法创建当前点到起始点的路径
        context.beginPath();
        context.arc(150, 550, 60, 0, Math.PI * 3 / 2);
        context.closePath();
        context.stroke();
    
        context.beginPath();
        context.arc(475, 550, 60, 0, Math.PI * 3 / 2);
        context.closePath();
        context.fill();
    
        context.beginPath();
        context.arc(820, 550, 60, 0, Math.PI * 3 / 2);
        context.closePath();
        context.stroke();
        context.fill();
        //绘制三角形
        context.beginPath();
        context.moveTo(120, 650);
        context.lineTo(120, 750);
        context.lineTo(180, 750);
        context.closePath();
        context.stroke();
    
        context.beginPath();
        context.moveTo(450, 650);
        context.lineTo(450, 750);
        context.lineTo(510, 750);
        context.closePath();
        context.fill();
    
        context.beginPath();
        context.moveTo(810, 650);
        context.lineTo(810, 750);
        context.lineTo(870, 750);
        context.closePath();
        context.fill();
        context.stroke();
    
        context.beginPath();
        context.moveTo(120, 800);
        context.lineTo(120, 900);
        context.lineTo(180, 900);
        context.stroke();
    
        context.beginPath();
        context.moveTo(450, 800);
        context.lineTo(450, 900);
        context.lineTo(510, 900);
        context.fill();
    
        context.beginPath();
        context.moveTo(810, 800);
        context.lineTo(810, 900);
        context.lineTo(870, 900);
        context.fill();
        context.stroke();
    </script>

    练习代码

  • 相关阅读:
    IP地址 子网掩码 默认网关和DNS服务器的关系
    ios下微信浏览器如何唤醒app?app已上架应用宝
    iOS: 零误差或极小误差的定时执行或延迟执行?
    iOS单例创建的一点疑惑
    Method Swizzing中一般替换方法都写在Category类别里吗?有没有别的实现方式
    相机拍照友盟检测crash是为什么?
    使用google API之前需要對input 做什麼 安全性的處理?
    关于node的聊天室错误
    Node+Deployd+MongoDB安装问题
    array.fliter无法正确过滤出我想要的数组
  • 原文地址:https://www.cnblogs.com/yanshanshuo/p/3908589.html
Copyright © 2011-2022 走看看