SHARE
TWEET

urmomkid123

nibbabich123 Jul 17th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.awt.*;
  2. import javax.swing.*;
  3. public class fibbbbbbb extends JPanel {
  4.    public static void main(String[] args) {
  5.        JFrame jf = new JFrame();
  6.        jf.setSize(800,600);
  7.        jf.add(new fibbbbbbb());
  8.        jf.setTitle("Snow Flake");
  9.        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  10.        jf.setVisible(true);
  11.     }
  12.     public fibbbbbbb(){
  13.         setBackground(Color.white);
  14.     }
  15.     public void drawSnow(Graphics g, int lev, int x1, int y1, int x5, int y5){
  16.         int deltaX, deltaY, x2, y2, x3, y3, x4, y4;
  17.         if(lev == 0){
  18.             g.drawLine(x1, y1, x5, y5);
  19.         }
  20.         else{
  21.             deltaX = x5 - x1;
  22.             deltaY = y5 - y1;
  23.             x2 = x1 + deltaX/3;
  24.             y2 = y1 + deltaY/3;
  25.             x3 = (int)(0.5*(x1+x5) + Math.sqrt(3) * (y1-y5)/6);
  26.             y3 = (int)(0.5*(y1+y5) + Math.sqrt(3) * (x1-x5)/6);
  27.             x4 = x1 + 2*deltaX/3;
  28.             y4 = y1 + 2*deltaY/3;
  29.            
  30.             drawSnow(g,lev-1,x1,y1,x2,y2);
  31.             drawSnow(g,lev-1,x2,y2,x3,y3);
  32.             drawSnow(g,lev-1,x3,y3,x4,y4);
  33.             drawSnow(g,lev-1,x4,y4,x5,y5);
  34.        }
  35.     }
  36.     public void paint(Graphics g){
  37.         super.paint(g);
  38.         int level = 4;
  39.         g.setColor(Color.BLACK);
  40.         drawSnow(g,level,20,280,280,280);
  41.         drawSnow(g,level,280,280,150,20);
  42.         drawSnow(g,level,150,20,20,280);
  43.     }
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top