Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.net.*;
- Server myServer;
- final int w = 200;
- final int h = 200;
- final int frmRate = 30;
- final static int INT_SIZE = 4;
- final int port = 5204;
- void setup() {
- size(w, h);
- frameRate(frmRate);
- background(255);
- myServer = new Server(this, port);
- bytes = new byte[w * h * INT_SIZE];
- }
- byte[] bytes;
- void draw() {
- if (mousePressed)
- if (mouseButton == LEFT)
- line(pmouseX, pmouseY, mouseX, mouseY);
- else
- background(255);
- loadPixels();
- for (int i = 0; i < w * h; i++) {
- byte[] b = convertIntToByteArray(pixels[i]);
- for(int k = 0; k < INT_SIZE; k++) {
- bytes[i * INT_SIZE + k] = b[k];
- }
- }
- myServer.write(bytes);
- }
- private static byte[] convertIntToByteArray(int val) {
- byte[] buffer = new byte[INT_SIZE];
- for(int i = 0; i < INT_SIZE; i++)
- buffer[i] = (byte) (val >> (8 * (3 - i)));
- return buffer;
- }
- void stop() {
- myServer.stop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement