Advertisement
Guest User

Blatt2_Aufgabe1

a guest
Nov 13th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. /*
  2.     Aufgabe 1) Verschachtelte Schleifen - Optische Täuschung Ouchi Illusion
  3. */
  4. import java.awt.*;
  5.  
  6. public class Aufgabe1 {
  7.    
  8.     public static void main(String[] args) {
  9.         //TODO: Implementieren Sie hier Ihre Lösung für die Angabe
  10.  
  11.         StdDraw.setCanvasSize(512,512);
  12.         StdDraw.setXscale(0,512);
  13.         StdDraw.setYscale(0,512);
  14.  
  15.         int yCoordinate=512-2;
  16.         int xCoordinate=0;
  17.  
  18.         for (int i = 0; i < 128; i++) {
  19.             xCoordinate=0+8;
  20.             if (i%2!=0){xCoordinate+=16;}
  21.             for (int j = 0; j < 32; j++) {
  22.                 DrawSquare(xCoordinate, yCoordinate, false);
  23.                 xCoordinate += 32;
  24.             }
  25.             yCoordinate-=4;
  26.  
  27.         }
  28.  
  29.         DrawInsideSquare(128,384);
  30.         DrawInsideSquare(384,384);
  31.         DrawInsideSquare(128,128);
  32.         DrawInsideSquare(384,128);
  33.  
  34.        
  35.  
  36.     }
  37.  
  38.     private static void DrawSquare(int X, int Y, boolean rotation){
  39.         StdDraw.setPenColor(Color.black);
  40.         if(rotation==false){
  41.             StdDraw.filledRectangle(X,Y,8,2);
  42.         }
  43.         else {
  44.             StdDraw.filledRectangle(X,Y,2,8);
  45.         }
  46.     }
  47.  
  48.     private  static void DrawInsideSquare(int milldeX, int middleY){
  49.  
  50.         int X=milldeX;
  51.         int Y=middleY;
  52.         int smallX;//=X-64+2;
  53.         int smallY=(Y+64-8);//=+64-8;
  54.  
  55.         StdDraw.setPenColor(Color.white);
  56.         StdDraw.filledRectangle(milldeX,middleY,64,64);
  57.         StdDraw.setPenColor(Color.black);
  58.  
  59.         for (int i = 0; i <8 ; i++) {
  60.             smallX=X-64+2;
  61.             if (i%2!=0){smallX+=4;}
  62.             for (int j = 0; j < 16; j++) {
  63.                 DrawSquare(smallX, smallY, true);
  64.                 smallX += 8;
  65.             }
  66.             smallY-=16;
  67.  
  68.         }
  69.  
  70.  
  71.     }
  72.    
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement