canvas繪製機器貓頭像程式碼例項
分享一段程式碼例項,它利用canvas繪製機器貓頭像的效果。
程式碼例項如下:
[HTML] 純文字檢視 複製程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> </head> <body> <canvas width="1300" height="600" id="myCanvas"></canvas> <script> var a = document.getElementById('myCanvas'); var cxt = a.getContext('2d'); cxt.fillStyle = "#22c1f1"; //大圓 cxt.beginPath(); cxt.scale(1.4, 1.2); cxt.arc(500, 110, 100, 0, Math.PI * 2, false); cxt.fill(); cxt.strokeStyle = "#000"; cxt.lineWidth = 1; cxt.beginPath(); cxt.arc(500, 110, 100, 0, Math.PI * 2, false); cxt.stroke(); cxt.fillStyle = "#fff"; //小圓 cxt.beginPath(); cxt.arc(500, 130, 75, 0, Math.PI * 2, false); cxt.fill(); cxt.strokeStyle = "#000"; cxt.lineWidth = 1; cxt.beginPath(); cxt.arc(500, 130, 75, 0, Math.PI * 2, false); cxt.stroke(); cxt.strokeStyle = "#000"; //左眼睛 cxt.lineWidth = 2; cxt.beginPath(); cxt.scale(0.7, 1.1); cxt.arc(680, 55, 30, 0, Math.PI * 2, false); cxt.stroke(); cxt.fillStyle = "#fff"; //眼睛 cxt.lineWidth = 1; cxt.beginPath(); cxt.arc(680, 55, 30, 0, Math.PI * 2, false); cxt.fill(); cxt.fillStyle = "#000"; cxt.lineWidth = 1; cxt.beginPath(); cxt.arc(695, 65, 5, 0, Math.PI * 2, false); cxt.fill(); cxt.strokeStyle = "#000"; //右眼睛 cxt.lineWidth = 2; cxt.beginPath(); //cxt.scale(0.7,1.1); cxt.arc(740, 55, 30, 0, Math.PI * 2, false); cxt.stroke(); cxt.fillStyle = "#fff"; //眼睛 cxt.lineWidth = 1; cxt.beginPath(); cxt.arc(740, 55, 30, 0, Math.PI * 2, false); cxt.fill(); cxt.fillStyle = "#000"; cxt.lineWidth = 1; cxt.beginPath(); cxt.arc(725, 65, 5, 0, Math.PI * 2, false); cxt.fill(); cxt.strokeStyle = "#000"; //鼻子 cxt.lineWidth = 1; cxt.beginPath(); cxt.arc(710, 80, 10, 0, Math.PI * 2, false); cxt.stroke(); cxt.fillStyle = "#ba2727"; cxt.lineWidth = 1; cxt.beginPath(); cxt.arc(710, 80, 10, 0, Math.PI * 2, false); cxt.fill(); cxt.strokeStyle = "#000"; cxt.lineWidth = 3; cxt.beginPath(); cxt.moveTo(710, 90); //嘴巴 cxt.lineTo(710, 155); cxt.stroke(); cxt.strokeStyle = "#000"; cxt.lineWidth = 3; cxt.beginPath(); cxt.scale(0.9, 0.3); cxt.arc(790, 425, 90, 0, Math.PI, false); cxt.stroke(); cxt.strokeStyle = "#000"; // 鬍鬚 cxt.lineWidth = 3; cxt.beginPath(); cxt.moveTo(700, 270); cxt.lineTo(750, 320); cxt.stroke(); cxt.strokeStyle = "#000"; //鬍鬚 cxt.lineWidth = 3; cxt.beginPath(); cxt.moveTo(700, 340); cxt.lineTo(750, 340); cxt.stroke(); cxt.strokeStyle = "#000"; //鬍鬚 cxt.lineWidth = 3; cxt.beginPath(); cxt.moveTo(750, 360); cxt.lineTo(700, 390); cxt.stroke(); cxt.strokeStyle = "#000"; //鬍鬚 cxt.lineWidth = 3; cxt.beginPath(); cxt.moveTo(875, 270); cxt.lineTo(825, 320); cxt.stroke(); cxt.strokeStyle = "#000"; //鬍鬚 cxt.lineWidth = 3; cxt.beginPath(); cxt.moveTo(825, 340); cxt.lineTo(875, 340); cxt.stroke(); cxt.strokeStyle = "#000"; //鬍鬚 cxt.lineWidth = 3; cxt.beginPath(); cxt.moveTo(825, 360); cxt.lineTo(875, 390); cxt.stroke(); cxt.fillStyle = "#ba2727"; //項鍊 cxt.fillRect(670, 570, 250, 65); cxt.fill(); cxt.strokeStyle = "#000"; //項鍊 cxt.lineWidth = 2; cxt.strokeRect(670, 572, 250, 65); cxt.stroke(); cxt.fillStyle = "#f6ea1c"; //鈴鐺 cxt.strokeStyle = "#000"; cxt.beginPath(); cxt.scale(0.5, 1.0); cxt.arc(1580, 620, 40, 0, Math.PI * 2, false); cxt.fill(); cxt.stroke(); cxt.fillStyle = "#000"; //鈴鐺 cxt.beginPath(); cxt.scale(1, 1.0); cxt.arc(1580, 620, 12, 0, Math.PI * 2, false); cxt.fill(); cxt.strokeStyle = "#000"; cxt.lineWidth = 6; cxt.beginPath(); cxt.moveTo(1580, 660); cxt.lineTo(1580, 610); cxt.stroke(); cxt.strokeStyle = "#000"; cxt.lineWidth = 3; cxt.beginPath(); cxt.moveTo(1540, 600); cxt.lineTo(1612, 600); cxt.stroke(); cxt.strokeStyle = "#000"; cxt.lineWidth = 3; cxt.beginPath(); cxt.moveTo(1540, 605); cxt.lineTo(1612, 605); cxt.stroke(); </script> </body> </html>
相關文章
- canvas繪製機器貓程式碼例項Canvas
- canvas繪製熊貓頭像程式碼例項Canvas
- canvas繪製箭頭效果程式碼例項Canvas
- canvas繪製扇形程式碼例項Canvas
- canvas繪製星星程式碼例項Canvas
- canvas 繪製雞蛋程式碼例項Canvas
- canvas繪製網格程式碼例項Canvas
- canvas繪製笑臉程式碼例項Canvas
- canvas繪製圓環效果程式碼例項Canvas
- canvas繪製米字旗程式碼例項Canvas
- canvas繪製拋物線程式碼例項Canvas線程
- canvas繪製夜空小屋效果程式碼例項Canvas
- canvas繪製鐘錶效果程式碼例項Canvas
- canvas繪製圓角矩形程式碼例項Canvas
- canvas繪製橢圓效果程式碼例項Canvas
- canvas繪製魚吃豆效果程式碼例項Canvas
- canvas繪製雪花飄落效果程式碼例項Canvas
- canvas繪製圓形鐘錶程式碼例項Canvas
- canvas繪製實心圓形程式碼例項Canvas
- canvas繪製網狀圓圈程式碼例項Canvas
- canvas繪製矩形並填充顏色程式碼例項Canvas
- canvas繪製貝濟埃曲線程式碼例項Canvas線程
- canvas繪製憤怒小鳥形象程式碼例項Canvas
- HTML5利用canvas繪製矩形程式碼例項HTMLCanvas
- canvas繪製五角星程式碼例項Canvas
- canvas繪製帶有刻度的座標系程式碼例項Canvas
- css繪製圓形程式碼例項CSS
- svg繪製半圓程式碼例項SVG
- 如何利用html5呼叫手機攝像頭程式碼例項HTML
- SVG拖動繪製矩形程式碼例項SVG
- jQuery繪製網格效果程式碼例項jQuery
- CSS3繪製菱形程式碼例項CSSS3
- div+css3程式碼繪製機器貓、哆啦A夢藍胖子CSSS3
- canvas刮刮樂程式碼例項Canvas
- canvas小球隨機漂浮碰撞程式碼例項Canvas隨機
- css3繪製月牙效果程式碼例項CSSS3
- js按住滑鼠繪製線條程式碼例項JS
- javascript繪製心形圖案程式碼例項JavaScript