Dot burst

Dot version of the sunburst

Log in to post a comment.

// Adjustable parameters
const dotsPerLine = 8; // min=3 max=15 step=1 Number of dots per radial line
const lineCount = 180; // min=60 max=360 step=10 Number of radiating lines
const innerRadius = 100; // min=30 max=150 step=5 Radius of the inner circle
const outerRadius = 300; // min=150 max=400 step=10 Maximum radius
const offsetAngle = 0.25; // min=0 max=1 step=0.05 Offset angle between rows
const dotSize = 2; // min=1 max=5 step=0.5 Size of dots
const zoomOut = 1; // min=0.2 max=2 step=0.1 Scale factor (smaller values zoom out)

// Create a turtle
const turtle = new Turtle();
Canvas.setpenopacity(1); // Set full opacity for solid black dots

// Position variables
const centerX = 0;
const centerY = 0;
const angleIncrement = 2 * Math.PI / lineCount;

// Function to calculate non-linear spacing between dots
function getDotRadius(dotIndex) {
  // Use a quadratic function to make inner dots closer together
  const t = dotIndex / dotsPerLine;
  const scaleFactor = t * t;
  // Apply zoom factor to the radius
  return (innerRadius + scaleFactor * (outerRadius - innerRadius)) * zoomOut;
}

// State tracking
let currentLine = 0;
let currentDot = 0;

// Custom function to draw a dot that appears solid
function drawDot(size) {
  // Since Turtletoy doesn't have native filled circles,
  // we'll create the appearance of a solid dot using very small circles
  
  // Save the current position
  const x = turtle.xcor();
  const y = turtle.ycor();
  
  // Apply zoom factor to the dot size
  const scaledSize = size * zoomOut;
  
  // Draw several concentric circles with decreasing radius
  // This creates a more filled appearance
  const iterations = 3;
  const steps = 18; // More steps for smoother appearance
  
  turtle.pendown();
  
  // Main dot
  turtle.right(90); // Point right to start circle
  turtle.circle(scaledSize/2, 360, steps); // Outer circle
  
  // Draw smaller circles inside to make it appear more solid
  for (let i = 1; i <= iterations; i++) {
    const smallerRadius = (scaledSize/2) * (1 - i/iterations);
    turtle.circle(smallerRadius, 360, steps);
  }
  
  turtle.left(90); // Restore original heading
  
  // Return to the original position and ensure pen is up
  turtle.penup();
  turtle.goto(x, y);
}

function walk(i) {
  // Check if drawing is complete
  if (currentLine >= lineCount) {
    return false;
  }
  
  // Calculate angle with offset for this dot row
  const rowOffset = currentDot * offsetAngle * angleIncrement;
  const angle = currentLine * angleIncrement + rowOffset;
  
  // Calculate radius for this dot
  const dotRadius = getDotRadius(currentDot);
  
  // Move to position
  turtle.penup();
  const x = centerX + Math.cos(angle) * dotRadius;
  const y = centerY + Math.sin(angle) * dotRadius;
  turtle.goto(x, y);
  
  // Draw the dot
  drawDot(dotSize);
  
  // Move to next dot
  currentDot++;
  
  // If we've completed all dots in this line, move to next line
  if (currentDot >= dotsPerLine) {
    currentDot = 0;
    currentLine++;
  }
  
  // Continue drawing
  return true;
}