Bienvenue sur le serveur miageprojet2

De $1

Table des matières
  1. 1. Introduction
  2. 2. Sections intéressantes

Version de 08:48, 21 Mai 2025

cette version.

Revenir à liste des archives.

Voir la version actuelle

/p[2]/span, reference to undefined name 'flickr'

/p[3]/span, function 'Calendar' failed with response:

doc

Consulter les nouvelles

  1. package contours;  
  2.   
  3. // Continuum percolation,  Evgeny Demidov, 17 Feb 2002  
  4. import java.awt.*;  
  5. import java.awt.event.*;  
  6. import java.awt.image.*;  
  7. import java.text.DecimalFormat;  
  8. import java.text.NumberFormat;  
  9. import javax.swing.JFrame;  
  10. import java.util.logging.Level;  
  11. import java.util.logging.Logger;  
  12. import javax.swing.JLabel;  
  13. import javax.swing.JPanel;  
  14.   
  15. public class Contour extends JFrameWithPreferences  
  16.         implements ItemListener, ActionListener, MouseMotionListener, MouseListener, Runnable {  
  17.   
  18.     int Rc = 8, Lc, w, h, lbSize = 30, iV[], maxColor = 9,  
  19.             cWhite = maxColor, cBlack = maxColor + 1, hBar, hCol, nb[], delNb[];  
  20.     double V[], f[][], G[][], Vo, sV, Vp = -.95;  
  21.     Choice chRc;  
  22.     Label lbRc;  
  23.     Button btNew;  
  24.     Image img, imBar;  
  25.     IndexColorModel iColor;  
  26.     long generTime;  
  27.     boolean bBurn = false;  
  28.     Checkbox cbBurn;  
  29.   
  30.     // M.Buffa  
  31.     private static boolean runAsApplet = true;  
  32.     int parameterRc;  
  33.     double parameterVp;  
  34.     String parameterBgColor;  
  35.     boolean parameterBurn;  
  36.     // Variable y qui varie pendant l'animation  
  37.     private int currentY = 480 / 2;  
  38.     // incrément en y  
  39.     private double incY = 3;  
  40.     // durée entre chaque animation  
  41.     private int animationDelay = 100;  
  42.     static int WIDTH1 = 720;  
  43.     static int HEIGHT1 = 480;  
  44.     private Label vpLabel = new Label();  
  45.     private boolean flipFlap = false;  
  46.     private Boolean fullscreen = false;  
  47.     // Parametres de l'animation  
  48.     private int delayAvantPhase1;  
  49.     private int tempsAnimPhase1;  
  50.     private double debutPhase1;  
  51.     private double finPhase1;  
  52.     private int delayAvantPhase2;  
  53.     private int tempsAnimPhase2;  
  54.     private double debutPhase2;  
  55.     private double finPhase2;  
  56.     private int delayAvantPhase3;  
  57.     private int tempsAnimPhase3;  
  58.     private double debutPhase3;  
  59.     private double finPhase3;  
  60.   
  61.     public void fullScreenMode(Window myWindow, int expectedWidth, int expectedHeight) {  
  62.         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();  
  63.         GraphicsDevice myDevice = ge.getScreenDevices()[0];  
  64.         DisplayMode[] displayModes = myDevice.getDisplayModes();  
  65.   
  66.         for (int i = 0; i < displayModes.length; i++) {  
  67.             System.out.println("Display mode[" + i + "]: w = " +  
  68.                     displayModes[i].getWidth() + " height = " +  
  69.                     displayModes[i].getHeight() + "bits = " +  
  70.                     displayModes[i].getBitDepth());  
  71.             // On va choisir le premier mode en expectedWidth, expectedHeight,   
  72.             // les modes avec le plus de bits de profondeur sont proposés   
  73.             // en premier par getDisplayModes  
  74.   
  75.             //DisplayMode oldDisplayMode = newDisplayMode;  
  76.             if (displayModes[i].getWidth() == expectedWidth &&  
  77.                     displayModes[i].getHeight() == expectedHeight) {  
  78.                 // C'est bon !  
  79.                 try {  
  80.                     myDevice.setFullScreenWindow(myWindow);  
  81.                     myDevice.setDisplayMode(displayModes[i]);  
  82.                     return;  
  83.                 } catch (Exception e) {  
  84.                     e.printStackTrace();  
  85.                 }  
  86.             }  
  87.         /*     finally { 
  88.         }  
  89.         myDevice.setDisplayMode(oldDisplayMode); 
  90.         myDevice.setFullScreenWindow(null); 
  91.          
  92.         } 
  93.          * */  
  94.         }  
  95.     }  
  96.   
  97.     public Contour(String title) {  
  98.         super(title);  
  99.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
  100.   
  101.         // Gestion du fichier de préférences  
  102.         setPreferencesFileNames("preferences""Contours.properties""defaultContours.properties");  
  103.         // Load default preferences, inherited method  
  104.         readPreferences();  
  105.         // Load custom preferences  
  106.         loadPreferences();  
  107.   
  108.         setLayout(new BorderLayout());  
  109.         //setSize(WIDTH1, HEIGHT1);  
  110.   
  111.         // Use our own security manager, that can register listeners  
  112.         // All JFrameWithPreferences are listeners, see contructor of this  
  113.         // class  
  114.         ExitListenerSecurityManager sm;  
  115.         System.setSecurityManager(sm = new ExitListenerSecurityManager());  
  116.         sm.addSystemExitListener(this);  
  117.   
  118.   
  119.         if (fullscreen) {  
  120.             fullScreenMode(this, WIDTH1, HEIGHT1);  
  121.         }  
  122.         setVisible(true);  
  123.         init();  
  124.         addMouseListener(this);  
  125.   
  126.   
  127.         validate();  
  128.         // on lance l'animation  
  129.         new Thread(this).start();  
  130.     }  
  131.   
  132.     public static void main(String[] args) {  
  133.   
  134.         runAsApplet = false;  
  135.         Contour c = new Contour("Contour");  
  136.   
  137.     /* 
  138.     JFrameContours f = new JFrameContours("Contours"); 
  139.     f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
  140.      
  141.      
  142.     // Read preferences 
  143.     f.setPreferencesFileNames("preferences", "Contours.properties", "defaultContours.properties"); 
  144.     f.readPreferences(); 
  145.      
  146.      
  147.      
  148.     // Use our own security manager, that can register listeners 
  149.     // All JFrameWithPreferences qare listeners, see contructor of this 
  150.     // class 
  151.     ExitListenerSecurityManager sm; 
  152.     System.setSecurityManager(sm = new ExitListenerSecurityManager()); 
  153.     sm.addSystemExitListener(f); 
  154.      
  155.      
  156.     Contour applet = new Contour(); 
  157.     applet.emulateAppletParameters(args); 
  158.      
  159.     f.setSize(WIDTH1, HEIGHT1); 
  160.     f.setLayout(new BorderLayout()); 
  161.     f.add(applet, BorderLayout.CENTER); 
  162.      
  163.     f.setVisible(true); 
  164.     applet.init(); 
  165.     applet.addMouseListener(applet); 
  166.     //applet.fullScreenMode(f, WIDTH1, HEIGHT1); 
  167.      
  168.     applet.start(); 
  169.     // on lance l'animation 
  170.     new Thread(applet).start(); 
  171.      */  
  172.     }  
  173.   
  174.     private void drawRectangleForVp(Graphics g, int y) {  
  175.         g.setColor(Color.white);  
  176.         g.fillRect(w - 70, y - 157030);  
  177.         g.setColor(Color.black);  
  178.     }  
  179.   
  180.     /** 
  181.      * Load prefs 
  182.      *  
  183.      * @throws NumberFormatException 
  184.      * @throws HeadlessException 
  185.      */  
  186.     private void loadPreferences() throws NumberFormatException, HeadlessException {  
  187.   
  188.         try {  
  189.             // Set window size  
  190.             int width = Integer.parseInt(preferences.getProperty("width"));  
  191.             int height = Integer.parseInt(preferences.getProperty("height"));  
  192.             currentY = height / 2;  
  193.   
  194.             WIDTH1 = width;  
  195.             HEIGHT1 = height;  
  196.             //setSize(width, height);  
  197.   
  198.             // Read all preferences  
  199.             String stringValue = null;  
  200.             Boolean value = null;  
  201.   
  202.             if ((stringValue = preferences.getProperty("animationDelay")) != null) {  
  203.                 animationDelay = Integer.parseInt(stringValue);  
  204.             }  
  205.   
  206.   
  207.             if ((stringValue = preferences.getProperty("Rc")) != null) {  
  208.                 parameterRc = Integer.parseInt(stringValue);  
  209.             }  
  210.   
  211.             if ((stringValue = preferences.getProperty("Vp")) != null) {  
  212.                 parameterVp = Double.parseDouble(stringValue);  
  213.             }  
  214.   
  215.             if ((stringValue = preferences.getProperty("Burn")) != null) {  
  216.                 value = Boolean.valueOf(stringValue);  
  217.                 parameterBurn = value;  
  218.             }  
  219.   
  220.             if ((stringValue = preferences.getProperty("fullscreen")) != null) {  
  221.                 value = Boolean.valueOf(stringValue);  
  222.                 fullscreen = value;  
  223.             }  
  224.   
  225.             // Lecture des paramètres correspondants aux phases de l'animation  
  226.   
  227.             // Phase 1  
  228.             if ((stringValue = preferences.getProperty("delayAvantPhase1")) != null) {  
  229.                 delayAvantPhase1 = Integer.parseInt(stringValue);  
  230.             }  
  231.             if ((stringValue = preferences.getProperty("tempsAnimPhase1")) != null) {  
  232.                 tempsAnimPhase1 = Integer.parseInt(stringValue);  
  233.             }  
  234.             if ((stringValue = preferences.getProperty("debutPhase1")) != null) {  
  235.                 debutPhase1 = Double.parseDouble(stringValue);  
  236.             }  
  237.             if ((stringValue = preferences.getProperty("finPhase1")) != null) {  
  238.                 finPhase1 = Double.parseDouble(stringValue);  
  239.             }  
  240.   
  241.             // Phase 2  
  242.             if ((stringValue = preferences.getProperty("delayAvantPhase2")) != null) {  
  243.                 delayAvantPhase2 = Integer.parseInt(stringValue);  
  244.             }  
  245.             if ((stringValue = preferences.getProperty("tempsAnimPhase2")) != null) {  
  246.                 tempsAnimPhase2 = Integer.parseInt(stringValue);  
  247.             }  
  248.             if ((stringValue = preferences.getProperty("debutPhase2")) != null) {  
  249.                 debutPhase2 = Double.parseDouble(stringValue);  
  250.             }  
  251.             if ((stringValue = preferences.getProperty("finPhase2")) != null) {  
  252.                 finPhase2 = Double.parseDouble(stringValue);  
  253.             }  
  254.   
  255.   
  256.             // Phase 3  
  257.             if ((stringValue = preferences.getProperty("delayAvantPhase3")) != null) {  
  258.                 delayAvantPhase3 = Integer.parseInt(stringValue);  
  259.             }  
  260.             if ((stringValue = preferences.getProperty("tempsAnimPhase3")) != null) {  
  261.                 tempsAnimPhase3 = Integer.parseInt(stringValue);  
  262.             }  
  263.             if ((stringValue = preferences.getProperty("debutPhase3")) != null) {  
  264.                 debutPhase3 = Double.parseDouble(stringValue);  
  265.             }  
  266.             if ((stringValue = preferences.getProperty("finPhase3")) != null) {  
  267.                 finPhase3 = Double.parseDouble(stringValue);  
  268.             }  
  269.   
  270.   
  271.         /* 
  272.         if ((stringValue = preferences.getProperty("redrawAllFrame")) != null) { 
  273.         value = Boolean.valueOf(stringValue); 
  274.         panelLyrics.setForceDrawFullImage(value.booleanValue()); 
  275.         cdgOptionsDialog.setRedrawFullImage(value.booleanValue()); 
  276.         } 
  277.          
  278.         if ((stringValue = preferences.getProperty("hardwareAcceleratedFullScreenModeSupported")) != null) { 
  279.         value = Boolean.valueOf(stringValue); 
  280.         hardwareAcceleratedFullScreenModeSupported = value.booleanValue(); 
  281.         setFullScreenModeOption(); 
  282.         } 
  283.          
  284.         int fsWidth = -1,  fsHeight = -1,  fsDepth = -1,  fsFreq = -1; 
  285.         if ((stringValue = preferences.getProperty("fsWidth")) != null) { 
  286.         fsWidth = Integer.parseInt(stringValue); 
  287.         } 
  288.         if ((stringValue = preferences.getProperty("fsHeight")) != null) { 
  289.         fsHeight = Integer.parseInt(stringValue); 
  290.         } 
  291.         if ((stringValue = preferences.getProperty("fsDepth")) != null) { 
  292.         fsDepth = Integer.parseInt(stringValue); 
  293.         } 
  294.         if ((stringValue = preferences.getProperty("fsFreq")) != null) { 
  295.         fsFreq = Integer.parseInt(stringValue); 
  296.         } 
  297.          
  298.         if ((fsWidth != -1) && (fsHeight != -1) && (fsDepth != -1) && (fsFreq != -1)) { 
  299.         System.out.println("Read prefs for fs mode, plug " + getName() + " : (" + fsWidth + "," + fsHeight + "," + fsDepth + "," + fsFreq + ")"); 
  300.         userDisplayMode = new DisplayMode(fsWidth, fsHeight, fsDepth, fsFreq); 
  301.         } 
  302.          * */  
  303.         } catch (Exception e) {  
  304.             e.printStackTrace();  
  305.         }  
  306.   
  307.     }  
  308.   
  309.     /** 
  310.      * We redefine the inherited method so that visibility is always set to false before saving the 
  311.      * preferences 
  312.      */  
  313.     @Override  
  314.     public void savePreferences() {  
  315.         System.out.println("dans pref redéfinie");  
  316.         super.savePreferences();  
  317.     }  
  318.   
  319.     public void init() {  
  320.         w = getSize().width - 30;  
  321.         h = getSize().height - lbSize;  
  322.         nb = new int[w * h];  
  323.         delNb = new int[4];  
  324.         delNb[0] = 1;  
  325.         delNb[1] = -1;  
  326.         delNb[2] = w;  
  327.         delNb[3] = -w;  
  328.   
  329.   
  330.         Rc = parameterRc;  
  331.         Vp = parameterVp;  
  332.   
  333.         V = new double[w * h];  
  334.         iV = new int[w * (h + 2)];  
  335.         f = new double[h + 64][w + 64];  
  336.         for (int i = 0; i < h + 64; i++) {  
  337.             for (int j = 0; j < w + 64; j++) {  
  338.                 f[i][j] = 2 * Math.random() - 1;  
  339. //  f[100][100] = 1;  
  340.             }  
  341.         }  
  342.         G = new double[32][32];  
  343.         Lc = 2 * Rc;  
  344.         double Rc2 = Rc * Rc;  
  345.         G[0][0] = 1;  
  346.         for (int i = 1; i < Lc; i++) {  
  347.             G[0][i] = Math.exp(-(i * i / Rc2));  
  348.             for (int j = 1; j <= i; j++) {  
  349.                 G[j][i] = G[0][i] * G[0][j];  
  350.             }  
  351.         }  
  352.         byte rColor[] = new byte[maxColor + 2], bColor[] = new byte[maxColor + 2],  
  353.                 gColor[] = new byte[maxColor + 2];  
  354.         int M = maxColor / 2;  
  355.         long M4 = (long) M * M * M * M;  
  356.         for (int i = 0; i < M; i++) {  
  357.             long dum = i;  
  358.             dum *= dum;  
  359.             dum *= dum;  
  360.             bColor[i] = gColor[M + i] = gColor[M - i] = rColor[maxColor - 1 - i] =  
  361.                     (byte) (255 - (255 * dum) / M4);  
  362.         }  
  363.         gColor[M] = (byte220;  
  364.         rColor[cWhite] = gColor[cWhite] = bColor[cWhite] = (byte255;  
  365.         iColor = new IndexColorModel(8, maxColor + 2, rColor, gColor, bColor);  
  366.         hCol = h / maxColor;  
  367.         hBar = maxColor * hCol;  
  368.         int cBar[] = new int[20 * hBar], t = 0;  
  369.         for (int i = maxColor - 1; i >= 0; i--) {  
  370.             for (int j = 0; j < hCol; j++) {  
  371.                 for (int k = 0; k < 20; k++) {  
  372.                     cBar[t++] = i;  
  373.                 }  
  374.             }  
  375.         }  
  376.         imBar = createImage(new MemoryImageSource(20, hBar, iColor, cBar, 020));  
  377.   
  378.         Panel pannelHaut = new Panel();  
  379.   
  380.         /*lbRc = new Label("Rc", Label.RIGHT); 
  381.         pannelHaut.add(lbRc); 
  382.         chRc = new Choice(); 
  383.         for (   int i = 0, r = 1; i < 5; i++) { 
  384.         chRc.addItem(Integer.toString(r)); 
  385.         r *= 2; 
  386.         } 
  387.         chRc.select("" + Rc); 
  388.         chRc.addItemListener(this); 
  389.         pannelHaut.add(chRc); 
  390.         btNew = new Button("New"); 
  391.         btNew.addActionListener(this); 
  392.         pannelHaut.add(btNew); 
  393.          */  
  394.   
  395.         /* 
  396.         pannelHaut.add(vpLabel); 
  397.         vpLabel.setText("Vp = "); 
  398.          */  
  399.         bBurn = parameterBurn;  
  400.   
  401.         /* 
  402.         cbBurn = new Checkbox("Burn", bBurn); 
  403.         pannelHaut.add(cbBurn); 
  404.         cbBurn.addItemListener(this); 
  405.          */  
  406.         //add(pannelHaut, BorderLayout.NORTH);  
  407.         addMouseMotionListener(this);  
  408.         averaging();  
  409.     }  
  410.   
  411.     public void destroy() {  
  412.         removeMouseMotionListener(this);  
  413.     }  
  414.   
  415.     public void averaging() {  
  416.         generTime = System.currentTimeMillis();  
  417.         double Vmin = 100, Vmax = -100;  
  418.         sV = 0;  
  419.         int t = 0, w32 = w + 32;  
  420.         for (int i = 32; i < h + 32; i++) {  
  421.             for (int j = 32; j < w32; j++) {  
  422.                 double s = G[0][0] * f[i][j];  
  423.                 for (int m = 1; m < Lc; m++) {  
  424.   
  425.   
  426.   
  427.   
  428.   
  429.   
  430.   
  431.   
  432.   
  433.   
  434.   
  435.   
  436.                     int im = i + m, i_m = i - m, jm = j + m, j_m = j - m;  
  437.                     s += G[0][m] * (f[im][j] + f[i_m][j] + f[i][jm] + f[i][j_m]) +  
  438.                             G[m][m] * (f[im][jm] + f[i_m][jm] + f[im][j_m] + f[i_m][j_m]);  
  439.                     for (int n = 1; n < m; n++) {  
  440.   
  441.   
  442.   
  443.   
  444.   
  445.   
  446.   
  447.   
  448.   
  449.   
  450.   
  451.   
  452.   
  453.   
  454.   
  455.   
  456.   
  457.   
  458.   
  459.   
  460.   
  461.                         int in = i + n,  
  462.                                 i_n = i -  
  463.                                 n, jn = j + n, j_n = j - n;  
  464.                         s += G[n][m] * (f[im][jn] + f[i_m][jn] + f[im][j_n] + f[i_m][j_n] +  
  465.                                 f[in][jm] + f[i_n][jm] + f[in][j_m] + f[i_n][j_m]);  
  466.                     }  
  467.                 }  
  468.                 V[t++] = s;  
  469.                 if (s > Vmax) {  
  470.                     Vmax = s;  
  471.                 }  
  472.                 if (s < Vmin) {  
  473.                     Vmin = s;  
  474.                 }  
  475.                 sV += s;  
  476.             }  
  477.         }  
  478.         sV /= w * h;  
  479.         Vo = Vmax;  
  480.         if (Vmax < -Vmin) {  
  481.             Vo = -Vmin;  
  482.         }  
  483.         makeImg();  
  484.         generTime = System.currentTimeMillis() - generTime;  
  485.     }  
  486.   
  487.     public synchronized void makeImg() {  
  488.         double a = .5 * maxColor / Vo, tmp, VpVo = Vp * Vo;  
  489.         for (int i = 0; i < w * h; i++) {  
  490.             if ((tmp = V[i]) < VpVo) {  
  491.                 iV[i + w] = cWhite;  
  492.             } else {  
  493.                 iV[i + w] = (int) (a * (tmp + Vo));  
  494.             }  
  495.         }  
  496.         if (bBurn) {  
  497.             int lastNb = -1;  
  498.             for (int i = w; i < 2 * w; i++) {  
  499.                 if (iV[i] == cWhite) {  
  500.                     nb[++lastNb] = i;  
  501.                 }  
  502.             }  
  503.             while (lastNb >= 0) {  
  504.                 int n = nb[lastNb--];  
  505.                 if (iV[n] == cWhite) {  
  506.                     iV[n] = cBlack;  
  507.                     for (int i = 0; i < 4; i++) {  
  508.                         int t = n + delNb[i];  
  509.                         if (iV[t] == cWhite) {  
  510.                             nb[++lastNb] = t;  
  511.                         }  
  512.                     }  
  513.                 }  
  514.             }  
  515.         }  
  516.         if (img != null) {  
  517.             img.flush();  
  518.         }  
  519.         img = createImage(new MemoryImageSource(w, h, iColor, iV, w, w));  
  520.     }  
  521.     NumberFormat nf = NumberFormat.getNumberInstance();  
  522.     DecimalFormat df = (DecimalFormat) nf;  
  523.     String output = "";  
  524.   
  525.     @Override  
  526.     public void paint(Graphics g) {  
  527.         // Pour l'affichage de Vp  
  528.         df.applyPattern("#.##");  
  529.         output = df.format(Vp);  
  530.   
  531.   
  532.   
  533.         //updateLabel(output);  
  534.   
  535.   
  536.         g.drawImage(img, 0, lbSize, this);  
  537.         g.drawImage(imBar, w, lbSize, this);  
  538.         g.setColor(Color.white);  
  539.         int y = lbSize + (int) (hBar * (1 - sV / Vo) / 2);  
  540.         g.drawLine(w + 10, y, w + 30, y);  
  541.         g.setColor(Color.black);  
  542.         y = lbSize + (int) (hBar * (1 - Vp) / 2);  
  543.         g.drawLine(w, y - 1, w + 15, y - 1);  
  544.         g.drawLine(w, y, w + 15, y);  
  545.         g.drawLine(w, y + 1, w + 15, y + 1);  
  546.         g.setColor(Color.black);  
  547.   
  548.   
  549.   
  550.   
  551.         if (flipFlap) {  
  552.             g.setColor(Color.WHITE);  
  553.         } else {  
  554.             g.setColor(Color.BLACK);  
  555.         }  
  556.         flipFlap = !flipFlap;  
  557.   
  558.         if (y >= HEIGHT1 - 50) {  
  559.             drawRectangleForVp(g, HEIGHT1 - 50 - 3);  
  560.             g.drawString("Vp = " + output, w - 60, HEIGHT1 - 50);  
  561.         } else if (y <= (lbSize + 50)) {  
  562.             drawRectangleForVp(g, lbSize + 50 - 3);  
  563.             g.drawString("Vp = " + output, w - 60, lbSize + 50);  
  564.         } else {  
  565.             drawRectangleForVp(g, y);  
  566.             g.drawString("Vp = " + output, w - 60, y + 5);  
  567.         }  
  568.   
  569.     // Affichage de Vp dnas un rectangle blanc en haut de la fenêtre  
  570.        /* g.setColor(Color.white); 
  571.     g.fillRect((getWidth() - 50) / 2, 0, 70, 50); 
  572.     g.setColor(Color.black); 
  573.     g.drawString("Vp = " + output, ((getWidth() - 50) / 2) + 10, 45); 
  574.      */  
  575.     }  
  576.   
  577.     synchronized private void updateLabel(String output) {  
  578.   
  579.         if (vpLabel != null) {  
  580.             vpLabel.setText("Vp = " + output + " T = " + generTime + " ms");  
  581.         }  
  582.     }  
  583.   
  584.     public void mouseMoved(MouseEvent e) {  
  585.     }  
  586.   
  587.     public void mouseDragged(MouseEvent e) {  
  588.         synchronized (new Object()) {  
  589.             if (e.getX() > w) {  
  590.                 int y = e.getY() - lbSize;  
  591.                 currentY = e.getY();  
  592.                 Vp = 1 - y * 2.0 / hBar;  
  593.                 if (Vp < -1) {  
  594.                     Vp = -1;  
  595.                 }  
  596.                 if (Vp > 1) {  
  597.                     Vp = 1;  
  598.                 }  
  599.                 makeImg();  
  600.   
  601.             //repaint();  
  602.             }  
  603.         }  
  604.     }  
  605.   
  606.     public void itemStateChanged(ItemEvent e) {  
  607.         Object src = e.getSource();  
  608.         if (src == cbBurn) {  
  609.             bBurn = cbBurn.getState();  
  610.             makeImg();  
  611.         }  
  612.         if (src == chRc) {  
  613.             Rc = Integer.parseInt(chRc.getSelectedItem());  
  614.             Lc = 2 * Rc;  
  615.             double Rc2 = Rc * Rc;  
  616.             G[0][0] = 1;  
  617.             for (int i = 1; i < Lc; i++) {  
  618.                 G[0][i] = Math.exp(-(i * i / Rc2));  
  619.                 for (int j = 1; j <= i; j++) {  
  620.                     G[j][i] = G[0][i] * G[0][j];  
  621.                 }  
  622.             }  
  623.             averaging();  
  624.         }  
  625.         repaint();  
  626.     }  
  627.   
  628.     private void newContour() {  
  629.         for (int i = 0; i < h + 64; i++) {  
  630.             for (int j = 0; j < w + 64; j++) {  
  631.                 f[i][j] = 2 * Math.random() - 1;  
  632.             }  
  633.         }  
  634.         averaging();  
  635.         repaint();  
  636.     }  
  637.   
  638.     public void actionPerformed(ActionEvent e) {  
  639.         newContour();  
  640.     }  
  641.   
  642.     @Override  
  643.     public void update(Graphics g) {  
  644.         paint(g);  
  645.     }  
  646.     public static final int PHASE1 = 0;  
  647.     public static final int PHASE2 = 1;  
  648.     public static final int PHASE3 = 2;  
  649.     private int phase = PHASE1;  
  650.   
  651.     private void setVp(double Vp) {  
  652.         //-Vp = -1 +(currentY -lbSize)*2/hbar;  
  653.         currentY = (int) ((((-Vp + 1) * hBar) / 2.0) + lbSize);  
  654.   
  655.     }  
  656.   
  657.     // Tous les temps sont en ms  
  658.     private double getVpCourant(double VpDebut, double VpInterval,  
  659.             long tempsEcoule, long tempsAnimPhase2) {  
  660.   
  661.         return VpDebut + (VpInterval * tempsEcoule) / (double) tempsAnimPhase2;  
  662.     }  
  663.   
  664.     private int getYFromVp(double Vp) {  
  665.         return (int) ((((-Vp + 1) * hBar) / 2.0) + lbSize);  
  666.     }  
  667.   
  668.     private void updateVp(double min, double max) {  
  669.   
  670.         int y = currentY - lbSize;  
  671.         Vp = 1 - y * 2.0 / hBar;  
  672.         if (Vp < min) {  
  673.             Vp = min;  
  674.             incY = -incY;  
  675.         }  
  676.         if (Vp > max) {  
  677.             Vp = max;  
  678.             incY = -incY;  
  679.         }  
  680.         // On rafraichit l'image suivante  
  681.         makeImg();  
  682.         repaint();  
  683.   
  684.         // On incremente y  
  685.         currentY += incY;  
  686.     }  
  687.   
  688.     public void run() {  
  689.         long tempsCourant = 0;  
  690.         long tempsDebut = 0;  
  691.         long tempsEcoule = 0;  
  692.         int y = 0;  
  693.         double VpCourant = 0;  
  694.         double intervalleVp = 0;  
  695.   
  696.         if (getWidth() != 0) {  
  697.             while (true) {  
  698.                 try {  
  699.                     // Phase 1  
  700.                     Thread.sleep(delayAvantPhase1 * 1000);  
  701.                     intervalleVp = finPhase1 - debutPhase1;  
  702.                     incY = -Math.abs(incY);  
  703.                     setVp(debutPhase1);  
  704.                     tempsDebut = System.currentTimeMillis();  
  705.                     while (phase == PHASE1) {  
  706.                         Thread.sleep(animationDelay);  
  707.   
  708.                         //   
  709.                         updateVp(debutPhase1, finPhase1);  
  710.   
  711.                         tempsCourant = System.currentTimeMillis();  
  712.                         tempsEcoule = tempsCourant - tempsDebut;  
  713.   
  714.                         // On calcule le prochain Vp en fonction du temps écoulé  
  715.                         VpCourant = getVpCourant(debutPhase1, intervalleVp, tempsEcoule, tempsAnimPhase1 * 1000);  
  716.                         currentY = getYFromVp(VpCourant);  
  717.                         //System.out.println("Dans PHASE 1, tempsEcoule=" + tempsEcoule / 1000.0 + " tempsAnimPhase1 = " + tempsAnimPhase1);  
  718.                         if ((tempsEcoule / 1000.0) > tempsAnimPhase1) {  
  719.                             //System.out.println("ON CHANGE DE PHASE !");  
  720.                             phase = PHASE2;  
  721.                         }  
  722.                     }  
  723.   
  724.                     // Phase 2         
  725.                     Thread.sleep(delayAvantPhase2 * 1000);  
  726.                     intervalleVp = finPhase2 - debutPhase2;  
  727.                     tempsDebut = System.currentTimeMillis();  
  728.                     setVp(debutPhase2);  
  729.                     incY = -Math.abs(incY);  
  730.                     while (phase == PHASE2) {  
  731.                         Thread.sleep(animationDelay);  
  732.                         updateVp(debutPhase2, finPhase2);  
  733.   
  734.                         tempsCourant = System.currentTimeMillis();  
  735.                         tempsEcoule = tempsCourant - tempsDebut;  
  736.   
  737.                         // On calcule le prochain Vp en fonction du temps écoulé  
  738.                         VpCourant = getVpCourant(debutPhase2, intervalleVp, tempsEcoule, tempsAnimPhase2 * 1000);  
  739.                         currentY = getYFromVp(VpCourant);  
  740.                         //System.out.println("Dans PHASE 2, tempsEcoule=" + tempsEcoule / 1000.0 + "tempsAnimPhase2 = " + tempsAnimPhase2);  
  741.   
  742.                         if (tempsEcoule / 1000.0 > tempsAnimPhase2) {  
  743.                             phase = PHASE3;  
  744.                         }  
  745.                     }  
  746.                     //System.out.println("Après phase 2 on attend : " + delayApresPhase2 * 1000);  
  747.   
  748.   
  749.                     // Phase 3  
  750.   
  751.                     Thread.sleep(delayAvantPhase3 * 1000);  
  752.                     incY = -Math.abs(incY);  
  753.                     setVp(debutPhase3);  
  754.                     intervalleVp = finPhase3 - debutPhase3;  
  755.                     tempsDebut = System.currentTimeMillis();  
  756.                     while (phase == PHASE3) {  
  757.                         Thread.sleep(animationDelay);  
  758.                         updateVp(debutPhase3, finPhase3);  
  759.   
  760.                         tempsCourant = System.currentTimeMillis();  
  761.                                tempsEcoule = tempsCourant - tempsDebut;  
  762.                         // On calcule le prochain Vp en fonction du temps écoulé  
  763.                         VpCourant = getVpCourant(debutPhase3, intervalleVp, tempsEcoule, tempsAnimPhase3 * 1000);  
  764.                         currentY = getYFromVp(VpCourant);  
  765.                         //System.out.println("Dans PHASE 3, tempsEcoule=" + tempsEcoule / 1000.0 + "tempsAnimPhase3 = " + tempsAnimPhase3);  
  766.   
  767.                    
  768.                         if (tempsEcoule / 1000.0 > tempsAnimPhase3) {  
  769.                             phase = PHASE1;  
  770.                             // On renouvelle le contourr  
  771.                             newContour();  
  772.                         }  
  773.                     }  
  774.                 //System.out.println("Après phase 3 on attend : " + delayApresPhase3 * 1000);  
  775.   
  776.                 } catch (InterruptedException ex) {  
  777.                     Logger.getLogger(Contour.class.getName()).log(Level.SEVERE, null, ex);  
  778.                 }  
  779.             }  
  780.         }  
  781.     }  
  782.   
  783.     public void mouseClicked(MouseEvent e) {  
  784.     }  
  785.   
  786.     public void mousePressed(MouseEvent e) {  
  787.         currentY = e.getY();  
  788.     }  
  789.   
  790.     public void mouseReleased(MouseEvent e) {  
  791.     }  
  792.   
  793.     public void mouseEntered(MouseEvent e) {  
  794.     }  
  795.   
  796.     public void mouseExited(MouseEvent e) {  
  797.     }  
  798. }  

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

Sections intéressantes

 

 


Récupéré depuis "http://miageprojet2.unice.fr/"