git-hash-art 0.10.1 → 0.12.0

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.
@@ -149,28 +149,27 @@ export const drawVesicaPiscis: DrawFunction = (ctx, size) => {
149
149
  export const drawTorus: DrawFunction = (ctx, size) => {
150
150
  const outerRadius = size / 2;
151
151
  const innerRadius = size / 4;
152
- const steps = 36;
152
+ // Adaptive step count: fewer segments for small shapes where detail isn't visible.
153
+ // 36×36 = 1296 segments at full size; at size < 60 we drop to 16×16 = 256.
154
+ const steps = size < 60 ? 16 : size < 150 ? 24 : 36;
155
+ const TWO_PI = Math.PI * 2;
156
+ const angleStep = TWO_PI / steps;
153
157
 
154
158
  ctx.beginPath();
155
159
  for (let i = 0; i < steps; i++) {
156
- const angle1 = (i / steps) * Math.PI * 2;
157
- // const angle2 = ((i + 1) / steps) * Math.PI * 2;
160
+ const angle1 = i * angleStep;
161
+ const cosA = Math.cos(angle1);
162
+ const sinA = Math.sin(angle1);
158
163
 
159
164
  for (let j = 0; j < steps; j++) {
160
- const phi1 = (j / steps) * Math.PI * 2;
161
- const phi2 = ((j + 1) / steps) * Math.PI * 2;
162
-
163
- const x1 =
164
- (outerRadius + innerRadius * Math.cos(phi1)) * Math.cos(angle1);
165
- const y1 =
166
- (outerRadius + innerRadius * Math.cos(phi1)) * Math.sin(angle1);
167
- const x2 =
168
- (outerRadius + innerRadius * Math.cos(phi2)) * Math.cos(angle1);
169
- const y2 =
170
- (outerRadius + innerRadius * Math.cos(phi2)) * Math.sin(angle1);
171
-
172
- ctx.moveTo(x1, y1);
173
- ctx.lineTo(x2, y2);
165
+ const phi1 = j * angleStep;
166
+ const phi2 = phi1 + angleStep;
167
+
168
+ const r1 = outerRadius + innerRadius * Math.cos(phi1);
169
+ const r2 = outerRadius + innerRadius * Math.cos(phi2);
170
+
171
+ ctx.moveTo(r1 * cosA, r1 * sinA);
172
+ ctx.lineTo(r2 * cosA, r2 * sinA);
174
173
  }
175
174
  }
176
175
  };