2014-09-30 5 views

답변

3

쉽게 마지막 매개 변수가 알파 또는 불투명도 될 것 rgba에 원의 채우기 스타일로이 속성을 달성 할 수있다. 구문은 다음과 같습니다.

circle.fillStyle = "rgba(255, 255, 255, 0.5)"; 
//can be used to fill as red object with opacity of 0.5 

원하는 효과를 얻기위한 전체 코드는 다음과 같습니다.

// JavaScript Code 
 

 
var canvas = document.getElementById('myCanvas'); 
 
var context = canvas.getContext('2d'); 
 
var centerleftX = canvas.width/4; 
 
var centerRightX = 3 * canvas.width/4; 
 
var centerY = canvas.height/2; 
 
var radius = 70; 
 

 
context.beginPath(); 
 
context.rect(0, 0, 400, 200); 
 
context.fillStyle = 'rgb(200,200,200)'; 
 
context.fill(); 
 
context.lineWidth = 7; 
 
context.strokeStyle = 'black'; 
 
context.stroke(); 
 

 

 
context.beginPath(); 
 
context.arc(centerleftX + 50, centerY, radius, 0, 2 * Math.PI, false); 
 
context.fillStyle = "rgba(0, 0,255,0.7)"; 
 
context.fill(); 
 

 

 
context.beginPath(); 
 
context.arc(centerRightX - 50, centerY, radius, 0, 2 * Math.PI, false); 
 
context.fillStyle = "rgba(255, 0,0,0.7)"; 
 
context.fill();

 
<!-- HTML Code --> 
 
<canvas id="myCanvas" width="400" height="200">

+1

완벽한 솔루션! 고마워요! –

관련 문제