百度T7 課程 canvas 學習 6, rect 補充
阿新 • • 發佈:2018-12-10
<script> function getRandomColor(){ var r = Math.floor(Math.random()*266) var g = Math.floor(Math.random()*266) var b = Math.floor(Math.random()*266) return `rgb(${r},${g},${b})` } window.onload = function(){ var c1 = document.getElementById('c1') var ctx = c1.getContext('2d') // ctx.rect(100,100,100,100) ctx.fillStyle= getRandomColor(); // ctx.fill() // ctx.strokeRect(100,100,100,100) ctx.fillRect(100,100,100,100) } </script>
總結下:
1 隨機生成顏色值
2, rect 只是路徑方法
3, fillRect 既是路徑也進行有有效填充
4. strokeRect 既是路徑也是進行描邊操作