⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 leaf_d.java

📁 用java实现的
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;
import java.lang.*;

public class Leaf_D extends JApplet{

    boolean bq;
    int st, r = 255, 
            g = 255,
            b = 255;

    public static final double PI = Math.PI / 180;
                            
    public void init()
    {
        new Leaf_D(); 
    }

    public void frameSet()
    {
        Leaf_D shapes = new Leaf_D();
        JFrame fra = new JFrame("welcome");
        fra.getContentPane().add(shapes,BorderLayout.CENTER);
        fra.setSize(new Dimension(670,400));
        fra.setResizable(false);
        fra.setVisible(true);
         
    }

    public static void main(String args[])
    {
        new Leaf_D().frameSet(); 
    }

    /////////////////////////////////////////////////////////////

    public void paint(Graphics g)
    {   
     
        float D,K;
        g.setColor(Color.black);
        D=-10;
        K=40;
       for(int n=1;n<=3;n++)
       {
         for(int i=0 ;i<=100;i++)
        { 
           D=D+0.2f;
           K=K+0.2f;
           drawLeaf(g,200, 300, 50,270,K,D);
           g.clearRect(0, 0, 670, 400);   //删除屏幕
        }
        
        for(int j=0 ;j<=100;j++)
        { 
           D=D-0.2f;;
           drawLeaf(g,200, 300, 50,270,K,D);
           g.clearRect(0, 0, 670, 400);   //删除屏幕
        }
      }
      drawLeaf(g,200, 300, 50,270,K,D);
    }
   
    public void drawLeaf(Graphics g,double x,double y,
                        double L, double a,float B,float C)
    {
        
        double x1,x2,x1L,x2L,x2R,x1R,
               y1,y2,y1L,y2L,y2R,y1R;
       // float B = 50;
        //float C =9;
        float s1 = 3;
        float s2 = 3;
        float s3 = 1.2f;

        if(L > s1)
        {
            x2 = x + L * Math.cos(a * PI);
            y2 = y + L * Math.sin(a * PI);
            x2R = x2 + L / s2 * Math.cos((a + B) * PI);
            y2R = y2 + L / s2 * Math.sin((a + B) * PI);
            x2L = x2 + L / s2 * Math.cos((a - B) * PI);
            y2L = y2 + L / s2 * Math.sin((a - B) * PI);
  
            x1 = x + L / s2 * Math.cos(a * PI);
            y1 = y + L / s2 * Math.sin(a * PI);
            x1L = x1 + L / s2 * Math.cos((a - B) * PI);
            y1L = y1 + L / s2 * Math.sin((a - B) * PI);
            x1R = x1 + L / s2 * Math.cos((a + B) * PI);
            y1R = y1 + L / s2 * Math.sin((a + B) * PI);
             
            g.drawLine((int) x, (int) y, (int) x2, (int) y2);
            g.drawLine((int) x2, (int) y2, (int) x2R, (int) y2R);
            g.drawLine((int) x2, (int) y2, (int) x2L, (int) y2L);
            g.drawLine((int) x1, (int) y1, (int) x1L, (int) y1L); 
            g.drawLine((int) x1, (int) y1, (int) x1R, (int) y1R);

               
            drawLeaf(g, x2, y2, L / s3, a + C,B,C);
            drawLeaf(g, x2R, y2R, L / s2, a + B,B,C);
            drawLeaf(g, x2L, y2L, L / s2, a - B,B,C);
            drawLeaf(g, x1L, y1L, L / s2, a - B,B,C);
            drawLeaf(g, x1R, y1R, L / s2, a + B,B,C);   
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -