package horloge;
import be.ibiiztera.md.pmatrix.pushmatrix.Camera;
import be.ibiiztera.md.pmatrix.pushmatrix.Point3D;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.image.BufferedImage;import be.ibiiztera.md.pmatrix.pushmatrix.Scene;
import be.ibiiztera.md.pmatrix.pushmatrix.TColor;
import be.ibiiztera.md.pmatrix.pushmatrix.ZBuffer;
import be.ibiiztera.md.pmatrix.pushmatrix.ZBufferFactory;
import be.ibiiztera.md.pmatrix.pushmatrix.ZBufferImpl;
import be.ibiiztera.md.pmatrix.pushmatrix.generator.TRISphere;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Image;
import java.util.Date;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;public class Horloge {
Color h;
Color m;
Color s;
Dimension res;
private boolean montre = true;
public Horloge(Color h, Color m, Color s, Dimension res) {
super();
this.h = h;
this.m = m;
this.s = s;
this.res = res;
}
public Scene time()
{
double f = 2*Math.PI;Date d = new Date();
Scene s = new Scene();
TRISphere s0 = new TRISphere(Point3D.O0, 10);
TRISphere sH = new TRISphere(position(f*d.getHours()/12)
.mult(60), 12);
TRISphere sM = new TRISphere(position(f*d.getMinutes()/60)
.mult(80), 8);
TRISphere sS = new TRISphere(position(f*d.getSeconds()/60)
.mult(100), 6);s0.couleur(new TColor(Color.WHITE));
sH.couleur(new TColor(Color.GREEN));
sM.couleur(new TColor(Color.BLUE));
sS.couleur(new TColor(Color.RED));s.add(s0);
s.add(sH);
s.add(sM);
s.add(sS);s.cameraActive(new Camera(Point3D.Z.mult(-200), Point3D.O0));
return s;
}
public Point3D position(double angle)
{Point3D p0 =
new Point3D(
-Math.sin(angle),
-Math.cos(angle),
0
);return p0;
}
public void montrer(Container c)
{
ZBuffer z = ZBufferFactory.instance(
(int)res.getWidth(),
(int)res.getHeight());while(montre)
{
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
z.couleurDeFond(new TColor(Color.BLACK));z.suivante();
z.scene(time());
z.dessinerSilhouette3D();
Image bi = ((ZBufferImpl)z).image2();
c.getGraphics().drawImage(bi, 0, 0,(int) res.getWidth(), (int)res.getHeight(), null);
}
}public static void main(String [] args)
{
JFrame f = new JFrame(« Horloge 3D »);f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel b = new JLabel(« Horloge »);
f.setContentPane(b);
f.setSize(1024, 768);
f.setVisible(true);
Horloge h = new Horloge(null, null, null, b.getSize());
h.montrer(b);
}
}
Laisser un commentaire