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>

    练习代码

  • 相关阅读:
    摄像机标定公式推导
    roscpp源码阅读
    机器学习(Machine Learning)&深度学习(Deep Learning)资料汇总 (上)
    机器学习(Machine Learning)&深度学习(Deep Learning)资料(下)
    【概率论与数理统计】全概率公式和贝叶斯公式
    机器学习之一些基本概念及符号系统
    机器学习之代价函数(cost function)
    机器学习之逻辑回归(Logistic Regression)
    机器学习之神经网络模型-下(Neural Networks: Representation)
    机器学习之神经网络模型-上(Neural Networks: Representation)
  • 原文地址:https://www.cnblogs.com/yanshanshuo/p/3908589.html
Copyright © 2011-2022 走看看