// 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 ;
}