Disegno per NXT classe 3E

Realizzare il disegno seguente; i rettangoli devono avere coordinate (0,0) – (4,4) – (8,8) – etc.

Rettangoli

import javax.microedition.lcdui.Graphics;

import lejos.nxt.Button;

public class Disegna {

	public static void main(String[] args) {
		Graphics g = new Graphics();

		int w = g.getWidth() - 1;
		int h = g.getHeight() - 1;

		for (int x = 0; x < h; x += 4) {
			// lato orizzontale superiore
			g.drawLine(x, x, w - x, x);
			// lato orizzontale inferiore
			g.drawLine(x, h - x, w - x, h - x);
			// lato verticale sinistro
			g.drawLine(x, x, x, h - x);
			// lato verticale destro
			g.drawLine(w - x, x, w - x, h - x);
		}

		Button.ESCAPE.waitForPressAndRelease();
	}
}