PROCESSING

http://processing.org

downlaod:  http://processing.org/download/

 i understood that it is mainly used to create applications  (java apps).

 NOTE: The applet folder is erased and recreated each time you use the Export command, so be sure to move the folder elsewhere before you make any changes to the HTML file or anything else inside.

example one :   just  to create ellipse
--
ellipse(50, 50, 80, 80);//(a,b,c,d)--center(a,b), major and minor axis (d,c)
 
 
ctrl+r---run
ctrl+shift+r---fullscreen mode 
 
 when saved---
produces jar and html files.
so can be used in any webpage as an app using html file.
 
This can also be exported directly as an application ---ctrl+shift+e
 
 
PROCESSING.... 
coordinate system



POINT::
LINE::
and...........
 
 
 
1st program adjusting coodinates
 
 
float x=300;

void setup ()
{
  size(600,600);
  smooth();
}
void draw()
{
  background (0);
  ellipse (x,mouseY,20,20);
  x=x+2;
  
  if (x>599)
  x=0;
}


2nd prog calling functions



void setup ()
{
  size(600,600);
  smooth();
}
void draw()
{
  background (0);
 
 elip(100,100,10);
 elip(100,200,100);
 elip(200,100,50);

}

void elip(float x,float y,float r)
{
  fill(r,30,20);
 ellipse (x,y,20,20) ;
 
}


Arduino with Processing :

Instructions

  1. Unzip the library and copy the "arduino" folder into the "libraries" sub-folder of your Processing Sketchbook. (You can find the location of your Sketchbook by opening the Processing Preferences. If you haven't made a "libraries" sub-folder, create one.)
  2. Run Arduino, open the Examples > Firmata > StandardFirmata sketch, and upload it to the Arduino board.
  3. Configure Processing for serial: http://processing.org/reference/libraries/serial/
  4. In Processing, open one of the examples that comes with with the Arduino library.
  5. Edit the example code to select the correct serial port.
  6. Run the example.

 
 
INTERFACING ARDUINO AND PROCESSING
example 1 leds
one should write two programs to interface arduino 
one for arduino and 2nd for processing.
step to be checked id to select the correct port in setup .
 
codes for arduino: 
int val=0;


void setup(){
 Serial.begin(9600);
 pinMode(12,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(10,OUTPUT);
}
 
void loop()
{
 
  int a=Serial.read();
  switch (a)
  {
    case 1:
  if (a==1)
  {
    digitalWrite(11,HIGH);
    delay(2000);
    digitalWrite(11,LOW);
  }
  break;
  case 2:
  if (a==2)
   {
    digitalWrite(12,HIGH);
    delay(2000);
    digitalWrite(12,LOW);
  }
  break;
  }
}
 
code for processing:
import processing.serial.*;
Serial ser1;
void setup()
{
  println(Serial.list());
 ser1=new Serial(this,Serial.list()[1],9600);
  ser1.buffer(1);
  size(400,400);
  background(0);
  noLoop();
}

void draw(){
  fill (100,0,0);
  rect (0,0,width/2, height);
  
  
}
void mousePressed() {
  println("Coordinates: " + mouseX +"," + mouseY);
  mouseAction();
    }

void mouseAction(){
  if (mouseX>0&& mouseX < width/2){
    if (mouseY>0 && mouseY <height){

      ser1.write(1);
    }
  }
   if (mouseX>width/2&& mouseX < width){
    if (mouseY>0 && mouseY <height){
     
      ser1.write(2);
    }
  }
} 
example 2 :  bouncing ball game
code for process:
import processing.serial.*;
Serial ser1;
 float x=0;
  float y=0;

 float  sx = 2;
 float  sy = .2;
 
void setup()
{
  println(Serial.list());
 ser1=new Serial(this,Serial.list()[1],9600);
  ser1.buffer(1);
  size(400,400);
  background(0);
  
  //noLoop();
 
}

void draw()
{
    background(0);//so that the privious ball erase
    smooth();
 ellipse (x,y,20,20);//display ball
 //now to move
    x  = x + sx;
    y  = y + sy;
    // now to bounce
    if (x > width)
    {
      sx=sx *-1;
    }
    if (y > height)
    {
      sy=sy *-1;
    }
    if (x<0)
    {
    sx=sx *-1;
    }
     if (y <0)
    {
      sy=sy *-1;
    }
    
    sy += .2;//gravity
    
     
     
    
    
}
void mousePressed(){
   println("Coordinates: " + mouseX +"," + mouseY);
   
   
  mouseAction();
    }

void mouseAction() { 
  
  
  if (mouseX >x-20 && mouseX < x+20){
    if (mouseY >y-20 && mouseY <y+20) {
      ser1.write(1);
      
    }
  }
  else 
  {
  ser1.write(2);
   
}
  
  
  
}
code for ard:
int val=0;


void setup(){
 Serial.begin(9600);
 pinMode(12,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(10,OUTPUT);
}
 
void loop()
{
 
  int a=Serial.read();
  switch (a)
  {
    case 1:
  if (a==1)
  {
    digitalWrite(11,HIGH);
    delay(500);
    digitalWrite(11,LOW);
  }
  break;
  case 2:
  if (a==2)
   {
    digitalWrite(12,HIGH);
    delay(500);
    digitalWrite(12,LOW);
  }
  break;
  }
}