Informatiker Board (http://www.informatikerboard.de/board/index.php)
- Themengebiete (http://www.informatikerboard.de/board/board.php?boardid=1)
--- Praktische Informatik (http://www.informatikerboard.de/board/board.php?boardid=6)
---- Algorithmen (http://www.informatikerboard.de/board/board.php?boardid=17)
----- Java Schachbrettmuster zeichnen mit zwei Schleifen? (http://www.informatikerboard.de/board/thread.php?threadid=1036)


Geschrieben von XHotSniperX am 14.10.2011 um 23:45:

  Java Schachbrettmuster zeichnen mit zwei Schleifen?

Ich soll in einem vorgegebenen Fenster (500*500) das gesamte Feld mit einem Schachbrettmuster zeichnen (Felder 20*20 gross).

Ich bin im Moment so weit gekommen, wie im Bild zu sehen und dem folgenden Code. Ist aber leider noch kein Schachbrettmuster.. könnt ihr mir bitte helfen?




=====================================================

package Praxis;

import Praxis.ch.unibas.informatik.cs101.ImageWindow;

public class BasicDrawingSchachbrett {

public static void main(String args[]) {
//creates a new instance of the ImageWindow Class
//with a viewable image area of 500x500 pixels
ImageWindow w = new ImageWindow(500,500);

//opens the corresponding window (makes it visible)
w.openWindow();

//colors the pixel at position 255,100 in the image
//with the rgb color 254 (red), 0 (green), 0 (blue)

// Add your code here

int y = 0;

while (y < 500) {


for (int x = 0; x < 500; x++) {

if (x % 20 == 0)

x += 20;


w.setPixel(x, y, 0, 0, 0);


w.setPixel(y, x, 0, 0, 0);


}
y ++;
}


//redraws the image on the screen so all changes
//become visible
w.redraw();
}
}


Forensoftware: Burning Board, entwickelt von WoltLab GmbH