FileDocCategorySizeDatePackage
spiral.javaAPI DocExample2250Tue Aug 08 17:19:28 BST 2000None

spiral

public class spiral extends Applet

Fields Summary
private int
lengthIncrement
private int
length
private int
startx
private int
starty
private int
endx
private int
endy
Constructors Summary
Methods Summary
public voidpaint(java.awt.Graphics g)

		// the end y position of the line

	   		// this does the drawing
	
		length = lengthIncrement ;	// initialise length
		startx = 150 ;					// initialise position to centre of
		starty = 150 ;					// applet window
		
		g.setColor(Color.blue) ;	// set the pen colour
		
		// start drawing lines, 4 per iteration
		for ( int count = 1 ; count <= 40  ; count += 4)
		{
			// start by drawing a vertical line upwards
			endx = startx ;			// set the end coords of the line
			endy = starty - length ;
			g.drawLine(startx,starty,endx,endy) ; // draw the line
			length = length + lengthIncrement ; // update length
			startx = endx ;	// reset the start of the line
			starty = endy ;
			
			// then draw a horizontal line to right
			endx = startx + length ;	// set the end coords of the line
			endy = starty ;
			g.drawLine(startx,starty,endx,endy) ; // draw the line
			length = length + lengthIncrement ;	// update length
			startx = endx ;	// reset the start of the line
			starty = endy ;
			
			// then draw a vertical line downwards 
			endx = startx ;	// set the end coords of the line
			endy = starty + length ;
			g.drawLine(startx,starty,endx,endy) ; // draw the line
			length = length + lengthIncrement ;   	// update length
			startx = endx ;	// reset the start of the line
			starty = endy ;
			
			// finally draw a horizontal line to left
			endx = startx - length ; // set the end coords of the line
			endy = starty ;
			g.drawLine(startx,starty,endx,endy) ;  // draw the line
			length = length + lengthIncrement ;	// update length
			startx = endx ;	// reset the start of the line
			starty = endy ;
		}