1
function Paint(){
var Size = document.getElementById('Size').value;
var Opacity = document.getElementById('opa').value;
var color = document.getElementById('color').value;
canvas = document.getElementById('PaintArea');
if(canvas.getContext){
    var ctx = canvas.getContext('2d');

    ctx.fillStyle = color;
    ctx.beginPath();
    ctx.arc(musX-10, musY-10, Size, 0, Math.PI*2); 
    ctx.closePath();
    ctx.fill();
}
}

As you can see i have the fillStyle by a user input in my HTML, but how do i get the opacity in there?

2 Answers 2

2

Try this: [Updated]

ctx.globalAlpha = Opacity;

Or just set the value:

ctx.globalAlpha = 0.2;
Sign up to request clarification or add additional context in comments.

1 Comment

Worked! I had to do "ctx.globalAlpha = Opacity"
0

Please use fillstyle with color:

ctx.fillStyle = "rgba(255, 255, 255, 0.5)";

For Image please use:

context.globalAlpha = 0.5;

Here is the complete link:

http://www.w3schools.com/tags/canvas_globalalpha.asp

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.