Advertisement
Guest User

Untitled

a guest
Aug 29th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. import java.awt.Container;
  2. import java.awt.Graphics;
  3.  
  4. import javax.swing.JFrame;
  5. import javax.swing.JPanel;
  6.  
  7.  
  8. public class oppg3 extends JFrame {
  9.  
  10.     public oppg3(){
  11.  
  12.  
  13.         this.setSize(1200, 1200);
  14.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  15.         this.setLocationRelativeTo(null);
  16.  
  17.  
  18.         Container contentPane = getContentPane();
  19.         contentPane.add(new Panel2());
  20.         this.setVisible(true);
  21.     }
  22.  
  23.     class Panel2 extends JPanel{
  24.  
  25.         double p = 0.95;
  26.         int x0= 50;
  27.         int y0 = 50;
  28.         int xtemp = 0;
  29.         int ytemp = 0;
  30.  
  31.         int x1 = 350;                   int y1=50;
  32.         int x2=350;                     int y2=350;
  33.         int x3=50;                      int y3=350;
  34.  
  35.  
  36.         public void paintComponent(Graphics g){
  37.  
  38.             super.paintComponents(g);
  39.  
  40.  
  41.  
  42.             for (int n = 0; n < 3; n++) {
  43.  
  44.  
  45.                 for (int j = 0; j < 3; j++) {
  46.  
  47.                     //x0 =y0 = x3 = y1 = 350*j;
  48.                     //x1 = x2 = y2 = y3 = 350*j+350;
  49.                     p = 1-p;
  50.  
  51.                     x0 = x3 = 50+300*j;
  52.                     x1 = x2 = 350 +300 * j;
  53.  
  54.                     y0 = y1 = 50+300*n;
  55.                     y2 = y3 = 350 + 300*n;
  56.  
  57.  
  58.                     for (int i = 0; i < 45; i++) {
  59.  
  60.  
  61.                         xtemp = x0; ytemp = y0;
  62.  
  63.                         g.drawLine(x0, y0, x1, y1);
  64.                         g.drawLine(x1, y1, x2, y2);
  65.                         g.drawLine(x2, y2, x3, y3);
  66.                         g.drawLine(x3, y3, x0, y0);
  67.  
  68.                         x0 = (int)Math.round((x1-x0)*p+x0);
  69.                         y0 = (int) Math.round((y1-y0)*p+y0);
  70.                         x1 = (int)Math.round((x2-x1)*p+x1);
  71.                         y1 = (int)Math.round((y2-y1)*p+y1);
  72.                         x2 = (int)Math.round((x3-x2)*p+x2);
  73.                         y2 = (int)Math.round((y3-y2)*p+y2);
  74.                         x3 = (int)Math.round((xtemp -x3)*p+x3);
  75.                         y3 = (int)Math.round((ytemp-y3)*p+y3);
  76.                     }
  77.  
  78.                 }
  79.             }
  80.         }
  81.     }
  82.  
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement