Cette classe dessinne une sorte de soleils. Je l'ai obtenu au hasard, mais je trouvais que le résultat donnait bien.
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class SoleilLouche extends JPanel {
private static final long serialVersionUID = 6899161860200488093L ;
public SoleilLouche (){
super ();
setOpaque (false );
setBackground (Color.white);
setPreferredSize (new Dimension (512 ,512 ));
}
public static void main (String[] args) {
JFrame frame = new JFrame (" Soleil louche " );
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.setContentPane (new SoleilLouche ());
frame.pack ();
frame.setVisible (true );
}
public void paint (Graphics graphics) {
graphics.setColor (Color.white);
graphics.fillRect (0 , 0 , getWidth (), getHeight ());
int r = 0 ;
int g = 0 ;
int b = 0 ;
for (int i = 0 ; i < getWidth (); i+ + ){
if (r = = 255 ){
if (b >= 1 ){
b- - ;
} else if (g = = 255 ){
r- - ;
} else {
g+ + ;
}
} else if (g = = 255 ){
if (b = = 255 ){
g- - ;
} else if (r = = 0 ){
b+ + ;
} else {
r- - ;
}
} else if (b = = 255 ){
if (r = = 255 )
b- - ;
} else if (g = = 0 ){
r+ + ;
} else {
g- - ;
}
graphics.setColor (new Color (r, g, b));
graphics.drawOval (0 , 0 , i, i);
}
super .paint (graphics);
}
}
|
|