import processing.core.*; 
import processing.data.*; 
import processing.event.*; 
import processing.opengl.*; 

import processing.serial.*; 

import java.util.HashMap; 
import java.util.ArrayList; 
import java.io.File; 
import java.io.BufferedReader; 
import java.io.PrintWriter; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.io.IOException; 

public class SimpleRead_bezier extends PApplet {

/**
 * Simple Read
 * 
 * Read data from the serial port and change the color of a rectangle
 * when a switch connected to a Wiring or Arduino board is pressed and released.
 * This example works with the Wiring / Arduino program that follows below.
 */



int lf=10;
Serial myPort;  // Create object from Serial class
String val;      // Data received from the serial port
float math,roll;
public void setup() 
{
   
  stroke(255);
  noFill();
  // I know that the first port in the serial list on my mac
  // is always my  FTDI adaptor, so I open Serial.list()[0].
  // On Windows machines, this generally opens COM1.
  // Open whatever port is the one you're using.
  String portName = Serial.list()[1];
  myPort = new Serial(this, portName, 9600);
}

public void draw()
{
  if ( myPort.available() > 0) {  // If data is available,
    val = myPort.readStringUntil(lf);         // read it and store it in val
  }
      if (val != null) {
  print(val);  // Prints String
  math=PApplet.parseFloat(val);  // Converts and prints float
  println(math);
      }


  background(0);
  for (int i = 0; i < 200; i += 20) {
    bezier(math-(i/2.0f), 40+i, 410, 20, 440, 300, 240-(i/16.0f), 300+(i/8.0f));}
}
  public void settings() {  size(640, 360); }
  static public void main(String[] passedArgs) {
    String[] appletArgs = new String[] { "SimpleRead_bezier" };
    if (passedArgs != null) {
      PApplet.main(concat(appletArgs, passedArgs));
    } else {
      PApplet.main(appletArgs);
    }
  }
}
