久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      涂鴉板簡單實現(xiàn) Html5編寫屬于自己的畫畫板

      這篇文章主要教大家如何使用Html5編寫屬于自己的畫畫板,進行繪畫、調(diào)整顏色等操作,感興趣的小伙伴們可以參考一下

      最近了解到html5強大的繪圖功能讓我驚奇,于是,寫了個小玩意—涂鴉板,能實現(xiàn)功能有:畫畫,改色,調(diào)整畫筆大小

      html5的繪圖可以分為點,線,面,圓,圖片等,點和線,這可是所有平面效果的基點,有了這兩個東西,沒有畫不出來的東西,只有想不到的算法。

      先上代碼了:

      html

      XML/HTML Code復制內(nèi)容到剪貼板

      <body style="cursor:pointer">    <canvas id="mycavas" width="1024" height="400" style="border:solid 4px #000000"></canvas><!--畫布-->    <input type="color" id="color1" name="color1"/><!--設(shè)色器-->    <output name="a" for="color1" onforminput="innerHTML=color1.value"></output>     <input type="range" name="points" id="size" min="5" max="20" /><!--拖動條-->    </body>

      效果:

      涂鴉板簡單實現(xiàn) Html5編寫屬于自己的畫畫板

      好了,一個簡陋的畫圖界面就搞好啦,下面開始寫一些畫線的代碼

      JavaScript Code復制內(nèi)容到剪貼板

      $.Draw = {};     $.extend($.Draw, {      D2: "",     CX:"",      Box: "mycavas",//畫布id      BoxObj:function(){//畫布對象      this.CX=document.getElementById(this.Box);      },      D2:function(){//2d繪圖對象     this.D2 = this.CX.getContext("2d");      },     Cricle: function (x, y, r, color) {//畫圓     if (this.D2) {      this.D2.beginPath();      this.D2.arc(x, y, r, 0, Math.PI * 2, true);      this.D2.closePath();      if (color) {      this.D2.fillStyle = color;      }      this.D2.fill();      }     },     init: function () {//初始化     this.BoxObj();     this.D2();     }       })

      相信這里的簡單代碼大家都看得懂,主要就是創(chuàng)建了一個對象,包含創(chuàng)建畫布,創(chuàng)建2d對象,畫圓方法,和對象初始化方法。

      接下里前臺html頁面來調(diào)用這個對象/p>

      看代碼:

      JavaScript Code復制內(nèi)容到剪貼板

      var color = "#000000";//初始化顏色      var size = 5;//初始化尺寸     document.getElementById('color1').onchange = function () {     color = this.value;      };      document.getElementById('size').onchange = function () {      size = this.value;      };      $.Draw.init();//初始化      var tag = false;//控制鼠標當前狀態(tài)并起到開啟油墨開關(guān)的作用       var current = {};//存儲鼠標按下時候的點     document.onmousedown = function (option) {//鼠標按下事件      current.x = option.x;     current.y = option.y;      $.Draw.Cricle(option.x, option.y, size, color);      tag = true;      }      document.onmouseup = function () {//鼠標抬起事件      tag = false;      }     document.onmousemove = function (option) {//鼠標移動事件      if (tag) {      if (size >= 0) {      $.Draw.Cricle(option.x, option.y, size, color);       }       }      }

      這段代碼主要有如下幾個意思

      1.捕獲顏色空間和拖動條控件的change事件,從而獲取對應的顏色和尺寸的數(shù)值,存儲下來供下面畫線用

      2.初始化畫圖對象

      3.捕獲鼠標的按下,抬起和移動事件,關(guān)鍵在一個開關(guān)可以控制油墨

      好了,一個簡單的涂鴉板就好了,上我的書法:

      涂鴉板簡單實現(xiàn) Html5編寫屬于自己的畫畫板

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號