欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js繪制一條直線并旋轉(zhuǎn)45度

 更新時(shí)間:2020年08月21日 09:08:47   作者:yangying_0220  
這篇文章主要為大家詳細(xì)介紹了js繪制一條直線并旋轉(zhuǎn)45度,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了js繪制一條直線并旋轉(zhuǎn)45度的具體代碼,供大家參考,具體內(nèi)容如下

繪制一條直線,并旋轉(zhuǎn)45度

html 頁(yè)面

<canvas id="canvas" width="300" height="300"
  style="background-color: orange;"></canvas>

js頁(yè)面

<script>
    var canvas = document.getElementById("canvas");
    var cxt = canvas.getContext('2d');

    cxt.lineWidth = 5;
    cxt.beginPath();
    cxt.moveTo(20, 20);
    cxt.lineTo(180, 20)
    cxt.stroke();
    cxt.closePath();
    //設(shè)置異次元空間
    cxt.save();
    //異次元空間 重置原點(diǎn),默認(rèn)是畫布的(0,0)點(diǎn)
    cxt.translate(20, 20);
    //設(shè)置旋轉(zhuǎn)角度 參數(shù)時(shí)弧度 角度0--360 弧度=角度*Math.PI/180
    cxt.rotate(-30 * Math.PI / 180);

    //旋轉(zhuǎn)一個(gè)線段
    cxt.lineWidth = 5;
    cxt.beginPath();
    cxt.moveTo(0, 0);
    cxt.lineTo(20, 180);
    cxt.stroke();
    cxt.closePath();
    //將旋轉(zhuǎn)之后的元素返回原畫布
    cxt.restore();
</script>

效果圖如下顯示:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:

相關(guān)文章

最新評(píng)論