import processing.net.*; Client c; int lBar, hBar, ballSize; int x1, y1, x2, y2, x3, y3; void setup() { size(400, 600); ballSize = 15; lBar = 100; hBar = 20; c = new Client(this, "127.0.0.1", 4321); } void draw() { background(0); sendPosition(); receivePosition(); drawBar(); drawBall(); x2 = mouseX; } void drawBar() { rect(min(max(x1 - (lBar/2), 0), (width - lBar)), height - (hBar + 10), lBar, hBar); rect(min(max(x2 - (lBar/2), 0), (width - lBar)), 10, lBar, hBar); } void drawBall() { ellipse(x3, y3, ballSize, ballSize); } void sendPosition() { c.write(x2+"\n"); } void receivePosition() { if (c.available() > 0) { String input = c.readString(); input = input.substring(0, input.indexOf("\n")); int[] data = int(splitTokens(input, ",")); x1 = data[0]; x3 = data[1]; y3 = data[2]; } }