modern-canvas 0.8.6 → 0.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -5125,20 +5125,17 @@ class GradientTexture extends Texture2D {
5125
5125
  const h = height;
5126
5126
  const cx = w / 2;
5127
5127
  const cy = h / 2;
5128
- const canAng = angle * Math.PI / 180;
5129
- const hypt = cy / Math.cos(canAng);
5130
- const fromTopRight = cx - Math.sqrt(hypt * hypt - cy * cy);
5131
- const diag = Math.sin(canAng) * fromTopRight;
5132
- const len = hypt + diag;
5133
- const x0 = cx + Math.cos(-Math.PI / 2 + canAng) * len;
5134
- const y0 = cy + Math.sin(-Math.PI / 2 + canAng) * len;
5135
- const x1 = cx + Math.cos(Math.PI / 2 + canAng) * len;
5136
- const y1 = cy + Math.sin(Math.PI / 2 + canAng) * len;
5137
- const gradient = ctx.createLinearGradient(x0, y0, x1, y1);
5138
- stops.forEach((stop) => {
5139
- gradient.addColorStop(stop.offset, stop.color);
5140
- });
5141
- ctx.fillStyle = gradient;
5128
+ const A = (angle + 90) * Math.PI / 180;
5129
+ const dx = Math.sin(A);
5130
+ const dy = -Math.cos(A);
5131
+ const L = Math.abs(w * Math.sin(A)) + Math.abs(h * Math.cos(A));
5132
+ const x0 = cx - dx * (L / 2);
5133
+ const y0 = cy - dy * (L / 2);
5134
+ const x1 = cx + dx * (L / 2);
5135
+ const y1 = cy + dy * (L / 2);
5136
+ const g = ctx.createLinearGradient(x0, y0, x1, y1);
5137
+ for (const s of stops) g.addColorStop(s.offset, s.color);
5138
+ ctx.fillStyle = g;
5142
5139
  ctx.fillRect(0, 0, w, h);
5143
5140
  const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
5144
5141
  return {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.8.6",
4
+ "version": "0.8.7",
5
5
  "packageManager": "pnpm@9.15.1",
6
6
  "description": "A JavaScript WebGL rendering engine.",
7
7
  "author": "wxm",