// The "Matrix2" class.
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.font.*;
import java.util.*;
import java.lang.*;
import java.awt.image.*;
import javax.swing.*;
import java.io.*;
import javax.sound.sampled.*;
public class Matrix2 extends JWindow
{
private static BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));
private int bufferWidth; // Image buffer width
private int bufferHeight; // Image buffer height
private Image bufferImage; // entire Image buffer
private Graphics bufferGraphics;
int ANTIALIASING = 0;
int LH = 1; //Letter Height
int LA = 1000; // Letter Amount - 1
int LLP = 0;
int x = 0;
int DS = 7;
int scry = 10;
int scrx = 10;
static String file = "";
int[] [] Letters = new int [LA + 1] [5];
int[] [] Chars = new int [LA + 1] [7];
public int i1 = 0x4E45; // letter values for the random letters
public int i2 = 0x4E45;
public int i3 = 0x4E45;
public int i4 = 0x4E45;
public int i5 = 0x4E45;
public int i6 = 0x4E45;
public int i7 = 0x4E45;
public int i8 = 0x4E45; // end of letter values
Random generator1 = new Random (); // random letter generator for all letter values
public void initializer () throws IOException
{
BufferedReader in = new BufferedReader (new FileReader ("Matrix Settings.txt"));
ANTIALIASING = Integer.parseInt (in.readLine ());
LH = Integer.parseInt (in.readLine ());
LA = Integer.parseInt (in.readLine ());
DS = Integer.parseInt (in.readLine ());
scry = Integer.parseInt (in.readLine ());
scrx = Integer.parseInt (in.readLine ());
file = in.readLine ();
}
public Matrix2 ()
{
try
{
initializer ();
}
catch (IOException e)
{
System.out.println ("Unable to initialize, wrong Settings");
}
Dimension dim = Toolkit.getDefaultToolkit ().getScreenSize ();
setSize (dim);
setBackground (Color.black);
setVisible (true);
for (int I = 0 ; I <= LA ; I++)
{
Letters [I] [0] = generator1.nextInt (scry);
}
}
public static void music ()
{
try
{
// From file
AudioInputStream stream = AudioSystem.getAudioInputStream (new File (file));
AudioFormat format = stream.getFormat ();
if (format.getEncoding () != AudioFormat.Encoding.PCM_SIGNED)
{
format = new AudioFormat (
AudioFormat.Encoding.PCM_SIGNED,
format.getSampleRate (),
format.getSampleSizeInBits () * 2,
format.getChannels (),
format.getFrameSize () * 2,
format.getFrameRate (),
true); // big endian
stream = AudioSystem.getAudioInputStream (format, stream);
}
// Create the clip
DataLine.Info info = new DataLine.Info (Clip.class, stream.getFormat (), ((int) stream.getFrameLength () * format.getFrameSize ()));
Clip clip = (Clip) AudioSystem.getLine (info);
// This method does not return until the audio file is completely loaded
clip.open (stream);
// Start playing
clip.loop (Clip.LOOP_CONTINUOUSLY);
}
catch (java.net.MalformedURLException e)
{
}
catch (IOException e)
{
}
catch (LineUnavailableException e)
{
}
catch (UnsupportedAudioFileException e)
{
}
}
public void draw (Graphics g, int x, int y, int LC, int LS, int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8)
{
x = x * LH;
Graphics2D g2;
g2 = (Graphics2D) g;
if (ANTIALIASING == 1)
{
g2.setRenderingHint (RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint (RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
}
FontRenderContext frc = g2.getFontRenderContext ();
Font f = new Font ("Arial Unicode MS", Font.PLAIN, LH);
char c1 = (char) i1;
String s1 = new String ();
s1 = String.valueOf (c1);
TextLayout tl = new TextLayout (s1, f, frc);
char c2 = (char) i2;
String s2 = new String ();
s2 = String.valueOf (c2);
TextLayout t2 = new TextLayout (s2, f, frc);
char c3 = (char) i3;
String s3 = new String ();
s3 = String.valueOf (c3);
TextLayout t3 = new TextLayout (s3, f, frc);
char c4 = (char) i4;
String s4 = new String ();
s4 = String.valueOf (c4);
TextLayout t4 = new TextLayout (s4, f, frc);
char c5 = (char) i5;
String s5 = new String ();
s5 = String.valueOf (c5);
TextLayout t5 = new TextLayout (s5, f, frc);
char c6 = (char) i6;
String s6 = new String ();
s6 = String.valueOf (c6);
TextLayout t6 = new TextLayout (s6, f, frc);
char c7 = (char) i7;
String s7 = new String ();
s7 = String.valueOf (c7);
TextLayout t7 = new TextLayout (s7, f, frc);
char c8 = (char) i8;
String s8 = new String ();
s8 = String.valueOf (c8);
TextLayout t8 = new TextLayout (s8, f, frc);
if (LS == 2)
{
g2.setColor (new Color (120, 255, 130));
tl.draw (g2, x, y);
g2.setColor (new Color (60, 255 - (255 / LS) * 1, 60));
t2.draw (g2, x, y - LH);
}
if (LS == 3)
{
g2.setColor (new Color (120, 255, 130));
tl.draw (g2, x, y);
g2.setColor (new Color (100, 255 - (255 / LS) * 1, 110));
t2.draw (g2, x, y - LH);
g2.setColor (new Color (0, 255 - (255 / LS) * 2, 0));
t3.draw (g2, x, y - 2 * LH);
}
if (LS == 4)
{
g2.setColor (new Color (120, 255, 130));
tl.draw (g2, x, y);
g2.setColor (new Color (100, 255 - (255 / LS) * 1, 110));
t2.draw (g2, x, y - LH);
g2.setColor (new Color (0, 255 - (255 / LS) * 2, 0));
t3.draw (g2, x, y - 2 * LH);
g2.setColor (new Color (0, 255 - (255 / LS) * 3, 0));
t4.draw (g2, x, y - 3 * LH);
}
if (LS == 5)
{
g2.setColor (new Color (120, 255, 130));
tl.draw (g2, x, y);
g2.setColor (new Color (100, 255 - (255 / LS) * 1, 110));
t2.draw (g2, x, y - LH);
g2.setColor (new Color (0, 255 - (255 / LS) * 2, 0));
t3.draw (g2, x, y - 2 * LH);
g2.setColor (new Color (0, 255 - (255 / LS) * 3, 0));
t4.draw (g2, x, y - 3 * LH);
g2.setColor (new Color (0, 255 - (255 / LS) * 4, 0));
t5.draw (g2, x, y - 4 * LH);
}
if (LS == 6)
{
g2.setColor (new Color (120, 255, 130));
tl.draw (g2, x, y);
g2.setColor (new Color (100, 255 - (255 / LS) * 1, 110));
t2.draw (g2, x, y - LH);
g2.setColor (new Color (0, 255 - (255 / LS) * 2, 0));
t3.draw (g2, x, y - 2 * LH);
g2.setColor (new Color (0, 255 - (255 / LS) * 3, 0));
t4.draw (g2, x, y - 3 * LH);
g2.setColor (new Color (0, 255 - (255 / LS) * 4, 0));
t5.draw (g2, x, y - 4 * LH);
g2.setColor (new Color (0, 255 - (255 / LS) * 5, 0));
t6.draw (g2, x, y - 5 * LH);
}
if (LS == 7)
{
g2.setColor (new Color (120, 255, 130));
tl.draw (g2, x, y);
g2.setColor (new Color (100, 255 - (255 / LS) * 1, 110));
t2.draw (g2, x, y - LH);
g2.setColor (new Color (0, 255 - (255 / LS) * 2, 0));
t3.draw (g2, x, y - 2 * LH);
g2.setColor (new Color (0, 255 - (255 / LS) * 3, 0));
t4.draw (g2, x, y - 3 * LH);
g2.setColor (new Color (0, 255 - (255 / LS) * 4, 0));
t5.draw (g2, x, y - 4 * LH);
g2.setColor (new Color (0, 255 - (255 / LS) * 5, 0));
t6.draw (g2, x, y - 5 * LH);
g2.setColor (new Color (0, 255 - (255 / LS) * 6, 0));
t7.draw (g2, x, y - 6 * LH);
}
if (LS == 8)
{
g2.setColor (new Color (120, 255, 130));
tl.draw (g2, x, y);
g2.setColor (new Color (100, 255 - (255 / LS) * 1, 110));
t2.draw (g2, x, y - LH);
g2.setColor (new Color (0, 255 - (255 / LS) * 2, 0));
t3.draw (g2, x, y - 2 * LH);
g2.setColor (new Color (0, 255 - (255 / LS) * 3, 0));
t4.draw (g2, x, y - 3 * LH);
g2.setColor (new Color (0, 255 - (255 / LS) * 4, 0));
t5.draw (g2, x, y - 4 * LH);
g2.setColor (new Color (0, 255 - (255 / LS) * 5, 0));
t6.draw (g2, x, y - 5 * LH);
g2.setColor (new Color (0, 255 - (255 / LS) * 6, 0));
t7.draw (g2, x, y - 6 * LH);
g2.setColor (new Color (0, 255 - (255 / LS) * 7, 0));
t8.draw (g2, x, y - 7 * LH);
}
}
public void update (Graphics g)
{
paint (g);
}
public void paint (Graphics g)
{
// checks the buffersize with the current panelsize
// or initialises the image with the first paint
if (bufferWidth != getSize ().width ||
bufferHeight != getSize ().height ||
bufferImage == null ||
bufferGraphics == null)
resetBuffer ();
if (bufferGraphics != null)
{
// this clears the offscreen image, not the onscreen one
bufferGraphics.clearRect (0, 0, bufferWidth, bufferHeight);
// calls the paintbuffer method with the offscreen graphics as a param
paintBuffer (bufferGraphics);
// we finaly paint the offscreen image onto the onscreen image
g.drawImage (bufferImage, 0, 0, this);
//If a delay is needed to freeze the letters, insert it here
}
}
private void resetBuffer ()
{
// always keep track of the image size
bufferWidth = getSize ().width;
bufferHeight = getSize ().height;
// clean up the previous image
if (bufferGraphics != null)
{
bufferGraphics.dispose ();
bufferGraphics = null;
}
if (bufferImage != null)
{
bufferImage.flush ();
bufferImage = null;
}
System.gc ();
// create the new image with the size of the panel
bufferImage = createImage (bufferWidth, bufferHeight);
bufferGraphics = bufferImage.getGraphics ();
}
public void paintBuffer (Graphics g)
{
for (int I = 0 ; I <= LA ; I++)
{
Letters [I] [0] = Letters [I] [0] + DS;
Letters [I] [3] = 0;
if (Letters [I] [0] > scry + LH * Letters [I] [4])
{
Letters [I] [1] = generator1.nextInt ((scrx / LH));
Letters [I] [4] = generator1.nextInt (6) + 2;
Letters [I] [0] = 0;
Letters [I] [2] = 0;
}
if (Letters [I] [0] > Letters [I] [2] + LH)
{
Letters [I] [3] = 1;
Letters [I] [2] = Letters [I] [0];
}
if (Letters [I] [3] == 1)
{
for (int h = 6 ; h >= 1 ; h--)
{
Chars [I] [h] = Chars [I] [h - 1];
}
Chars [I] [0] = generator1.nextInt ((0x9FA5 - 0x4E00)) + 0x4E00;
}
}
for (int I = 0 ; I <= LA ; I++)
{
draw (g, Letters [I] [1], Letters [I] [0], Letters [I] [3], Letters [I] [4], Chars [I] [0], Chars [I] [1], Chars [I] [2], Chars [I] [3], Chars [I] [4], Chars [I] [5], Chars [I] [6], Chars [I] [6]);
}
repaint ();
}
public static void main (String[] args)
{
new Matrix2 ();
//music ();
}
} // Matrix2 class
|