BlinkenArea - GitList
Repositories
Blog
Wiki
BlinkenSimJava
Code
Commits
Branches
Tags
Search
Tree:
16048cb
Branches
Tags
master
v0.1
v0.1.1
v0.2
BlinkenSimJava
BlinkenSim.java
BlinkenSimJava v.0.1 (2004-06-29)
Christian Heimke
commited
16048cb
at 2011-07-15 09:12:42
BlinkenSim.java
Blame
History
Raw
import java.lang.*; import java.applet.*; import java.awt.*; public class BlinkenSim extends Applet { private DynMcufClient mcuf; private FrameProcessor frameProc; public void init( ) { String host = ""; int port = 0; host = getParameter( "host" ); if( host.length( ) <= 0 ) host = "proxy.blinkenlights.de"; port = Integer.parseInt( getParameter( "port" ) ); if( port <= 0 || port > 65535 ) port = 4242; mcuf = new DynMcufClient( ); frameProc = new FrameProcessor( this ); mcuf.start( host, port, frameProc ); } public void stop( ) { mcuf.stop( ); mcuf = null; frameProc = null; } public void paint( Graphics g ) { int height, width, channels; byte[][][] data; Image img; Graphics gBuf; int y, x, c, val; Frame frame = frameProc.getFrame( ); height = frame.getHeight( ); width = frame.getWidth( ); channels = frame.getChannels( ); data = frame.getData( ); img = createImage( width * 10 + 20, height * 20 + 50 ); gBuf = img.getGraphics( ); gBuf.setColor( Color.black ); gBuf.fillRect( 0, 0, width * 10 + 20, height * 20 + 50 ); gBuf.setColor( Color.white ); gBuf.drawString( "BlinkenSimJava: " + height + "x" + width + "-" + channels, 20, 20 ); for( y = 0; y < height; y++ ) { for( x = 0; x < width; x++ ) { val = 0; for( c = 0; c < channels; c++ ) val += data[y][x][c] & 0xFF; val /= channels; gBuf.setColor( new Color( val, val, val ) ); gBuf.fillRect( x * 10 + 10, y * 20 + 30, 10, 20 ); } } g.drawImage( img, 0, 0, this ); //System.out.println( frame.toString( ) ); } public void update( Graphics g ) { paint( g ); } }