shapingthings

EtchSketch_Processing

Jun 15th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import processing.serial.*;
  2.  
  3. float penX;
  4. float penY;
  5.  
  6. color bgColor = color( 0 ); // color of background
  7. color penColor = color( 60, 120, 20 ); // color of our pen
  8.  
  9. Serial myPort; // our serial port
  10.  
  11. void setup() {
  12. size( 800, 600 );
  13. background( bgColor ); // set the background color
  14. noStroke(); // turn off outline around shapes
  15. fill( penColor ); // set pen color
  16.  
  17. penX = width/2; // starting x position of pen
  18. penY = height/2; // starting y position of pen
  19.  
  20. printArray(Serial.list());
  21.  
  22. myPort = new Serial(this, Serial.list()[11], 9600);
  23.  
  24. myPort.bufferUntil(10);
  25. }
  26.  
  27. void draw() {
  28. ellipse( penX, penY, 10, 10 );
  29. }
  30.  
  31. void serialEvent(Serial p) {
  32.  
  33. String inString = p.readString(); // read in the string
  34. //println( inString );
  35. String pairs[] = split( inString, ';' ); // split up string into pairs
  36.  
  37. println(pairs[0]+","+pairs[1]+","+pairs[2]);
  38.  
  39. int x = Integer.parseInt(pairs[0]);
  40. int y = Integer.parseInt(pairs[1]);
  41.  
  42. // x value mapping
  43. penX = map( x, 0, 1023, 0, width);
  44.  
  45. // y value mapping
  46. penY = map( y, 0, 1023, 0, width);
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment