import java.awt.event.*; import javax.swing.*; import java.util.*; import javax.media.opengl.*; import javax.media.opengl.glu.*; import com.sun.opengl.util.*; public class randomDemo// extends glskeleton// implements GLEventListener// , KeyListener// { private GLU glu; // public randomDemo() { } public void run() { GLCapabilities caps = new GLCapabilities(); GLJPanel canvas = new GLJPanel(caps); randomDemo demo = new randomDemo(); canvas.addGLEventListener(demo); demo.setCanvas(canvas); demo.setDefaultListeners(demo); // JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("randomDemo"); frame.setSize(400, 400); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(canvas); frame.setVisible(true); canvas.requestFocusInWindow(); } public static void main(String[] args) { new randomDemo().run(); } public void init(GLAutoDrawable drawable) { GL gl = drawable.getGL(); glu = new GLU(); // gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); gl.glShadeModel(GL.GL_SMOOTH); } public void display(GLAutoDrawable drawable) { GL gl = drawable.getGL(); // java.util.Random /* An instance of this class is used to generate a stream of pseudorandom numbers. The class uses a 48-bit seed, which is modified using a linear congruential formula. (See Donald Knuth, The Art of Computer Programming, Volume 2, Section 3.2.1.) nextBoolean nextFloat nextDouble nextGaussian nextInt setSeed(long seed) */ Random ran = new Random(); gl.glClear(GL.GL_COLOR_BUFFER_BIT); /* select white for all lines */ gl.glColor3f(0.0f, 0.0f, 0.0f); gl.glPointSize(2.0f); gl.glBegin(GL.GL_POINTS); for(double x=0; x<400.0; x+=0.1){ //double y = ran.nextDouble()*100; double y = ran.nextGaussian()*100; gl.glVertex2d(x,y); } gl.glEnd(); gl.glFlush(); } public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) { GL gl = drawable.getGL(); // gl.glViewport(0, 0, w, h); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glu.gluOrtho2D(0.0, (double) w, 0.0, (double) h); } public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { } public void keyTyped(KeyEvent key) { } public void keyPressed(KeyEvent key) { switch (key.getKeyCode()) { case KeyEvent.VK_ESCAPE: super.runExit(); break; default: break; } } public void keyReleased(KeyEvent key) { } }