js實(shí)現(xiàn)驗(yàn)證碼干擾(靜態(tài))
本文實(shí)例為大家分享了js實(shí)現(xiàn)驗(yàn)證碼干擾的具體代碼,供大家參考,具體內(nèi)容如下
效果
代碼
<!DOCTYPE html><html> <head> <meta charset='UTF-8'> <title></title> <style> *{ padding: 0; margin: 0; } canvas{ background: #272822; } </style> </head> <body> <canvas id=’canvas’ width=’800’ height=’500’></canvas> <script> //獲得畫板 var canvas=document.getElementById(’canvas’); //獲得繪畫環(huán)境 var cv=canvas.getContext(’2d’); cv.fillStyle=’#272822’; cv.fillRect(0,0,800,500); cv.font=’80px 微軟雅黑’; cv.fillStyle=’greenyellow’; cv.fillText( Math.floor(Math.random()*10000),200,200); //獲得所有的圖像像素點(diǎn)信息 var alldata=cv.getImageData(0,0,800,500); //獲得像素點(diǎn)的個(gè)數(shù) var dian=alldata.data.length/4; for(var i=0;i<10000;i++){ //取隨機(jī)數(shù) var num=Math.floor(Math.random()*dian); //計(jì)算像素點(diǎn)對應(yīng)的四條信息從幾號開始 var start=(num-1)*4; alldata.data[start]=Math.floor(Math.random()*256); alldata.data[start+1]=Math.floor(Math.random()*256); alldata.data[start+2]=Math.floor(Math.random()*256); } //將數(shù)據(jù)寫回畫板 cv.putImageData(alldata,0,0); </script> </body></html>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. idea設(shè)置代碼格式化的方法步驟2. ajax異步讀取后臺傳遞回的下拉選項(xiàng)的值方法3. 關(guān)于ajax異步訪問數(shù)據(jù)的問題4. Vue打包部署到Nginx時(shí),css樣式不生效的解決方式5. Python 調(diào)用API發(fā)送郵件6. 聊一聊數(shù)據(jù)請求中Ajax、Fetch及Axios的區(qū)別7. ajax異步實(shí)現(xiàn)文件分片上傳實(shí)例代碼8. Vue組件通信$attrs、$listeners實(shí)現(xiàn)原理解析9. HTML iframe標(biāo)簽用法案例詳解10. 簡單明了帶你了解CSS Modules
