• HTML5 Canvas 基本图形画法


    本文将不断增加Canvas基本图形的画法和一些简单的操作。

    首先,我们需要添加一个Canvas标签

    <canvas id="one"></canvas>

    然后,获取canvas DOM对象,并进行一些简单的设置

    <script type="text/javascript">
    
            var canvas = document.getElementById("one");
    
            var ctx = canvas.getContext("2d");
            //setting the width and height of canvas
            canvas.width = 800;
            canvas.height = 600;
    
            //填充canvas背景
            ctx.fillStyle='#333';
            ctx.fillRect(0,0,800,600);
    
            //画一条线
            ctx.beginPath();
            ctx.moveTo(10, 0);  
            ctx.lineTo(10, 400);  
            ctx.stroke();
    
            //画一个弧线,并填充。
            ctx.fillStyle="#f00";
            ctx.beginPath();
            //arc(x, y, radius, startAngle, endAngle, counterclockwise)
            /*
            *参数说明
            * x, y                    圆心的坐标
            * radius                半径
            * startAngle, endAngle 起始和结束的弧度,起始位置为3点钟方向
            * coutnerclockwise     顺时针还是逆时针 false顺时针 true逆时针
            */
            //正圆
            ctx.beginPath();
            ctx.arc(150,150,50,0,Math.PI * 2,true);
            ctx.closePath();
            ctx.fill();
    
            //半圆
            ctx.beginPath();
            ctx.arc(150,260,50,0,Math.PI,true);
            ctx.closePath();
            ctx.fill();
    
            // 1/4
            ctx.beginPath();
            ctx.arc(150,370,50,0,Math.PI / 2 ,false);
            ctx.closePath();
            ctx.fill();
    
            // 1/8
            ctx.beginPath();
            ctx.arc(150,480,50,0,Math.PI / 4 ,false);
            ctx.closePath();
            ctx.fill();
    
    
        </script>

    效果如图:

  • 相关阅读:
    超全面的vue.js使用总结
    Python3 [字典】类型 学习笔记
    Python3 [集合]类型 学习笔记
    Python 希尔排序法
    Python 堆排序法
    Python 归并排序法
    Python 冒泡排序法
    Python 选择排序法
    Python 快速排序法(转)
    Python 插入排序法
  • 原文地址:https://www.cnblogs.com/leftice/p/3254817.html
Copyright © 2020-2023  润新知