Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Container;
- import java.awt.Graphics;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- public class oppg3 extends JFrame {
- public oppg3(){
- this.setSize(1200, 1200);
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.setLocationRelativeTo(null);
- Container contentPane = getContentPane();
- contentPane.add(new Panel2());
- this.setVisible(true);
- }
- class Panel2 extends JPanel{
- double p = 0.95;
- int x0= 50;
- int y0 = 50;
- int xtemp = 0;
- int ytemp = 0;
- int x1 = 350; int y1=50;
- int x2=350; int y2=350;
- int x3=50; int y3=350;
- public void paintComponent(Graphics g){
- super.paintComponents(g);
- for (int n = 0; n < 3; n++) {
- for (int j = 0; j < 3; j++) {
- //x0 =y0 = x3 = y1 = 350*j;
- //x1 = x2 = y2 = y3 = 350*j+350;
- p = 1-p;
- x0 = x3 = 50+300*j;
- x1 = x2 = 350 +300 * j;
- y0 = y1 = 50+300*n;
- y2 = y3 = 350 + 300*n;
- for (int i = 0; i < 45; i++) {
- xtemp = x0; ytemp = y0;
- g.drawLine(x0, y0, x1, y1);
- g.drawLine(x1, y1, x2, y2);
- g.drawLine(x2, y2, x3, y3);
- g.drawLine(x3, y3, x0, y0);
- x0 = (int)Math.round((x1-x0)*p+x0);
- y0 = (int) Math.round((y1-y0)*p+y0);
- x1 = (int)Math.round((x2-x1)*p+x1);
- y1 = (int)Math.round((y2-y1)*p+y1);
- x2 = (int)Math.round((x3-x2)*p+x2);
- y2 = (int)Math.round((y3-y2)*p+y2);
- x3 = (int)Math.round((xtemp -x3)*p+x3);
- y3 = (int)Math.round((ytemp-y3)*p+y3);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement