📄 tree.java
字号:
/*
作者 连惠城
1999
*/
import java.awt.*;
import java.util.Stack;
import java.util.Vector;
import java.awt.event.*;
import java.lang.*;
public class MyFractal
extends java.applet.Applet
{
POT init =new POT(0.0,0.0);
int k;
static double r=5;
Graphics g;
public void paint(Graphics g)
{
g.setColor(Color.blue);
g.draw3DRect(10,10,195,20,false);
g.drawString("这是用随机分形画出来的橛叶!",28,24);
g.setColor(Color.yellow);
g.drawString("作者: 连惠城 ",500-100,400-15);
g.setColor(Color.red);
for( int i=0;i<500;i++)
{
k=0;
pifs(g,init);
}
}
void pifs(Graphics g,POT X)
{ POT newX=new POT(2.0,2.0);
double rand1;
float lon;
//repaint();
//g.drawString("aaa",100+10,200);
rand1=mrnd1(g,r);
k++;
if(rand1>=0.00 & rand1< 0.01) newX=tran1(X);
else if (rand1>=0.01 & rand1< 0.86) newX=tran2(X);
else if(rand1>=0.86 & rand1< 0.93) newX=tran3(X);
else if(rand1>=0.93 & rand1<=1.0) newX=tran4(X);
if(k>100)
Pixel(g,newX);
if(k>500)
return;
pifs(g,newX);
}
/*---------*/
POT tran1(POT X)
{
POT Temp =new POT(0.0,X.y*0.16);
return(Temp);
}
/*----------*/
POT tran2(POT X)
{POT Temp =new POT(0.85*X.x+0.04*X.y,-0.04*X.x+0.85*X.y+60);
return(Temp);
}
/*----------*/
POT tran3(POT X)
{POT Temp =new POT(0.2*X.x-0.26*X.y,0.23*X.x+0.22*X.y+70);
return(Temp);
}
/*----------*/
POT tran4(POT X)
{POT Temp =new POT(-0.15*X.x+0.28*X.y,+0.26*X.x+0.24*X.y+70);
return(Temp);
}
/*----------*/
/*-------*/
void Pixel(Graphics g,POT X)
{ int gX=(int)(X.x+250);
int gY=(int)(-X.y+390);
g.drawLine(gX,gY,gX,gY);
}
/*----------*/
double mrnd1(Graphics g, double r)
{
return(Math.random());
}
}
////end of class CLSFractal
//////////
class POT{
double x;
double y;
public POT(double x,double y)
{ this.x=x;
this.y=y;
return;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -