Advertisement
Guest User

remote_server

a guest
Nov 21st, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import processing.net.*;
  2.  
  3. Server myServer;
  4.  
  5. final int w = 200;
  6. final int h = 200;
  7. final int frmRate = 30;
  8. final static int INT_SIZE = 4;
  9. final int port = 5204;
  10.  
  11. void setup() {
  12.   size(w, h);
  13.   frameRate(frmRate);
  14.   background(255);
  15.   myServer = new Server(this, port);
  16.   bytes = new byte[w * h * INT_SIZE];
  17. }
  18.  
  19. byte[] bytes;
  20.  
  21. void draw() {
  22.    
  23.   if (mousePressed)
  24.     if (mouseButton == LEFT)
  25.       line(pmouseX, pmouseY, mouseX, mouseY);
  26.     else
  27.       background(255);
  28.   loadPixels();
  29.  
  30.   for (int i = 0; i < w * h; i++) {
  31.     byte[] b = convertIntToByteArray(pixels[i]);
  32.     for(int k = 0; k < INT_SIZE; k++) {
  33.     bytes[i * INT_SIZE + k] = b[k];
  34.     }
  35.   }
  36.   myServer.write(bytes);
  37. }
  38.  
  39. private static byte[] convertIntToByteArray(int val) {
  40.   byte[] buffer = new byte[INT_SIZE];
  41.   for(int i = 0; i < INT_SIZE; i++)
  42.     buffer[i] = (byte) (val >> (8 * (3 - i)));
  43.  
  44.  
  45.   return buffer;
  46. }
  47.  
  48. void stop() {
  49.   myServer.stop();
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement