Skip to content

Commit

Permalink
Merge pull request #51 from ericente/feature/gradient-transparency
Browse files Browse the repository at this point in the history
Support transparency in gradient colors
  • Loading branch information
ShukantPal committed Mar 5, 2022
2 parents 969559f + 3267acb commit dd30e0f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/gradients/src/ColorStop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
*/
export interface ColorStop
{
color: number;
color: number | string;
offset: number;
}
9 changes: 6 additions & 3 deletions packages/gradients/src/GradientFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import type { Renderer } from '@pixi/core';
* @ignore
* @param color - The hexadecimal form of the color.
*/
function cssColor(color: number) {
function cssColor(color: number | string) {
if(typeof color === 'string'){
return color;
}
let string = color.toString(16);

while (string.length < 6) {
Expand Down Expand Up @@ -75,7 +78,7 @@ export class GradientFactory

colorStops.forEach((stop) => {
gradient.addColorStop(stop.offset, cssColor(stop.color));
})
});

context.fillStyle = gradient;
context.fillRect(0, 0, renderTexture.width, renderTexture.height);
Expand Down Expand Up @@ -144,7 +147,7 @@ export class GradientFactory

colorStops.forEach((stop) => {
gradient.addColorStop(stop.offset, cssColor(stop.color));
})
});

context.fillStyle = gradient;
context.fillRect(0, 0, renderTexture.width, renderTexture.height);
Expand Down

0 comments on commit dd30e0f

Please sign in to comment.