Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. import javax.swing.JFrame;
  2. import java.awt.Graphics;
  3. import javax.swing.JPanel;
  4. import java.awt.Color;
  5.  
  6.  
  7. public class fraktal extends JPanel{
  8.    
  9.     public fraktal(){
  10.         super();
  11.     }
  12.    
  13.    
  14.     public boolean drawQuader(Graphics g, int x, int y, int width, int height, int n){
  15.        
  16.         if ( n == 4){g.setColor(Color.RED);}
  17.         if ( n == 3){g.setColor(Color.BLUE);}
  18.         if ( n == 2){g.setColor(Color.CYAN);}
  19.         if ( n == 1){g.setColor(Color.ORANGE);}
  20.         if ( n == 0){g.setColor(Color.PINK);}
  21.        
  22.         g.fillRect(x,y,width,height);
  23.        
  24.         if (n == 0){
  25.             return true;
  26.             }
  27.         else {
  28.             drawQuader(g,x-width/4,y-height/4,width/2,height/2,n-1);
  29.             drawQuader(g,(x+width)-width/4,(y+height)-width/4,width/2,height/2,n-1);
  30.             drawQuader(g,(x+width)-width/4,y-width/4, width/2, height/2, n-1);
  31.             drawQuader(g,x-width/4,(y+width)-width/4, width/2, height/2, n-1);
  32.             return true;
  33.         }
  34.        
  35.     }
  36.    
  37.     public void paintComponent(Graphics g){
  38.         super.paintComponent(g);
  39.         drawQuader(g, 150, 150, 250, 250, 4);
  40.        
  41.     }
  42.     public static void main(String[] args) {
  43.         fraktal panel = new fraktal();             
  44.         JFrame application = new JFrame();
  45.        
  46.        
  47.         application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  48.         application.add(panel);                    
  49.         application.setSize(600, 600);
  50.         application.setVisible(true);                          
  51.         application.setTitle("Fraktal");
  52.  
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement