AP Computer Science --- Haas --- Spiral

Write a Java Applet which draws a spiral, much like the one below. Your spiral will be created by drawing a series of lines. You must use a for loop or while loop to create the drawing.

Recall the basics of drawing using Java Applets. Run the following example:


/**
 *  This Applet example draws a line between two points.
 *  To draw a spiral you can modify this code to draw a series of lines.
 *  Of course you will need some kind of loop.
 */ 
import javax.swing.JApplet;
import java.awt.*; // import Graphics, Graphics2D, and Rectangle
public class Spiral extends JApplet
{
  public void paint (Graphics g)
    {
    setBackground(Color.blue);
    
    g.setColor(Color.black); 
    
    // recall from last year, this is how you draw a line!
    int x = 250;
    int y = 250;
    int i = 50;
    g.drawLine(x,y,x+i,y+i);  //(from x, from y, to x+i, to y+i) 

  } // end of paint
} // end of Spiral


After you finish the basic spiral above try to produce another spiral of you own creation. Below is an example of a triangular spiral. Your spiral does not have to look like the one below. Make up your own!