-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* linear gradient * radial gradients * fixes * fixes
- Loading branch information
Showing
9 changed files
with
97 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"penpot-exporter": minor | ||
--- | ||
|
||
Added support for linear and radial gradients |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { applyMatrixToPoint } from '@plugin/utils/applyMatrixToPoint'; | ||
import { matrixInvert } from '@plugin/utils/matrixInvert'; | ||
|
||
export const calculateRadialGradient = (t: Transform): { start: number[]; end: number[] } => { | ||
const transform = t.length === 2 ? [...t, [0, 0, 1]] : [...t]; | ||
const mxInv = matrixInvert(transform); | ||
|
||
if (!mxInv) { | ||
return { | ||
start: [0, 0], | ||
end: [0, 0] | ||
}; | ||
} | ||
|
||
const centerPoint = applyMatrixToPoint(mxInv, [0.5, 0.5]); | ||
const rxPoint = applyMatrixToPoint(mxInv, [1, 0.5]); | ||
const ryPoint = applyMatrixToPoint(mxInv, [0.5, 1]); | ||
|
||
const rx = Math.sqrt( | ||
Math.pow(rxPoint[0] - centerPoint[0], 2) + Math.pow(rxPoint[1] - centerPoint[1], 2) | ||
); | ||
const ry = Math.sqrt( | ||
Math.pow(ryPoint[0] - centerPoint[0], 2) + Math.pow(ryPoint[1] - centerPoint[1], 2) | ||
); | ||
const angle = | ||
Math.atan((rxPoint[1] - centerPoint[1]) / (rxPoint[0] - centerPoint[0])) * (180 / Math.PI); | ||
|
||
return { | ||
start: centerPoint, | ||
end: calculateRadialGradientEndPoint(angle, centerPoint, [rx, ry]) | ||
}; | ||
}; | ||
|
||
const calculateRadialGradientEndPoint = ( | ||
rotation: number, | ||
center: number[], | ||
radius: number[] | ||
): [number, number] => { | ||
const angle = rotation * (Math.PI / 180); | ||
const x = center[0] + radius[0] * Math.cos(angle); | ||
const y = center[1] + radius[1] * Math.sin(angle); | ||
return [x, y]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters