-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38b0227
commit 589f671
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,58 @@ | ||
const width = 125; | ||
const height = 125; | ||
|
||
// Set document dimensions | ||
setDocDimensions(width, height); | ||
|
||
// Store final lines | ||
const finalLines = []; | ||
|
||
// Parameters for the spiral galaxy | ||
const numArms = 5; // Number of spiral arms | ||
const numSegments = 50; // Number of segments per arm | ||
const centerX = width / 2; | ||
const centerY = height / 2; | ||
const maxRadius = 60; // Maximum radius of the spiral | ||
const rotationIncrement = 5; // Degree rotation per segment | ||
const arcLength = 15; // Length of each arc segment | ||
|
||
/** | ||
* Function to generate an arc | ||
* @param {number} cx - X-coordinate of the center | ||
* @param {number} cy - Y-coordinate of the center | ||
* @param {number} startAngle - Starting angle of the arc | ||
* @param {number} radius - Radius of the arc | ||
* @param {number} length - Length of the arc in degrees | ||
*/ | ||
function createArc(cx, cy, startAngle, radius, length) { | ||
const arc = []; | ||
const steps = 10; // Number of points to define the arc | ||
const angleStep = (length * Math.PI) / (180 * steps); | ||
|
||
for (let i = 0; i <= steps; i++) { | ||
const angle = (startAngle * Math.PI) / 180 + i * angleStep; | ||
const x = cx + radius * Math.cos(angle); | ||
const y = cy + radius * Math.sin(angle); | ||
arc.push([x, y]); | ||
} | ||
|
||
return arc; | ||
} | ||
|
||
// Generate spiral arms | ||
for (let arm = 0; arm < numArms; arm++) { | ||
let rotation = (arm * 360) / numArms; | ||
|
||
for (let segment = 0; segment < numSegments; segment++) { | ||
const radius = (segment / numSegments) * maxRadius; | ||
const arc = createArc(centerX, centerY, rotation, radius, arcLength); | ||
finalLines.push(arc); | ||
rotation += rotationIncrement; // Increment the angle for the next segment | ||
} | ||
} | ||
|
||
// Add a slight rotation to the entire design | ||
bt.rotate(finalLines, 30, [centerX, centerY]); | ||
|
||
// Draw the spiral galaxy | ||
drawLines(finalLines); |