2011-07-21 20 views
0

私は三角形のキャンバスを描くためにこのコードを持っています。しかし、私は黒以外の塗りつぶし色を得ることはできません。それはctx.fillStyleで動作すると言われていますが、そうではありません。私は自分のコードで何かを見逃している必要がありますあなたは一見を持っていることができますか?キャンバスに色を塗りつぶし、黒色にします

function drawShape(){ 
    // get the canvas element using the DOM 
     var canvas = document.getElementById('balkboven'); 

    // Make sure we don't execute when canvas isn't supported 
     if (canvas.getContext){ 

    // use getContext to use the canvas for drawing 
     var ctx = canvas.getContext('2d'); 
     var ctxwidth = window.innerWidth;    
    // Filled triangle 
     ctx.canvas.width = window.innerWidth; 
     ctx.beginPath(); 
     ctx.moveTo(0,0); 
     ctx.lineTo(ctxwidth,0); 
     ctx.lineTo(0,105); 
     ctx.fill(); 
     ctx.fillStyle="red" 

    } 
} 

答えて

5

fillStylestrokeStyleあなたはその後、オブジェクトを描画していない前を設定する必要があります!

ペイントブラシにペイントしていると考えてください。あなたはブラシでストロークする前にこれをしなければなりません!

参照:http://jsfiddle.net/F8smR/

+0

ありがとう、私はこれを試してみました。 – Jurriaan

関連する問題