📄 dynarule2.java
字号:
import java.applet.Applet;
import java.awt.*;
public class dynarule2 extends Applet implements Runnable {
float radius, centralPoint, arcAngle, dist, speed;
int xSize, ySize, numberOfPics;
Image img, bufferImage;
Color bgColor = null;
MediaTracker tracker = null;
Graphics bufferGraphics = null;
Thread thread = null;
float Pi2 = 6.283185F;
public dynarule2()
{
}
public void init()
{
tracker = new MediaTracker(this);
xSize = getSize().width;
ySize = getSize().height;
String s = getParameter("img");
img = getImage(getDocumentBase(), s);
tracker.addImage(img, 0);
s = getParameter("num");
numberOfPics = s != null ?
Integer.valueOf(s).intValue() : 1;
s = getParameter("dist");
dist = s != null ? Float.valueOf(s).floatValue() : 1.0F;
s = getParameter("speed");
speed = s != null ? Float.valueOf(s).floatValue() : Pi2 / 400F;
s = getParameter("bgcolor");
bgColor = s != null ?
new Color(Integer.valueOf(s, 16).intValue()) :
getBackground();
bufferImage = createImage(getSize().width, getSize().height);
bufferGraphics = bufferImage.getGraphics();
}
public void start()
{
try
{
showStatus("dynarule2: Loading image...");
tracker.waitForID(0);
showStatus("");
}
catch(InterruptedException _ex)
{
showStatus("dynarule2: Image loading interrupted");
return;
}
radius = (xSize - img.getWidth(this)) / 2;
centralPoint = radius;
arcAngle = 0.0F;
if(thread == null)
{
thread = new Thread(this);
thread.start();
}
}
public void stop()
{
if(thread != null)
{
thread.stop();
thread = null;
}
}
public void run()
{
do
{
arcAngle += speed;
if(arcAngle > Pi2)
arcAngle -= Pi2;
repaint();
try
{
Thread.sleep(15L);
}
catch(InterruptedException _ex) { }
}
while(true);
}
public void paint(Graphics g)
{
bufferGraphics.setColor(bgColor);
bufferGraphics.fillRect(0, 0, xSize, ySize);
float angle = arcAngle;
for(int i = 0; i < numberOfPics; i++)
{
int j = (int)(Math.sin(angle) * (double)radius
+ (double)centralPoint);
bufferGraphics.drawImage(img, j, 0, this);
angle += dist;
}
g.drawImage(bufferImage, 0, 0, this);
}
public final synchronized void update(Graphics g)
{
paint(g);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -