Advertisement
Guest User

Drawing Squares

a guest
Apr 7th, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. package cz.czechitas.beginnerjava.homework.practice;
  2.  
  3. import org.teachingextensions.logo.Turtle;
  4. import org.teachingextensions.logo.utils.ColorUtils.PenColor;
  5.  
  6. public class SquareShape {
  7.    
  8.     public static void main(String[] args) {
  9.         SquareShape myApp = new SquareShape();
  10.         myApp.run();
  11.     }
  12.    
  13.     Turtle turtle = new Turtle();
  14.    
  15.    
  16.     public void run() {
  17.         turtle.show();
  18.         turtle.setSpeed(8);
  19.         turtle.setPenColor(PenColor.magenta);
  20.        
  21.         turtle.setX(300);
  22.         turtle.setY(220);
  23.         turtle.turn(45);
  24.        
  25.         int lenght;
  26.         lenght = 15;
  27.        
  28.             int j;
  29.             for (j = 0; j < 40; j++) {
  30.            
  31.             drawSquares(lenght);
  32.            
  33.             ///draw
  34.             lenght = lenght + 10;      
  35.            
  36.             }
  37.     }
  38.    
  39.     public void drawSquares(int side) {
  40.         int i;
  41.         for (i = 0; i < 4; i++) {
  42.         turtle.move(side);
  43.         turtle.turn(90);
  44.         }
  45.        
  46.         turtle.setPenUp();
  47.         turtle.move(-5);
  48.         turtle.turn(-90);
  49.         turtle.move(5);
  50.         turtle.turn(90);
  51.         turtle.setPenDown();
  52.        
  53.     }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement