Guest User

Untitled

a guest
May 21st, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. class polygon{
  2. public static void main(String args[]){
  3.     int count = StdIn.readInt ();
  4.     StdIn.readLine ();
  5.     char str [] = new char [ count ];
  6.     for ( int i = 0; i < count ; i ++){
  7.         str [i] = StdIn.readChar ();
  8.     }
  9.     StdIn.readLine ();
  10.     StdDraw.setPenRadius(.01);
  11.     StdDraw.setXscale(-count,count);
  12.     StdDraw.setYscale(-count,count);
  13.     double x1=0.0,y1=0.0;
  14.     int ausrichtung=0;
  15.     for (int k=0; k<count ; k++){
  16.         if (str[k]=='F'){
  17.             if ((ausrichtung)%4==0){
  18.                 StdDraw.line(x1,y1,x1+1,y1);
  19.                 x1=x1+1;
  20.                 y1=y1;
  21.             }
  22.             if ((ausrichtung)%4==1){
  23.                 StdDraw.line(x1,y1,x1,y1+1);
  24.                 x1=x1;
  25.                 y1=y1+1;
  26.             }
  27.             if ((ausrichtung)%4==2){
  28.                 StdDraw.line(x1,y1,x1-1,y1);
  29.                 x1=x1-1;
  30.                 y1=y1;
  31.             }
  32.             if ((ausrichtung)%4==3){
  33.                 StdDraw.line(x1,y1,x1,y1-1);
  34.                 x1=x1;
  35.                 y1=y1-1;
  36.             }
  37.         }
  38.         if (str[k]=='R'){
  39.             ausrichtung--;
  40.         }
  41.         if (str[k]=='L'){
  42.             ausrichtung++;
  43.         }
  44.     }              
  45. }
  46. }
Add Comment
Please, Sign In to add comment