Edit... JSPWiki v2.2.28 |
Der Unterschied zwischen version 1 und version 1: [{Java2HtmlPlugin
import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.awt.image.*; public class WaveApplet extends Applet implements Runnable { int width; int height; int oldMouseY; int size; int swap; Image image; class Surface { float[] h; public Surface(int size) { h = new float[size]; } }; float[] v; Surface[] b; float[] s; public WaveApplet() { } public void init() { width = this.getWidth(); height = this.getHeight(); size = width; v = new float[size]; b = new Surface[] {new Surface(size), new Surface(size)}; s = new float[size]; this.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent arg0) { } public void mouseEntered(MouseEvent arg0) { oldMouseY = arg0.getY(); } public void mouseExited(MouseEvent arg0) { } public void mousePressed(MouseEvent arg0) { } public void mouseReleased(MouseEvent arg0) { }}); this.addMouseMotionListener(new MouseMotionListener() { public void mouseDragged(MouseEvent arg0) { } public void mouseMoved(MouseEvent arg0) { rotate(oldMouseY-arg0.getY()); oldMouseY = arg0.getY(); } }); this.requestFocus(); image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR); new Thread(this).start(); for (int i = 0; i < size; i++) { b[0].h[i] = 60; } for (int i = 0; i < size; i++) { b[1].h[i] = b[0].h[i]; } for (int i = 0; i < size; i++) { s[i] = (float) Math.sin((float)i*10/size)*(float)size/4+(float)size/3; } } public void rotate(int v) { v=v*3; for (int i = 0; i < size; i++) { s[i]+=v*((float)i-size/2)/size; } } public void run() { while (true) { if (getGraphics() != null) { process(); paint(getGraphics()); } } } private void process() { for (int j = 0; j < 2; j++) { Surface b0 = b[swap]; swap=(swap+1)%2; Surface b1 = b[swap]; float a = 0.05F; float b = 1F; float d = 0.003F; float g = 1F; for (int i = 0; i < size-1; i++) { if (b0.h[i]<0.1 && b0.h[i+1]<0.1) { v[i] = 0; continue; } // 1. Kräfte berechnen: Drücke float p0 = b0.h[i]+s[i]; float pr = b0.h[i+1]+s[i+1]; // 2. Geschwindigkeiten aus Kräften bilden float dv = (p0-pr)*a; // 3. Geschwindigkeiten aufsummieren v[i] += dv; // 4. Dämpfung v[i] -= v[i]*d; } for (int i = 0; i < size; i++) { b1.h[i] = b0.h[i]; } for (int i = 0; i < size-1; i++) { float dh = v[i]*b; b1.h[i ]-=dh; b1.h[i+1]+=dh; } } } public void paint(Graphics g) { Graphics vg = image.getGraphics(); vg.setColor(Color.BLACK); vg.fillRect(0, 0, width, height); int wd = width/size; Surface buffa = b[swap]; for (int i = 1; i < buffa.h.length-1; i++) { int y = (int) (buffa.h[i]+s[i]); int y1 = (int) s[i]; vg.setColor(Color.BLUE); vg.fillRect((i * wd), height-y, wd, y-y1); vg.setColor(Color.DARK_GRAY); vg.fillRect((i * wd), height-y1, wd, y1); } g.drawImage(image, 0, 0, width, height, this); } } }] Zurück zu Water Applet.Source Code, or zur History der Seite.
Earthdawn (R) ist ein eingetragenes Warenzeichen der FASA Corporation. Barsaive (TM) ist ein Warenzeichen der FASA Corporation. Copyright (c) 2015 by FASA Corporation. Copyright der deutschen Ausgabe (c) 2015 by Ulisses Spiele GmbH, Waldems. www.ulisses-spiele.de. Diese Webseite unterliegt keiner Abnahme oder Genehmigung durch Ulisses Spiele oder FASA.
|