canvas實現的七巧板效果程式碼例項
分享一段簡單的程式碼例項,它實現了簡單的七巧板效果。
程式碼例項如下:
[HTML] 純文字檢視 複製程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <script> window.onload = function() { var canvas = document.getElementById("canvas"); canvas.width = 500; canvas.height = 500; var context = canvas.getContext("2d"); context.beginPath() context.moveTo(0, 0) context.lineTo(250, 250) context.lineTo(500, 0) context.closePath() context.fillStyle = "green" context.fill() context.stroke() context.beginPath() context.moveTo(0, 0) context.lineTo(250, 250) context.lineTo(0, 500) context.closePath() context.fillStyle = "pink" context.fill() context.beginPath() context.moveTo(0, 500) context.lineTo(125, 375) context.lineTo(250, 500) context.closePath() context.fillStyle = "red" context.fill() context.stroke() context.beginPath() context.moveTo(125, 375) context.lineTo(250, 250) context.lineTo(375, 375) context.lineTo(250, 500) context.closePath() context.fillStyle = "purple" context.fill() context.beginPath() context.moveTo(250, 250) context.lineTo(375, 125) context.lineTo(375, 375) context.closePath() context.fillStyle = "yellow" context.fill() context.beginPath() context.moveTo(500, 0) context.lineTo(500, 250) context.lineTo(375, 375) context.lineTo(375, 125) context.closePath() context.fillStyle = "blue" context.fill() context.beginPath() context.moveTo(500, 250) context.lineTo(250, 500) context.lineTo(500, 500) context.closePath() context.fillStyle = "black" context.fill() } </script> </head> <body> <canvas id="canvas"></canvas> </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
- canvas原型鐘錶效果程式碼例項Canvas原型
- canvas氣泡上浮效果程式碼例項Canvas
- canvas田字格效果程式碼例項Canvas
- canvas繪製圓環效果程式碼例項Canvas
- canvas螞蟻線效果程式碼例項Canvas
- canvas實現的變幻線程式碼例項Canvas線程
- canvas實現的多邊形程式碼例項Canvas
- canvas實現的千輪眼程式碼例項Canvas
- jquery實現的選項卡效果例項程式碼jQuery
- canvas模擬彈幕效果程式碼例項Canvas
- canvas繪製箭頭效果程式碼例項Canvas
- canvas繪製夜空小屋效果程式碼例項Canvas
- canvas流星劃過星空效果程式碼例項Canvas
- canvas繪製鐘錶效果程式碼例項Canvas
- canvas繪製橢圓效果程式碼例項Canvas