2
我已經定義了兩個函數來渲染一個圓和一個三角形。非常直截了當的東西。畫布項目不能正確渲染
function circle(offset, size){
var color = $("#color option:selected").val();
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
radius = size * 1;
context.beginPath();
context.arc(offset, 2, radius, 0, 2 * Math.PI, false);
context.fillStyle = color;
context.fill();
}
function triangle(offset, size){
var color = $("#color option:selected").val();
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
var width = size * 6;
var height = size * 5;
var padding = 0;
// Draw a path
context.beginPath();
context.moveTo(offset + width/2, padding);
context.lineTo(offset + width, height + padding);
context.lineTo(offset, height + padding);
context.closePath();
// Fill the path
context.fillStyle = color;
context.fill();
}
我已經添加了畫布到我的頁面:
<canvas id="canvas"></canvas>
出於某種原因,我可以看到圓和廣場無法正常渲染。請參閱附加屏幕截圖。
是的。我將它改爲:它完美的工作!謝謝! – Tithos 2012-04-11 20:33:04