import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.vecmath.*; public class Spin2 extends Device2 implements Runnable { private int angleCount = 0; public Spin2 ( int h, int w, float s ){ super ( h, w, s ); } public Spin2 ( int h, int w ) { this ( h, w, 1.0f ); } public Spin2() { this ( 550, 850 ); } public void rotate() { angleCount++; double angle = angleCount * Math.PI / 64; viewPosition = new Vector3f ( (float) ( 5 * Math.cos ( angle ) ), (float) ( 5* Math.sin ( angle ) ), 5 ); viewNormal = new Vector3f ( (float) ( -1 * Math.cos ( angle ) ), (float) ( -1 * Math.sin ( angle ) ), -1 ); viewUp = new Vector3f ( 0, 0, 1); fixView(); repaint(); } public void run() { Thread thread = Thread.currentThread(); while ( thread != null ) { try { thread.sleep ( 300 ); } catch ( InterruptedException e ) { System.out.println ( "Work, work, work, all I do is work" ); } rotate(); } } public static void main ( String[] args ) { try { UIManager.setLookAndFeel ( UIManager.getCrossPlatformLookAndFeelClassName() ); } catch ( Exception exc ) { System.out.println ( "Error loading L&F: " + exc ); } WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; JFrame frame = new JFrame ( "Sci Vis" ); frame.addWindowListener(l); Function3f fun = new TorusKnot( 1.0f, 0.5f, 3, 2); ParametricCurve p = new ParametricCurve ( 0, 6, 0.25f, fun ); Spin2 d = new Spin2( 600, 600, 100); d.setModel ( p ); frame.getContentPane().add(d, BorderLayout.CENTER); frame.setSize ( d.getSize() ); frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); frame.show(); frame.validate(); frame.repaint(); Thread t = new Thread ( d ); t.start(); d.requestDefaultFocus(); } }