Section courante

A propos

Section administrative du site

J'ai longuement hésité, tant qu'à savoir, si je devais mettre ou non, un exemple d'affichage du Cube RVB en 3 dimensions. Est-ce vraiment utile? Il semblerait que, dans un certain sens, oui, puisque je considère que cela permettra pour plusieurs de développer leur imagination dans un sens pratique du traitement des couleurs. Le concept de l'image suivante est fort simple, il faut créer des coordonnées en 3 dimensions de façon à égaler toujours la même somme total en coordonnée lorsqu'on affiche dans une couleur. Voici le code source Java :

  1. import java.awt.*;
  2. import java.awt.event.*; 
  3.  
  4. public class RGBBOX extends Frame implements WindowListener {
  5.     
  6.     static final int CenterHorizontal=320 >> 1;
  7.     static final int CenterVertical=320 >> 1;
  8.     
  9.     public void windowClosing(WindowEvent e) {
  10.         System.exit(0);
  11.     }
  12.     
  13.     public void windowActivated(WindowEvent e){}
  14.     public void windowClosed(WindowEvent e){}
  15.     public void windowDeactivated(WindowEvent e){}
  16.     public void windowDeiconified(WindowEvent e){}
  17.     public void windowIconified(WindowEvent e){}
  18.     public void windowOpened(WindowEvent e) {} 
  19.     
  20.     public RGBBOX() {
  21.         addWindowListener(this);
  22.     } 
  23.     
  24.     public static void SetPixel3D(Graphics g,int X,int Y,int Z,Color Kr) {
  25.         g.setColor(Kr);
  26.         g.drawRect(CenterHorizontal+X-(Z >> 1),CenterVertical-Y+(Z >> 1),1,1);
  27.     }
  28.     
  29.     public void paint(Graphics g) { 
  30.         for(int I=0;I<149;I++) {
  31.             SetPixel3D(g,0,0,I,Color.BLACK);
  32.             SetPixel3D(g,0,I,0,Color.BLACK);
  33.             SetPixel3D(g,I,0,0,Color.BLACK);
  34.         }
  35.         for(int J=99;J>=0;J--) for(int I=0;I<=99;I++) SetPixel3D(g,I,J,99,new Color(I,J,99));
  36.         for(int K=0;K<=99;K++) for(int I=0;I<=99;I++) SetPixel3D(g,I,99,K,new Color(I,99,K));
  37.         for(int J=99;J>=0;J--) for(int K=0;K<=99;K++) SetPixel3D(g,99,J,K,new Color(99,J,K));
  38.     }
  39.     
  40.     public static void main(String[] args) {  
  41.         RGBBOX f = new RGBBOX();
  42.         f.setTitle("Cube RVB");
  43.         f.setSize(320, 320);
  44.         f.setVisible(true);
  45.     }
  46.     
  47. }

Voici en terminant un exemple du résultat de se petit programme :




Dernière mise à jour : Mercredi, le 3 juin 2015