📄 cloud.java
字号:
import java.applet.Applet;
import java.awt.*;
public class cloud extends Applet{
Image Buffer;
Graphics Context;
float Displace(float num){
float max=num/(float)(getSize().width+getSize().height)*3;
return ((float )Math.random()-0.5f)*max;
}
Color ComputeColor(float c){
float Red=0;
float Green=0;
float Blue=0;
if(c<0.5f){
Red=c*2;
}else{
Red=(1.0f-c)*2;
}
if(c>=0.3f&&c<0.8f){
Green=(c-0.3f)*2;
}else if(c<0.3f){
Green=(0.3f-c)*2;
}else{
Green=(1.3f-c)*2;
}
if(c>=0.5f){
Blue=(c-0.5f)*2;
}else{
Blue=(0.5f-c)*2;
}
return new Color(Red,Green,Blue);
}
void drawcloud(Graphics g,int width,int height){
float r1,r2,r3,r4;
r1=(float)Math.random();
r2=(float)Math.random();
r3=(float)Math.random();
r4=(float)Math.random();
Midpoint(g,0,0,width,height,r1,r2,r3,r4);
}
void Midpoint(Graphics g,float x,float y,float width,float height,float r1,float r2,float r3,float r4){
float M1,M2,M3,M4,Middle;
float newWidth=width/2;
float newHeight=height/2;
if(width>2||height>2){
Middle=(r1+r2+r3+r4)/4+Displace(newWidth+newHeight);
M1=(r1+r2)/2;
M2=(r2+r3)/2;
M3=(r3+r4)/2;
M4=(r4+r1)/2;
if(Middle<0){
Middle=0;
}else if(Middle>1.0f){
Middle=1.0f;
}
Midpoint(g,x,y,newWidth,newHeight,r1,M1,Middle,M4);
Midpoint(g,x+newWidth,y,newWidth,newHeight,M1,r2,M2,Middle);
Midpoint(g,x+newWidth,y+newHeight,newWidth,newHeight,Middle,M2,r3,M3);
Midpoint(g,x,y+newHeight,newWidth,newHeight,M4,Middle,M3,r4);
}else{
float c=(r1+r2+r3+r4)/4;
g.setColor(ComputeColor(c));
g.drawRect((int)x,(int)y,1,1);
}
}
public boolean mouseUp(Event evt,int x,int y){
drawcloud(Context,getSize().width,getSize().height);
repaint();
return false;
}
public void paint(Graphics g){
g.drawImage(Buffer,0,0,this);
}
public void init(){
Buffer=createImage(getSize().width,getSize().height);
Context=Buffer.getGraphics();
drawcloud(Context,getSize().width,getSize().height);
}
}
/*
* <applet code=cloud width=200 height=200>
* </applet>
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -