// initialise variables
squareXPosition = 150 ; // middle of applet window
squareYPosition = 150 ; // middle of applet window
width = 20 ; // side length of smallest square
g.setColor(Color.blue) ; // set colour
for (int count = 1 ; count <= 10 ; count++)
{
// draw rectangle
g.drawRect(squareXPosition,squareYPosition,width,width) ;
// reset rectangle parameters
width = width + 20 ;
squareXPosition = squareXPosition - 10 ;
squareYPosition = squareYPosition - 10 ;
}
// draw diagonals
squareXPosition = squareXPosition + 10 ; // undo last increment
squareYPosition = squareYPosition + 10 ;
width = width - 20 ;
g.setColor(Color.magenta) ;
// top left to bottom right
g.drawLine(squareXPosition, squareYPosition,
squareXPosition + width, squareYPosition + width) ;
// top right to bottom left
g.drawLine(squareXPosition + width, squareYPosition,
squareXPosition, squareYPosition + width) ;