-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove defXY and cx/cy should not affect transform #1624
- Loading branch information
Showing
122 changed files
with
3,649 additions
and
984 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
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,82 @@ | ||
import { Circle, Rect, Path, Group } from '../../../packages/g'; | ||
|
||
export async function clipPath(context) { | ||
const { canvas } = context; | ||
await canvas.ready; | ||
|
||
// in user space | ||
const clipPathCircle = new Circle({ | ||
style: { | ||
cx: 150, | ||
cy: 150, | ||
r: 35, | ||
fill: 'blue', | ||
}, | ||
}); | ||
|
||
const rect1 = new Rect({ | ||
style: { | ||
x: 0, | ||
y: 0, | ||
width: 45, | ||
height: 45, | ||
stroke: 'white', | ||
strokeWidth: 2, | ||
fill: 'red', | ||
clipPath: clipPathCircle, | ||
cursor: 'pointer', | ||
// transform: 'translate(200px, 200px)', | ||
}, | ||
}); | ||
const rect2 = rect1.cloneNode(); | ||
rect2.style.y = 55; | ||
const rect3 = rect1.cloneNode(); | ||
rect3.style.x = 55; | ||
rect3.style.y = 55; | ||
const rect4 = rect1.cloneNode(); | ||
rect4.style.x = 55; | ||
rect4.style.y = 0; | ||
|
||
const clipPathRect = new Rect({ | ||
style: { | ||
x: 125, | ||
y: 125, | ||
width: 50, | ||
height: 50, | ||
}, | ||
}); | ||
const clipPath = new Path({ | ||
style: { | ||
stroke: 'black', | ||
lineWidth: 2, | ||
path: 'M 10,10 L -10,0 L 10,-10 Z', | ||
anchor: [0.5, 0.5], | ||
}, | ||
}); | ||
|
||
const g = new Group(); | ||
const group = new Group({ | ||
style: { | ||
transform: 'translate(100, 100)', | ||
}, | ||
}); | ||
g.appendChild(clipPathCircle); | ||
group.appendChild(rect1); | ||
group.appendChild(rect2); | ||
group.appendChild(rect3); | ||
group.appendChild(rect4); | ||
g.appendChild(group); | ||
|
||
canvas.appendChild(g); | ||
|
||
// g.style.x = 200; | ||
// g.style.y = 200; | ||
|
||
clipPathCircle.animate( | ||
[{ transform: 'scale(1)' }, { transform: 'scale(2)' }], | ||
{ | ||
duration: 1500, | ||
iterations: Infinity, | ||
}, | ||
); | ||
} |
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,125 @@ | ||
import { Rect, HTML, Line } from '../../../packages/g'; | ||
|
||
export async function gradient(context) { | ||
const { canvas } = context; | ||
await canvas.ready; | ||
// single linear gradient | ||
const rect1 = new Rect({ | ||
style: { | ||
x: 50, | ||
y: 50, | ||
width: 200, | ||
height: 100, | ||
fill: 'linear-gradient(0deg, blue, green 40%, red)', | ||
}, | ||
}); | ||
|
||
// multi linear gradients | ||
const rect2 = new Rect({ | ||
style: { | ||
x: 50, | ||
y: 250, | ||
width: 200, | ||
height: 100, | ||
fill: `linear-gradient(217deg, rgba(255,0,0,.8), rgba(255,0,0,0) 70.71%), | ||
linear-gradient(127deg, rgba(0,255,0,.8), rgba(0,255,0,0) 70.71%), | ||
linear-gradient(336deg, rgba(0,0,255,.8), rgba(0,0,255,0) 70.71%)`, | ||
}, | ||
}); | ||
|
||
// single radial gradient | ||
const rect3 = new Rect({ | ||
style: { | ||
x: 350, | ||
y: 50, | ||
width: 200, | ||
height: 100, | ||
fill: 'radial-gradient(circle at center, red, blue, green 100%)', | ||
}, | ||
}); | ||
|
||
// hard stop | ||
const rect4 = new Rect({ | ||
style: { | ||
x: 350, | ||
y: 250, | ||
width: 200, | ||
height: 100, | ||
fill: 'radial-gradient(red 50%, blue 50%)', | ||
}, | ||
}); | ||
|
||
const line1 = new Line({ | ||
style: { | ||
x1: 50, | ||
y1: 180, | ||
x2: 250, | ||
y2: 180, | ||
strokeWidth: 10, | ||
stroke: 'linear-gradient(0deg, blue, green 40%, red)', | ||
}, | ||
}); | ||
const line2 = new Line({ | ||
style: { | ||
x1: 350, | ||
y1: 180, | ||
x2: 550, | ||
y2: 180, | ||
strokeWidth: 10, | ||
stroke: 'radial-gradient(circle at center, red, blue, green 100%)', | ||
}, | ||
}); | ||
|
||
canvas.appendChild(line1); | ||
canvas.appendChild(line2); | ||
|
||
canvas.appendChild(rect1); | ||
canvas.appendChild(rect2); | ||
canvas.appendChild(rect3); | ||
canvas.appendChild(rect4); | ||
|
||
canvas.appendChild( | ||
new HTML({ | ||
style: { | ||
x: 100, | ||
y: 20, | ||
height: 30, | ||
width: 200, | ||
innerHTML: 'linear gradient', | ||
}, | ||
}), | ||
); | ||
canvas.appendChild( | ||
new HTML({ | ||
style: { | ||
x: 60, | ||
y: 220, | ||
height: 30, | ||
width: 200, | ||
innerHTML: 'multiple linear gradients', | ||
}, | ||
}), | ||
); | ||
canvas.appendChild( | ||
new HTML({ | ||
style: { | ||
x: 350, | ||
y: 20, | ||
height: 30, | ||
width: 200, | ||
innerHTML: 'radial gradient', | ||
}, | ||
}), | ||
); | ||
canvas.appendChild( | ||
new HTML({ | ||
style: { | ||
x: 350, | ||
y: 220, | ||
height: 30, | ||
width: 200, | ||
innerHTML: 'hard color stop', | ||
}, | ||
}), | ||
); | ||
} |
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
Oops, something went wrong.