Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JFrame;
- import java.awt.Graphics;
- import javax.swing.JPanel;
- import java.awt.Color;
- public class fraktal extends JPanel{
- public fraktal(){
- super();
- }
- public boolean drawQuader(Graphics g, int x, int y, int width, int height, int n){
- if ( n == 4){g.setColor(Color.RED);}
- if ( n == 3){g.setColor(Color.BLUE);}
- if ( n == 2){g.setColor(Color.CYAN);}
- if ( n == 1){g.setColor(Color.ORANGE);}
- if ( n == 0){g.setColor(Color.PINK);}
- g.fillRect(x,y,width,height);
- if (n == 0){
- return true;
- }
- else {
- drawQuader(g,x-width/4,y-height/4,width/2,height/2,n-1);
- drawQuader(g,(x+width)-width/4,(y+height)-width/4,width/2,height/2,n-1);
- drawQuader(g,(x+width)-width/4,y-width/4, width/2, height/2, n-1);
- drawQuader(g,x-width/4,(y+width)-width/4, width/2, height/2, n-1);
- return true;
- }
- }
- public void paintComponent(Graphics g){
- super.paintComponent(g);
- drawQuader(g, 150, 150, 250, 250, 4);
- }
- public static void main(String[] args) {
- fraktal panel = new fraktal();
- JFrame application = new JFrame();
- application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- application.add(panel);
- application.setSize(600, 600);
- application.setVisible(true);
- application.setTitle("Fraktal");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment