Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.applet.Applet;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.util.Random;
- public class alcsnow extends Applet implements Runnable
- {
- Thread mainThread;
- Image offScrn;
- Graphics offGrph;
- Random rand;
- int stopFlag;
- long stopTime;
- int[] snowX;
- int[] snowY;
- int snows;
- int wind;
- int threadSleep;
- Dimension dim;
- Image[] gAlc;
- MediaTracker mt;
- public void init()
- {
- rand = new Random();
- dim = size();
- offScrn = createImage(dim.width, dim.height);
- offGrph = offScrn.getGraphics();
- String str = getParameter("snows");
- if (str == null) {
- snows = 100;
- } else {
- snows = Integer.valueOf(str).intValue();
- }
- if (snows > 500) {
- snows = 500;
- }
- str = getParameter("threadsleep");
- if (str == null) {
- threadSleep = 80;
- } else {
- threadSleep = Integer.valueOf(str).intValue();
- }
- if (threadSleep < 10) {
- threadSleep = 10;
- } else if (threadSleep > 1000) {
- threadSleep = 1000;
- }
- snowX = new int[snows];
- snowY = new int[snows];
- for (int i = 0; i < snows; i++) {
- snowX[i] =
- (rand.nextInt() % (dim.width / 2) + dim.width / 2);
- snowY[i] =
- (rand.nextInt() % (dim.height / 2) + dim.height / 2);
- }
- str = getParameter("graphic");
- if (str == null) {
- str = getParameter("graph");
- if (str == null) {
- str = getParameter("grph");
- if (str == null) {
- str = "tento1.gif";
- }
- }
- }
- mt = new MediaTracker(this);
- gAlc = new Image[1];
- gAlc[0] = getImage(getDocumentBase(), str);
- mt.addImage(gAlc[0], 0);
- try {
- mt.waitForID(0);
- } catch (InterruptedException localInterruptedException) {
- return;
- }
- stopFlag = 0;
- }
- public void start() {
- if (mainThread == null) {
- mainThread = new Thread(this);
- mainThread.start();
- }
- }
- public void stop() {
- mainThread = null;
- }
- public void run() {
- while (mainThread != null) {
- try {
- Thread.sleep(threadSleep);
- }
- catch (InterruptedException localInterruptedException) {
- return;
- }
- repaint();
- }
- }
- public void paint(Graphics paramGraphics)
- {
- offGrph.setColor(java.awt.Color.black);
- offGrph.fillRect(0, 0, dim.width, dim.height);
- offGrph.drawImage(gAlc[0], 0, 0, this);
- drawBackSnow();
- paramGraphics.drawImage(offScrn, 0, 0, null);
- }
- public void update(Graphics paramGraphics)
- {
- paint(paramGraphics);
- }
- public void drawBackSnow()
- {
- offGrph.setColor(java.awt.Color.white);
- for (int i = 0; i < snows; i++) {
- offGrph.fillRect(snowX[i], snowY[i], 1, 1);
- snowX[i] += rand.nextInt() % 2 + wind;
- snowY[i] += (rand.nextInt() % 6 + 5) / 5 + 1;
- if (snowX[i] >= dim.width) {
- snowX[i] = 0;
- }
- if (snowX[i] < 0) {
- snowX[i] = (dim.width - 1);
- }
- if ((snowY[i] >= dim.height) ||
- (snowY[i] < 0)) {
- snowX[i] = Math.abs(rand.nextInt() % dim.width);
- snowY[i] = 0;
- }
- }
- switch (rand.nextInt() % 100) {
- case -2:
- wind = -2;
- return;
- case -1:
- wind = -1;
- return;
- case 0:
- wind = 0;
- return;
- case 1:
- wind = 1;
- return;
- case 2:
- wind = 2; return;
- }
- }
- public alcsnow() {}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement