data speed between arduino and processing, maybe coding prob ?

I ve got a tablet hook up to arduino which send 3 variables to processing : penStatus, x, y in ascii string
In processing i ve set up a drawing sketch which splits the string then interprets x and y to do some drawing.
But the lines are not continuous and kind of "laggy". it seems that it can't keep up with the speed of the stylus; it only draws small xtoy points and jumps to another one with no connection lines between them, i ve joined the processing sketch and a picture of the results.
thanks for any help.

import processing.serial.*;

 Serial myPort;                       // The serial port
 
 
 int x = 0;
 int y = 0;

 int oldx = 0;
 int oldy = 0;
 int penStatus = 0;


  

 void setup()
 {
   size(3200,2400);
   frameRate(25);
   background(0);
   smooth();
   stroke (204, 102, 0);
   strokeWeight(5);
   strokeJoin(MITER);
   
   myPort = new Serial(this, "COM5", 19200); 
   myPort.bufferUntil('\n');
  
 }

void serialEvent(Serial myPort) {
     
     oldx = x;
     oldy = y;
  
  // read the serial buffer:
   String myString = myPort.readStringUntil('\n');
   // if you got any bytes other than the linefeed:
     myString = trim(myString);
  
     // split the string at the commas
     // and convert the sections into integers:
     int sensors[] = int(split(myString, ','));
 
    // print out the values you got:
     for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
      print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
      println();
     
     penStatus = sensors[0];
     x = sensors[1];
     y = sensors[2];
     
     
     print(oldx);
     print(oldy);
     print(x);
     println(y);
     
     
    }
 
}


 void draw() {
   
   line (oldx, oldy, x, y);
   
   

  
 }

Heres a pic about the results

There are a number of issues with your code that you could improve.

The draw() function is called in an endless loop, just like loop() in the Arduino sketch. You my be drawing the same line thousands of times. I think you should only draw a line when there is data for a new line to be drawn (that is, in the serial event).

You are receiving data at 19200. The Arduino is capable of sending data 6 times that fast, at 115200. That alone will improve your response rate.

Converting integer data to strings, sending strings, and converting those strings back to integers is not the fastest way to send binary data from the Arduino to the Processing application. You should learn how to send data as binary values, and how to receive binary data in Processing.

Hi,
yeah i ve already changed the baudrate to 115200, i can see a slight improvement, but still have the dot lines thing.
I ll try the other two suggestions and report, thanks !

edit : Yeah, putting the "line" in the serial event and not in the draw function worked !
I was minsinformed about the draw() function beeing for everything that is drawn on the screen.

thanks for the help.