Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

void spiral( centerX, centerY, maxRadius, spinRate, numSegments) This will draw

ID: 3879274 • Letter: V

Question

void spiral( centerX, centerY, maxRadius, spinRate, numSegments)

This will draw a spiral centered at (x, y). The maxRadius determines how large the spiral can be. A low spin rate will be basically a line out from the center. A high spin rate will have more circles. The spiral will be consist of many line segments. The numSegments parameters says how many to use to draw it.

Basically we're using a drawline method with a drawing library where StdDraw.drawline(x,y,x1,y1) draws a line at those coordinates. We need to create a spiral drawing method with the parameters above.

Explanation / Answer

import java.awt.Graphics;
import javax.swing.JPanel;
import javax.swing.JFrame;

public class CircSpiral extends JPanel {
   public void paintComponent(Graphics g) {
      int x = 100;
      int y = 120;
      int width = 40;
      int height = 60;
      int startAngle = 20;
      int arcAngle = 80;
      for (int i = 0; i < 5; i++) {
         g.drawArc(x, y, width, height, startAngle, arcAngle);
         g.drawArc(x + 10, y + 10, width, height, startAngle + 10, arcAngle);
         x = x + 5;
         y = y + 5;
         startAngle = startAngle - 10;
         arcAngle = arcAngle + 10;
      }
   }

   public static void main(String[] args) {
      CircSpiral panel = new CircSpiral();
      JFrame application = new JFrame();
      application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      application.add(panel);
      application.setSize(300, 300);
      application.setVisible(true);
   }
}