2014-10-31 5 views
0

저는 fabric js를 사용하고 있으며 그라디언트 색상을 사용해야합니다.Fabric JS 그래디언트 색상

직물 JS 바이올린 Fabric link

참조 캔버스 구배 Reference Gredient link

정상 캔버스를 사용하는 것과 같이 경사를 달성하기 위해 원단 JS 날 가이드주세요.

Fabric JS :+Snap of code 
rect.setGradient('fill', { 
    x1: 0, 
    y1: -rect.height, 
    x2: rect.width, 
    y2: rect.height, 
    colorStops: { 
    0: "black", 
    0.5: "red", 
    1: "blue" 
    } 
}); 

Normal Canvas Code : 
var grd=ctx.createLinearGradient(45,50,170,90); 
grd.addColorStop(0,"black"); 
grd.addColorStop(0.5,"red"); 
grd.addColorStop(1,"blue"); 
ctx.fillStyle=grd; 
ctx.fillRect(20,20,150,100); 
+0

메이크업의 jsfiddle 라이브에서 작업 데모 우리가 이미 여기에 공유 다시 패브릭 JS 공유를 확인하는 예를 링크 – Innodel

+0

로 알려 : http://jsfiddle.net/ashishbhatt/e425a3ew/ 참조 : http://jsfiddle.net/ashishbhatt/7x4q91kj/ – ashishbhattb

+0

당신은 완벽한 방법으로 가고 있습니다. 무엇보다 문제가 있습니까? – Innodel

답변

1

나는 3 가지 색상으로 fabricjs를 사용하여 그라디언트를 얻으려고합니다. 바이올린 here을 사용하면 이렇게 할 수 있습니다.

//diagonal 
rect.setGradient('fill', { 
    x1: -rect.width/2, 
    y1: -rect.height/2, 
    x2: rect.width/2, 
    y2: rect.height/2, 
    colorStops: { 
    0: "black", 
    0.5: "red", 
    1: "blue" 
    } 
    }); 
// horizontal 
    rect.setGradient('fill', { 
    x1: -rect.width/2, 
    y1: 0, 
    x2: rect.width/2, 
    y2: 0, 
    colorStops: { 
     0: "black", 
     0.5: "red", 
     1: "blue" 
    } 
    }); 

    // vertical just change below 
    x1: 0, 
    y1: -rect.height/2, 
    x2: 0, 
    y2: rect.height/2, 

enter image description here enter image description here

관련 문제