|
Bienvenue sur le serveur miageprojet2
De $1
/p[2]/span, reference to undefined name 'flickr'
Consulter les nouvelles
- package contours;
-
-
- import java.awt.*;
- import java.awt.event.*;
- import java.awt.image.*;
- import java.text.DecimalFormat;
- import java.text.NumberFormat;
- import javax.swing.JFrame;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
-
- public class Contour extends JFrameWithPreferences
- implements ItemListener, ActionListener, MouseMotionListener, MouseListener, Runnable {
-
- int Rc = 8, Lc, w, h, lbSize = 30, iV[], maxColor = 9,
- cWhite = maxColor, cBlack = maxColor + 1, hBar, hCol, nb[], delNb[];
- double V[], f[][], G[][], Vo, sV, Vp = -.95;
- Choice chRc;
- Label lbRc;
- Button btNew;
- Image img, imBar;
- IndexColorModel iColor;
- long generTime;
- boolean bBurn = false;
- Checkbox cbBurn;
-
-
- private static boolean runAsApplet = true;
- int parameterRc;
- double parameterVp;
- String parameterBgColor;
- boolean parameterBurn;
-
- private int currentY = 480 / 2;
-
- private double incY = 3;
-
- private int animationDelay = 100;
- static int WIDTH1 = 720;
- static int HEIGHT1 = 480;
- private Label vpLabel = new Label();
- private boolean flipFlap = false;
- private Boolean fullscreen = false;
-
- private int delayAvantPhase1;
- private int tempsAnimPhase1;
- private double debutPhase1;
- private double finPhase1;
- private int delayAvantPhase2;
- private int tempsAnimPhase2;
- private double debutPhase2;
- private double finPhase2;
- private int delayAvantPhase3;
- private int tempsAnimPhase3;
- private double debutPhase3;
- private double finPhase3;
-
- public void fullScreenMode(Window myWindow, int expectedWidth, int expectedHeight) {
- GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
- GraphicsDevice myDevice = ge.getScreenDevices()[0];
- DisplayMode[] displayModes = myDevice.getDisplayModes();
-
- for (int i = 0; i < displayModes.length; i++) {
- System.out.println("Display mode[" + i + "]: w = " +
- displayModes[i].getWidth() + " height = " +
- displayModes[i].getHeight() + "bits = " +
- displayModes[i].getBitDepth());
-
-
-
-
-
- if (displayModes[i].getWidth() == expectedWidth &&
- displayModes[i].getHeight() == expectedHeight) {
-
- try {
- myDevice.setFullScreenWindow(myWindow);
- myDevice.setDisplayMode(displayModes[i]);
- return;
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
-
-
-
-
-
-
- }
- }
-
- public Contour(String title) {
- super(title);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
-
- setPreferencesFileNames("preferences", "Contours.properties", "defaultContours.properties");
-
- readPreferences();
-
- loadPreferences();
-
- setLayout(new BorderLayout());
-
-
-
-
-
- ExitListenerSecurityManager sm;
- System.setSecurityManager(sm = new ExitListenerSecurityManager());
- sm.addSystemExitListener(this);
-
-
- if (fullscreen) {
- fullScreenMode(this, WIDTH1, HEIGHT1);
- }
- setVisible(true);
- init();
- addMouseListener(this);
-
-
- validate();
-
- new Thread(this).start();
- }
-
- public static void main(String[] args) {
-
- runAsApplet = false;
- Contour c = new Contour("Contour");
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
- private void drawRectangleForVp(Graphics g, int y) {
- g.setColor(Color.white);
- g.fillRect(w - 70, y - 15, 70, 30);
- g.setColor(Color.black);
- }
-
-
-
-
-
-
-
- private void loadPreferences() throws NumberFormatException, HeadlessException {
-
- try {
-
- int width = Integer.parseInt(preferences.getProperty("width"));
- int height = Integer.parseInt(preferences.getProperty("height"));
- currentY = height / 2;
-
- WIDTH1 = width;
- HEIGHT1 = height;
-
-
-
- String stringValue = null;
- Boolean value = null;
-
- if ((stringValue = preferences.getProperty("animationDelay")) != null) {
- animationDelay = Integer.parseInt(stringValue);
- }
-
-
- if ((stringValue = preferences.getProperty("Rc")) != null) {
- parameterRc = Integer.parseInt(stringValue);
- }
-
- if ((stringValue = preferences.getProperty("Vp")) != null) {
- parameterVp = Double.parseDouble(stringValue);
- }
-
- if ((stringValue = preferences.getProperty("Burn")) != null) {
- value = Boolean.valueOf(stringValue);
- parameterBurn = value;
- }
-
- if ((stringValue = preferences.getProperty("fullscreen")) != null) {
- value = Boolean.valueOf(stringValue);
- fullscreen = value;
- }
-
-
-
-
- if ((stringValue = preferences.getProperty("delayAvantPhase1")) != null) {
- delayAvantPhase1 = Integer.parseInt(stringValue);
- }
- if ((stringValue = preferences.getProperty("tempsAnimPhase1")) != null) {
- tempsAnimPhase1 = Integer.parseInt(stringValue);
- }
- if ((stringValue = preferences.getProperty("debutPhase1")) != null) {
- debutPhase1 = Double.parseDouble(stringValue);
- }
- if ((stringValue = preferences.getProperty("finPhase1")) != null) {
- finPhase1 = Double.parseDouble(stringValue);
- }
-
-
- if ((stringValue = preferences.getProperty("delayAvantPhase2")) != null) {
- delayAvantPhase2 = Integer.parseInt(stringValue);
- }
- if ((stringValue = preferences.getProperty("tempsAnimPhase2")) != null) {
- tempsAnimPhase2 = Integer.parseInt(stringValue);
- }
- if ((stringValue = preferences.getProperty("debutPhase2")) != null) {
- debutPhase2 = Double.parseDouble(stringValue);
- }
- if ((stringValue = preferences.getProperty("finPhase2")) != null) {
- finPhase2 = Double.parseDouble(stringValue);
- }
-
-
-
- if ((stringValue = preferences.getProperty("delayAvantPhase3")) != null) {
- delayAvantPhase3 = Integer.parseInt(stringValue);
- }
- if ((stringValue = preferences.getProperty("tempsAnimPhase3")) != null) {
- tempsAnimPhase3 = Integer.parseInt(stringValue);
- }
- if ((stringValue = preferences.getProperty("debutPhase3")) != null) {
- debutPhase3 = Double.parseDouble(stringValue);
- }
- if ((stringValue = preferences.getProperty("finPhase3")) != null) {
- finPhase3 = Double.parseDouble(stringValue);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
-
-
-
-
-
- @Override
- public void savePreferences() {
- System.out.println("dans pref redéfinie");
- super.savePreferences();
- }
-
- public void init() {
- w = getSize().width - 30;
- h = getSize().height - lbSize;
- nb = new int[w * h];
- delNb = new int[4];
- delNb[0] = 1;
- delNb[1] = -1;
- delNb[2] = w;
- delNb[3] = -w;
-
-
- Rc = parameterRc;
- Vp = parameterVp;
-
- V = new double[w * h];
- iV = new int[w * (h + 2)];
- f = new double[h + 64][w + 64];
- for (int i = 0; i < h + 64; i++) {
- for (int j = 0; j < w + 64; j++) {
- f[i][j] = 2 * Math.random() - 1;
-
- }
- }
- G = new double[32][32];
- Lc = 2 * Rc;
- double Rc2 = Rc * Rc;
- G[0][0] = 1;
- for (int i = 1; i < Lc; i++) {
- G[0][i] = Math.exp(-(i * i / Rc2));
- for (int j = 1; j <= i; j++) {
- G[j][i] = G[0][i] * G[0][j];
- }
- }
- byte rColor[] = new byte[maxColor + 2], bColor[] = new byte[maxColor + 2],
- gColor[] = new byte[maxColor + 2];
- int M = maxColor / 2;
- long M4 = (long) M * M * M * M;
- for (int i = 0; i < M; i++) {
- long dum = i;
- dum *= dum;
- dum *= dum;
- bColor[i] = gColor[M + i] = gColor[M - i] = rColor[maxColor - 1 - i] =
- (byte) (255 - (255 * dum) / M4);
- }
- gColor[M] = (byte) 220;
- rColor[cWhite] = gColor[cWhite] = bColor[cWhite] = (byte) 255;
- iColor = new IndexColorModel(8, maxColor + 2, rColor, gColor, bColor);
- hCol = h / maxColor;
- hBar = maxColor * hCol;
- int cBar[] = new int[20 * hBar], t = 0;
- for (int i = maxColor - 1; i >= 0; i--) {
- for (int j = 0; j < hCol; j++) {
- for (int k = 0; k < 20; k++) {
- cBar[t++] = i;
- }
- }
- }
- imBar = createImage(new MemoryImageSource(20, hBar, iColor, cBar, 0, 20));
-
- Panel pannelHaut = new Panel();
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- bBurn = parameterBurn;
-
-
-
-
-
-
-
- addMouseMotionListener(this);
- averaging();
- }
-
- public void destroy() {
- removeMouseMotionListener(this);
- }
-
- public void averaging() {
- generTime = System.currentTimeMillis();
- double Vmin = 100, Vmax = -100;
- sV = 0;
- int t = 0, w32 = w + 32;
- for (int i = 32; i < h + 32; i++) {
- for (int j = 32; j < w32; j++) {
- double s = G[0][0] * f[i][j];
- for (int m = 1; m < Lc; m++) {
-
-
-
-
-
-
-
-
-
-
-
-
- int im = i + m, i_m = i - m, jm = j + m, j_m = j - m;
- s += G[0][m] * (f[im][j] + f[i_m][j] + f[i][jm] + f[i][j_m]) +
- G[m][m] * (f[im][jm] + f[i_m][jm] + f[im][j_m] + f[i_m][j_m]);
- for (int n = 1; n < m; n++) {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- int in = i + n,
- i_n = i -
- n, jn = j + n, j_n = j - n;
- s += G[n][m] * (f[im][jn] + f[i_m][jn] + f[im][j_n] + f[i_m][j_n] +
- f[in][jm] + f[i_n][jm] + f[in][j_m] + f[i_n][j_m]);
- }
- }
- V[t++] = s;
- if (s > Vmax) {
- Vmax = s;
- }
- if (s < Vmin) {
- Vmin = s;
- }
- sV += s;
- }
- }
- sV /= w * h;
- Vo = Vmax;
- if (Vmax < -Vmin) {
- Vo = -Vmin;
- }
- makeImg();
- generTime = System.currentTimeMillis() - generTime;
- }
-
- public synchronized void makeImg() {
- double a = .5 * maxColor / Vo, tmp, VpVo = Vp * Vo;
- for (int i = 0; i < w * h; i++) {
- if ((tmp = V[i]) < VpVo) {
- iV[i + w] = cWhite;
- } else {
- iV[i + w] = (int) (a * (tmp + Vo));
- }
- }
- if (bBurn) {
- int lastNb = -1;
- for (int i = w; i < 2 * w; i++) {
- if (iV[i] == cWhite) {
- nb[++lastNb] = i;
- }
- }
- while (lastNb >= 0) {
- int n = nb[lastNb--];
- if (iV[n] == cWhite) {
- iV[n] = cBlack;
- for (int i = 0; i < 4; i++) {
- int t = n + delNb[i];
- if (iV[t] == cWhite) {
- nb[++lastNb] = t;
- }
- }
- }
- }
- }
- if (img != null) {
- img.flush();
- }
- img = createImage(new MemoryImageSource(w, h, iColor, iV, w, w));
- }
- NumberFormat nf = NumberFormat.getNumberInstance();
- DecimalFormat df = (DecimalFormat) nf;
- String output = "";
-
- @Override
- public void paint(Graphics g) {
-
- df.applyPattern("#.##");
- output = df.format(Vp);
-
-
-
-
-
-
- g.drawImage(img, 0, lbSize, this);
- g.drawImage(imBar, w, lbSize, this);
- g.setColor(Color.white);
- int y = lbSize + (int) (hBar * (1 - sV / Vo) / 2);
- g.drawLine(w + 10, y, w + 30, y);
- g.setColor(Color.black);
- y = lbSize + (int) (hBar * (1 - Vp) / 2);
- g.drawLine(w, y - 1, w + 15, y - 1);
- g.drawLine(w, y, w + 15, y);
- g.drawLine(w, y + 1, w + 15, y + 1);
- g.setColor(Color.black);
-
-
-
-
- if (flipFlap) {
- g.setColor(Color.WHITE);
- } else {
- g.setColor(Color.BLACK);
- }
- flipFlap = !flipFlap;
-
- if (y >= HEIGHT1 - 50) {
- drawRectangleForVp(g, HEIGHT1 - 50 - 3);
- g.drawString("Vp = " + output, w - 60, HEIGHT1 - 50);
- } else if (y <= (lbSize + 50)) {
- drawRectangleForVp(g, lbSize + 50 - 3);
- g.drawString("Vp = " + output, w - 60, lbSize + 50);
- } else {
- drawRectangleForVp(g, y);
- g.drawString("Vp = " + output, w - 60, y + 5);
- }
-
-
-
-
-
-
-
- }
-
- synchronized private void updateLabel(String output) {
-
- if (vpLabel != null) {
- vpLabel.setText("Vp = " + output + " T = " + generTime + " ms");
- }
- }
-
- public void mouseMoved(MouseEvent e) {
- }
-
- public void mouseDragged(MouseEvent e) {
- synchronized (new Object()) {
- if (e.getX() > w) {
- int y = e.getY() - lbSize;
- currentY = e.getY();
- Vp = 1 - y * 2.0 / hBar;
- if (Vp < -1) {
- Vp = -1;
- }
- if (Vp > 1) {
- Vp = 1;
- }
- makeImg();
-
-
- }
- }
- }
-
- public void itemStateChanged(ItemEvent e) {
- Object src = e.getSource();
- if (src == cbBurn) {
- bBurn = cbBurn.getState();
- makeImg();
- }
- if (src == chRc) {
- Rc = Integer.parseInt(chRc.getSelectedItem());
- Lc = 2 * Rc;
- double Rc2 = Rc * Rc;
- G[0][0] = 1;
- for (int i = 1; i < Lc; i++) {
- G[0][i] = Math.exp(-(i * i / Rc2));
- for (int j = 1; j <= i; j++) {
- G[j][i] = G[0][i] * G[0][j];
- }
- }
- averaging();
- }
- repaint();
- }
-
- private void newContour() {
- for (int i = 0; i < h + 64; i++) {
- for (int j = 0; j < w + 64; j++) {
- f[i][j] = 2 * Math.random() - 1;
- }
- }
- averaging();
- repaint();
- }
-
- public void actionPerformed(ActionEvent e) {
- newContour();
- }
-
- @Override
- public void update(Graphics g) {
- paint(g);
- }
- public static final int PHASE1 = 0;
- public static final int PHASE2 = 1;
- public static final int PHASE3 = 2;
- private int phase = PHASE1;
-
- private void setVp(double Vp) {
-
- currentY = (int) ((((-Vp + 1) * hBar) / 2.0) + lbSize);
-
- }
-
-
- private double getVpCourant(double VpDebut, double VpInterval,
- long tempsEcoule, long tempsAnimPhase2) {
-
- return VpDebut + (VpInterval * tempsEcoule) / (double) tempsAnimPhase2;
- }
-
- private int getYFromVp(double Vp) {
- return (int) ((((-Vp + 1) * hBar) / 2.0) + lbSize);
- }
-
- private void updateVp(double min, double max) {
-
- int y = currentY - lbSize;
- Vp = 1 - y * 2.0 / hBar;
- if (Vp < min) {
- Vp = min;
- incY = -incY;
- }
- if (Vp > max) {
- Vp = max;
- incY = -incY;
- }
-
- makeImg();
- repaint();
-
-
- currentY += incY;
- }
-
- public void run() {
- long tempsCourant = 0;
- long tempsDebut = 0;
- long tempsEcoule = 0;
- int y = 0;
- double VpCourant = 0;
- double intervalleVp = 0;
-
- if (getWidth() != 0) {
- while (true) {
- try {
-
- Thread.sleep(delayAvantPhase1 * 1000);
- intervalleVp = finPhase1 - debutPhase1;
- incY = -Math.abs(incY);
- setVp(debutPhase1);
- tempsDebut = System.currentTimeMillis();
- while (phase == PHASE1) {
- Thread.sleep(animationDelay);
-
-
- updateVp(debutPhase1, finPhase1);
-
- tempsCourant = System.currentTimeMillis();
- tempsEcoule = tempsCourant - tempsDebut;
-
-
- VpCourant = getVpCourant(debutPhase1, intervalleVp, tempsEcoule, tempsAnimPhase1 * 1000);
- currentY = getYFromVp(VpCourant);
-
- if ((tempsEcoule / 1000.0) > tempsAnimPhase1) {
-
- phase = PHASE2;
- }
- }
-
-
- Thread.sleep(delayAvantPhase2 * 1000);
- intervalleVp = finPhase2 - debutPhase2;
- tempsDebut = System.currentTimeMillis();
- setVp(debutPhase2);
- incY = -Math.abs(incY);
- while (phase == PHASE2) {
- Thread.sleep(animationDelay);
- updateVp(debutPhase2, finPhase2);
-
- tempsCourant = System.currentTimeMillis();
- tempsEcoule = tempsCourant - tempsDebut;
-
-
- VpCourant = getVpCourant(debutPhase2, intervalleVp, tempsEcoule, tempsAnimPhase2 * 1000);
- currentY = getYFromVp(VpCourant);
-
-
- if (tempsEcoule / 1000.0 > tempsAnimPhase2) {
- phase = PHASE3;
- }
- }
-
-
-
-
-
- Thread.sleep(delayAvantPhase3 * 1000);
- incY = -Math.abs(incY);
- setVp(debutPhase3);
- intervalleVp = finPhase3 - debutPhase3;
- tempsDebut = System.currentTimeMillis();
- while (phase == PHASE3) {
- Thread.sleep(animationDelay);
- updateVp(debutPhase3, finPhase3);
-
- tempsCourant = System.currentTimeMillis();
- tempsEcoule = tempsCourant - tempsDebut;
-
- VpCourant = getVpCourant(debutPhase3, intervalleVp, tempsEcoule, tempsAnimPhase3 * 1000);
- currentY = getYFromVp(VpCourant);
-
-
-
- if (tempsEcoule / 1000.0 > tempsAnimPhase3) {
- phase = PHASE1;
-
- newContour();
- }
- }
-
-
- } catch (InterruptedException ex) {
- Logger.getLogger(Contour.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- }
-
- public void mouseClicked(MouseEvent e) {
- }
-
- public void mousePressed(MouseEvent e) {
- currentY = e.getY();
- }
-
- public void mouseReleased(MouseEvent e) {
- }
-
- public void mouseEntered(MouseEvent e) {
- }
-
- public void mouseExited(MouseEvent e) {
- }
- }
package contours;
// Continuum percolation, Evgeny Demidov, 17 Feb 2002
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import javax.swing.JFrame;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Contour extends JFrameWithPreferences
implements ItemListener, ActionListener, MouseMotionListener, MouseListener, Runnable {
int Rc = 8, Lc, w, h, lbSize = 30, iV[], maxColor = 9,
cWhite = maxColor, cBlack = maxColor + 1, hBar, hCol, nb[], delNb[];
double V[], f[][], G[][], Vo, sV, Vp = -.95;
Choice chRc;
Label lbRc;
Button btNew;
Image img, imBar;
IndexColorModel iColor;
long generTime;
boolean bBurn = false;
Checkbox cbBurn;
// M.Buffa
private static boolean runAsApplet = true;
int parameterRc;
double parameterVp;
String parameterBgColor;
boolean parameterBurn;
// Variable y qui varie pendant l'animation
private int currentY = 480 / 2;
// incrément en y
private double incY = 3;
// durée entre chaque animation
private int animationDelay = 100;
static int WIDTH1 = 720;
static int HEIGHT1 = 480;
private Label vpLabel = new Label();
private boolean flipFlap = false;
private Boolean fullscreen = false;
// Parametres de l'animation
private int delayAvantPhase1;
private int tempsAnimPhase1;
private double debutPhase1;
private double finPhase1;
private int delayAvantPhase2;
private int tempsAnimPhase2;
private double debutPhase2;
private double finPhase2;
private int delayAvantPhase3;
private int tempsAnimPhase3;
private double debutPhase3;
private double finPhase3;
public void fullScreenMode(Window myWindow, int expectedWidth, int expectedHeight) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice myDevice = ge.getScreenDevices()[0];
DisplayMode[] displayModes = myDevice.getDisplayModes();
for (int i = 0; i < displayModes.length; i++) {
System.out.println("Display mode[" + i + "]: w = " +
displayModes[i].getWidth() + " height = " +
displayModes[i].getHeight() + "bits = " +
displayModes[i].getBitDepth());
// On va choisir le premier mode en expectedWidth, expectedHeight,
// les modes avec le plus de bits de profondeur sont proposés
// en premier par getDisplayModes
//DisplayMode oldDisplayMode = newDisplayMode;
if (displayModes[i].getWidth() == expectedWidth &&
displayModes[i].getHeight() == expectedHeight) {
// C'est bon !
try {
myDevice.setFullScreenWindow(myWindow);
myDevice.setDisplayMode(displayModes[i]);
return;
} catch (Exception e) {
e.printStackTrace();
}
}
/* finally {
}
myDevice.setDisplayMode(oldDisplayMode);
myDevice.setFullScreenWindow(null);
}
* */
}
}
public Contour(String title) {
super(title);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Gestion du fichier de préférences
setPreferencesFileNames("preferences", "Contours.properties", "defaultContours.properties");
// Load default preferences, inherited method
readPreferences();
// Load custom preferences
loadPreferences();
setLayout(new BorderLayout());
//setSize(WIDTH1, HEIGHT1);
// Use our own security manager, that can register listeners
// All JFrameWithPreferences are listeners, see contructor of this
// class
ExitListenerSecurityManager sm;
System.setSecurityManager(sm = new ExitListenerSecurityManager());
sm.addSystemExitListener(this);
if (fullscreen) {
fullScreenMode(this, WIDTH1, HEIGHT1);
}
setVisible(true);
init();
addMouseListener(this);
validate();
// on lance l'animation
new Thread(this).start();
}
public static void main(String[] args) {
runAsApplet = false;
Contour c = new Contour("Contour");
/*
JFrameContours f = new JFrameContours("Contours");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Read preferences
f.setPreferencesFileNames("preferences", "Contours.properties", "defaultContours.properties");
f.readPreferences();
// Use our own security manager, that can register listeners
// All JFrameWithPreferences qare listeners, see contructor of this
// class
ExitListenerSecurityManager sm;
System.setSecurityManager(sm = new ExitListenerSecurityManager());
sm.addSystemExitListener(f);
Contour applet = new Contour();
applet.emulateAppletParameters(args);
f.setSize(WIDTH1, HEIGHT1);
f.setLayout(new BorderLayout());
f.add(applet, BorderLayout.CENTER);
f.setVisible(true);
applet.init();
applet.addMouseListener(applet);
//applet.fullScreenMode(f, WIDTH1, HEIGHT1);
applet.start();
// on lance l'animation
new Thread(applet).start();
*/
}
private void drawRectangleForVp(Graphics g, int y) {
g.setColor(Color.white);
g.fillRect(w - 70, y - 15, 70, 30);
g.setColor(Color.black);
}
/**
* Load prefs
*
* @throws NumberFormatException
* @throws HeadlessException
*/
private void loadPreferences() throws NumberFormatException, HeadlessException {
try {
// Set window size
int width = Integer.parseInt(preferences.getProperty("width"));
int height = Integer.parseInt(preferences.getProperty("height"));
currentY = height / 2;
WIDTH1 = width;
HEIGHT1 = height;
//setSize(width, height);
// Read all preferences
String stringValue = null;
Boolean value = null;
if ((stringValue = preferences.getProperty("animationDelay")) != null) {
animationDelay = Integer.parseInt(stringValue);
}
if ((stringValue = preferences.getProperty("Rc")) != null) {
parameterRc = Integer.parseInt(stringValue);
}
if ((stringValue = preferences.getProperty("Vp")) != null) {
parameterVp = Double.parseDouble(stringValue);
}
if ((stringValue = preferences.getProperty("Burn")) != null) {
value = Boolean.valueOf(stringValue);
parameterBurn = value;
}
if ((stringValue = preferences.getProperty("fullscreen")) != null) {
value = Boolean.valueOf(stringValue);
fullscreen = value;
}
// Lecture des paramètres correspondants aux phases de l'animation
// Phase 1
if ((stringValue = preferences.getProperty("delayAvantPhase1")) != null) {
delayAvantPhase1 = Integer.parseInt(stringValue);
}
if ((stringValue = preferences.getProperty("tempsAnimPhase1")) != null) {
tempsAnimPhase1 = Integer.parseInt(stringValue);
}
if ((stringValue = preferences.getProperty("debutPhase1")) != null) {
debutPhase1 = Double.parseDouble(stringValue);
}
if ((stringValue = preferences.getProperty("finPhase1")) != null) {
finPhase1 = Double.parseDouble(stringValue);
}
// Phase 2
if ((stringValue = preferences.getProperty("delayAvantPhase2")) != null) {
delayAvantPhase2 = Integer.parseInt(stringValue);
}
if ((stringValue = preferences.getProperty("tempsAnimPhase2")) != null) {
tempsAnimPhase2 = Integer.parseInt(stringValue);
}
if ((stringValue = preferences.getProperty("debutPhase2")) != null) {
debutPhase2 = Double.parseDouble(stringValue);
}
if ((stringValue = preferences.getProperty("finPhase2")) != null) {
finPhase2 = Double.parseDouble(stringValue);
}
// Phase 3
if ((stringValue = preferences.getProperty("delayAvantPhase3")) != null) {
delayAvantPhase3 = Integer.parseInt(stringValue);
}
if ((stringValue = preferences.getProperty("tempsAnimPhase3")) != null) {
tempsAnimPhase3 = Integer.parseInt(stringValue);
}
if ((stringValue = preferences.getProperty("debutPhase3")) != null) {
debutPhase3 = Double.parseDouble(stringValue);
}
if ((stringValue = preferences.getProperty("finPhase3")) != null) {
finPhase3 = Double.parseDouble(stringValue);
}
/*
if ((stringValue = preferences.getProperty("redrawAllFrame")) != null) {
value = Boolean.valueOf(stringValue);
panelLyrics.setForceDrawFullImage(value.booleanValue());
cdgOptionsDialog.setRedrawFullImage(value.booleanValue());
}
if ((stringValue = preferences.getProperty("hardwareAcceleratedFullScreenModeSupported")) != null) {
value = Boolean.valueOf(stringValue);
hardwareAcceleratedFullScreenModeSupported = value.booleanValue();
setFullScreenModeOption();
}
int fsWidth = -1, fsHeight = -1, fsDepth = -1, fsFreq = -1;
if ((stringValue = preferences.getProperty("fsWidth")) != null) {
fsWidth = Integer.parseInt(stringValue);
}
if ((stringValue = preferences.getProperty("fsHeight")) != null) {
fsHeight = Integer.parseInt(stringValue);
}
if ((stringValue = preferences.getProperty("fsDepth")) != null) {
fsDepth = Integer.parseInt(stringValue);
}
if ((stringValue = preferences.getProperty("fsFreq")) != null) {
fsFreq = Integer.parseInt(stringValue);
}
if ((fsWidth != -1) && (fsHeight != -1) && (fsDepth != -1) && (fsFreq != -1)) {
System.out.println("Read prefs for fs mode, plug " + getName() + " : (" + fsWidth + "," + fsHeight + "," + fsDepth + "," + fsFreq + ")");
userDisplayMode = new DisplayMode(fsWidth, fsHeight, fsDepth, fsFreq);
}
* */
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* We redefine the inherited method so that visibility is always set to false before saving the
* preferences
*/
@Override
public void savePreferences() {
System.out.println("dans pref redéfinie");
super.savePreferences();
}
public void init() {
w = getSize().width - 30;
h = getSize().height - lbSize;
nb = new int[w * h];
delNb = new int[4];
delNb[0] = 1;
delNb[1] = -1;
delNb[2] = w;
delNb[3] = -w;
Rc = parameterRc;
Vp = parameterVp;
V = new double[w * h];
iV = new int[w * (h + 2)];
f = new double[h + 64][w + 64];
for (int i = 0; i < h + 64; i++) {
for (int j = 0; j < w + 64; j++) {
f[i][j] = 2 * Math.random() - 1;
// f[100][100] = 1;
}
}
G = new double[32][32];
Lc = 2 * Rc;
double Rc2 = Rc * Rc;
G[0][0] = 1;
for (int i = 1; i < Lc; i++) {
G[0][i] = Math.exp(-(i * i / Rc2));
for (int j = 1; j <= i; j++) {
G[j][i] = G[0][i] * G[0][j];
}
}
byte rColor[] = new byte[maxColor + 2], bColor[] = new byte[maxColor + 2],
gColor[] = new byte[maxColor + 2];
int M = maxColor / 2;
long M4 = (long) M * M * M * M;
for (int i = 0; i < M; i++) {
long dum = i;
dum *= dum;
dum *= dum;
bColor[i] = gColor[M + i] = gColor[M - i] = rColor[maxColor - 1 - i] =
(byte) (255 - (255 * dum) / M4);
}
gColor[M] = (byte) 220;
rColor[cWhite] = gColor[cWhite] = bColor[cWhite] = (byte) 255;
iColor = new IndexColorModel(8, maxColor + 2, rColor, gColor, bColor);
hCol = h / maxColor;
hBar = maxColor * hCol;
int cBar[] = new int[20 * hBar], t = 0;
for (int i = maxColor - 1; i >= 0; i--) {
for (int j = 0; j < hCol; j++) {
for (int k = 0; k < 20; k++) {
cBar[t++] = i;
}
}
}
imBar = createImage(new MemoryImageSource(20, hBar, iColor, cBar, 0, 20));
Panel pannelHaut = new Panel();
/*lbRc = new Label("Rc", Label.RIGHT);
pannelHaut.add(lbRc);
chRc = new Choice();
for ( int i = 0, r = 1; i < 5; i++) {
chRc.addItem(Integer.toString(r));
r *= 2;
}
chRc.select("" + Rc);
chRc.addItemListener(this);
pannelHaut.add(chRc);
btNew = new Button("New");
btNew.addActionListener(this);
pannelHaut.add(btNew);
*/
/*
pannelHaut.add(vpLabel);
vpLabel.setText("Vp = ");
*/
bBurn = parameterBurn;
/*
cbBurn = new Checkbox("Burn", bBurn);
pannelHaut.add(cbBurn);
cbBurn.addItemListener(this);
*/
//add(pannelHaut, BorderLayout.NORTH);
addMouseMotionListener(this);
averaging();
}
public void destroy() {
removeMouseMotionListener(this);
}
public void averaging() {
generTime = System.currentTimeMillis();
double Vmin = 100, Vmax = -100;
sV = 0;
int t = 0, w32 = w + 32;
for (int i = 32; i < h + 32; i++) {
for (int j = 32; j < w32; j++) {
double s = G[0][0] * f[i][j];
for (int m = 1; m < Lc; m++) {
int im = i + m, i_m = i - m, jm = j + m, j_m = j - m;
s += G[0][m] * (f[im][j] + f[i_m][j] + f[i][jm] + f[i][j_m]) +
G[m][m] * (f[im][jm] + f[i_m][jm] + f[im][j_m] + f[i_m][j_m]);
for (int n = 1; n < m; n++) {
int in = i + n,
i_n = i -
n, jn = j + n, j_n = j - n;
s += G[n][m] * (f[im][jn] + f[i_m][jn] + f[im][j_n] + f[i_m][j_n] +
f[in][jm] + f[i_n][jm] + f[in][j_m] + f[i_n][j_m]);
}
}
V[t++] = s;
if (s > Vmax) {
Vmax = s;
}
if (s < Vmin) {
Vmin = s;
}
sV += s;
}
}
sV /= w * h;
Vo = Vmax;
if (Vmax < -Vmin) {
Vo = -Vmin;
}
makeImg();
generTime = System.currentTimeMillis() - generTime;
}
public synchronized void makeImg() {
double a = .5 * maxColor / Vo, tmp, VpVo = Vp * Vo;
for (int i = 0; i < w * h; i++) {
if ((tmp = V[i]) < VpVo) {
iV[i + w] = cWhite;
} else {
iV[i + w] = (int) (a * (tmp + Vo));
}
}
if (bBurn) {
int lastNb = -1;
for (int i = w; i < 2 * w; i++) {
if (iV[i] == cWhite) {
nb[++lastNb] = i;
}
}
while (lastNb >= 0) {
int n = nb[lastNb--];
if (iV[n] == cWhite) {
iV[n] = cBlack;
for (int i = 0; i < 4; i++) {
int t = n + delNb[i];
if (iV[t] == cWhite) {
nb[++lastNb] = t;
}
}
}
}
}
if (img != null) {
img.flush();
}
img = createImage(new MemoryImageSource(w, h, iColor, iV, w, w));
}
NumberFormat nf = NumberFormat.getNumberInstance();
DecimalFormat df = (DecimalFormat) nf;
String output = "";
@Override
public void paint(Graphics g) {
// Pour l'affichage de Vp
df.applyPattern("#.##");
output = df.format(Vp);
//updateLabel(output);
g.drawImage(img, 0, lbSize, this);
g.drawImage(imBar, w, lbSize, this);
g.setColor(Color.white);
int y = lbSize + (int) (hBar * (1 - sV / Vo) / 2);
g.drawLine(w + 10, y, w + 30, y);
g.setColor(Color.black);
y = lbSize + (int) (hBar * (1 - Vp) / 2);
g.drawLine(w, y - 1, w + 15, y - 1);
g.drawLine(w, y, w + 15, y);
g.drawLine(w, y + 1, w + 15, y + 1);
g.setColor(Color.black);
if (flipFlap) {
g.setColor(Color.WHITE);
} else {
g.setColor(Color.BLACK);
}
flipFlap = !flipFlap;
if (y >= HEIGHT1 - 50) {
drawRectangleForVp(g, HEIGHT1 - 50 - 3);
g.drawString("Vp = " + output, w - 60, HEIGHT1 - 50);
} else if (y <= (lbSize + 50)) {
drawRectangleForVp(g, lbSize + 50 - 3);
g.drawString("Vp = " + output, w - 60, lbSize + 50);
} else {
drawRectangleForVp(g, y);
g.drawString("Vp = " + output, w - 60, y + 5);
}
// Affichage de Vp dnas un rectangle blanc en haut de la fenêtre
/* g.setColor(Color.white);
g.fillRect((getWidth() - 50) / 2, 0, 70, 50);
g.setColor(Color.black);
g.drawString("Vp = " + output, ((getWidth() - 50) / 2) + 10, 45);
*/
}
synchronized private void updateLabel(String output) {
if (vpLabel != null) {
vpLabel.setText("Vp = " + output + " T = " + generTime + " ms");
}
}
public void mouseMoved(MouseEvent e) {
}
public void mouseDragged(MouseEvent e) {
synchronized (new Object()) {
if (e.getX() > w) {
int y = e.getY() - lbSize;
currentY = e.getY();
Vp = 1 - y * 2.0 / hBar;
if (Vp < -1) {
Vp = -1;
}
if (Vp > 1) {
Vp = 1;
}
makeImg();
//repaint();
}
}
}
public void itemStateChanged(ItemEvent e) {
Object src = e.getSource();
if (src == cbBurn) {
bBurn = cbBurn.getState();
makeImg();
}
if (src == chRc) {
Rc = Integer.parseInt(chRc.getSelectedItem());
Lc = 2 * Rc;
double Rc2 = Rc * Rc;
G[0][0] = 1;
for (int i = 1; i < Lc; i++) {
G[0][i] = Math.exp(-(i * i / Rc2));
for (int j = 1; j <= i; j++) {
G[j][i] = G[0][i] * G[0][j];
}
}
averaging();
}
repaint();
}
private void newContour() {
for (int i = 0; i < h + 64; i++) {
for (int j = 0; j < w + 64; j++) {
f[i][j] = 2 * Math.random() - 1;
}
}
averaging();
repaint();
}
public void actionPerformed(ActionEvent e) {
newContour();
}
@Override
public void update(Graphics g) {
paint(g);
}
public static final int PHASE1 = 0;
public static final int PHASE2 = 1;
public static final int PHASE3 = 2;
private int phase = PHASE1;
private void setVp(double Vp) {
//-Vp = -1 +(currentY -lbSize)*2/hbar;
currentY = (int) ((((-Vp + 1) * hBar) / 2.0) + lbSize);
}
// Tous les temps sont en ms
private double getVpCourant(double VpDebut, double VpInterval,
long tempsEcoule, long tempsAnimPhase2) {
return VpDebut + (VpInterval * tempsEcoule) / (double) tempsAnimPhase2;
}
private int getYFromVp(double Vp) {
return (int) ((((-Vp + 1) * hBar) / 2.0) + lbSize);
}
private void updateVp(double min, double max) {
int y = currentY - lbSize;
Vp = 1 - y * 2.0 / hBar;
if (Vp < min) {
Vp = min;
incY = -incY;
}
if (Vp > max) {
Vp = max;
incY = -incY;
}
// On rafraichit l'image suivante
makeImg();
repaint();
// On incremente y
currentY += incY;
}
public void run() {
long tempsCourant = 0;
long tempsDebut = 0;
long tempsEcoule = 0;
int y = 0;
double VpCourant = 0;
double intervalleVp = 0;
if (getWidth() != 0) {
while (true) {
try {
// Phase 1
Thread.sleep(delayAvantPhase1 * 1000);
intervalleVp = finPhase1 - debutPhase1;
incY = -Math.abs(incY);
setVp(debutPhase1);
tempsDebut = System.currentTimeMillis();
while (phase == PHASE1) {
Thread.sleep(animationDelay);
//
updateVp(debutPhase1, finPhase1);
tempsCourant = System.currentTimeMillis();
tempsEcoule = tempsCourant - tempsDebut;
// On calcule le prochain Vp en fonction du temps écoulé
VpCourant = getVpCourant(debutPhase1, intervalleVp, tempsEcoule, tempsAnimPhase1 * 1000);
currentY = getYFromVp(VpCourant);
//System.out.println("Dans PHASE 1, tempsEcoule=" + tempsEcoule / 1000.0 + " tempsAnimPhase1 = " + tempsAnimPhase1);
if ((tempsEcoule / 1000.0) > tempsAnimPhase1) {
//System.out.println("ON CHANGE DE PHASE !");
phase = PHASE2;
}
}
// Phase 2
Thread.sleep(delayAvantPhase2 * 1000);
intervalleVp = finPhase2 - debutPhase2;
tempsDebut = System.currentTimeMillis();
setVp(debutPhase2);
incY = -Math.abs(incY);
while (phase == PHASE2) {
Thread.sleep(animationDelay);
updateVp(debutPhase2, finPhase2);
tempsCourant = System.currentTimeMillis();
tempsEcoule = tempsCourant - tempsDebut;
// On calcule le prochain Vp en fonction du temps écoulé
VpCourant = getVpCourant(debutPhase2, intervalleVp, tempsEcoule, tempsAnimPhase2 * 1000);
currentY = getYFromVp(VpCourant);
//System.out.println("Dans PHASE 2, tempsEcoule=" + tempsEcoule / 1000.0 + "tempsAnimPhase2 = " + tempsAnimPhase2);
if (tempsEcoule / 1000.0 > tempsAnimPhase2) {
phase = PHASE3;
}
}
//System.out.println("Après phase 2 on attend : " + delayApresPhase2 * 1000);
// Phase 3
Thread.sleep(delayAvantPhase3 * 1000);
incY = -Math.abs(incY);
setVp(debutPhase3);
intervalleVp = finPhase3 - debutPhase3;
tempsDebut = System.currentTimeMillis();
while (phase == PHASE3) {
Thread.sleep(animationDelay);
updateVp(debutPhase3, finPhase3);
tempsCourant = System.currentTimeMillis();
tempsEcoule = tempsCourant - tempsDebut;
// On calcule le prochain Vp en fonction du temps écoulé
VpCourant = getVpCourant(debutPhase3, intervalleVp, tempsEcoule, tempsAnimPhase3 * 1000);
currentY = getYFromVp(VpCourant);
//System.out.println("Dans PHASE 3, tempsEcoule=" + tempsEcoule / 1000.0 + "tempsAnimPhase3 = " + tempsAnimPhase3);
if (tempsEcoule / 1000.0 > tempsAnimPhase3) {
phase = PHASE1;
// On renouvelle le contourr
newContour();
}
}
//System.out.println("Après phase 3 on attend : " + delayApresPhase3 * 1000);
} catch (InterruptedException ex) {
Logger.getLogger(Contour.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
public void mouseClicked(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
currentY = e.getY();
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
}
Introduction
Ce nouveau wiki plus moderne que l'ancien http://miageprojet.unice.fr (toujours en ligne), devrait permettre de gérer beaucoup plus facilement les projets, cours, TP, etc... ayant cours à la miage. N'hésitez pas à vous inscrire et à commencer à créer des pages, à les éditer, etc.
User:MichelBuffa
|