Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Aufgabe 1) Verschachtelte Schleifen - Optische Täuschung Ouchi Illusion
- */
- import java.awt.*;
- public class Aufgabe1 {
- public static void main(String[] args) {
- //TODO: Implementieren Sie hier Ihre Lösung für die Angabe
- StdDraw.setCanvasSize(512,512);
- StdDraw.setXscale(0,512);
- StdDraw.setYscale(0,512);
- int yCoordinate=512-2;
- int xCoordinate=0;
- for (int i = 0; i < 128; i++) {
- xCoordinate=0+8;
- if (i%2!=0){xCoordinate+=16;}
- for (int j = 0; j < 32; j++) {
- DrawSquare(xCoordinate, yCoordinate, false);
- xCoordinate += 32;
- }
- yCoordinate-=4;
- }
- DrawInsideSquare(128,384);
- DrawInsideSquare(384,384);
- DrawInsideSquare(128,128);
- DrawInsideSquare(384,128);
- }
- private static void DrawSquare(int X, int Y, boolean rotation){
- StdDraw.setPenColor(Color.black);
- if(rotation==false){
- StdDraw.filledRectangle(X,Y,8,2);
- }
- else {
- StdDraw.filledRectangle(X,Y,2,8);
- }
- }
- private static void DrawInsideSquare(int milldeX, int middleY){
- int X=milldeX;
- int Y=middleY;
- int smallX;//=X-64+2;
- int smallY=(Y+64-8);//=+64-8;
- StdDraw.setPenColor(Color.white);
- StdDraw.filledRectangle(milldeX,middleY,64,64);
- StdDraw.setPenColor(Color.black);
- for (int i = 0; i <8 ; i++) {
- smallX=X-64+2;
- if (i%2!=0){smallX+=4;}
- for (int j = 0; j < 16; j++) {
- DrawSquare(smallX, smallY, true);
- smallX += 8;
- }
- smallY-=16;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement