Monday, 28 March 2011

//variables - defining how the wave will move from point to point on the x/y axis
int xpos;
int w;

//floats -
float map;
float freq;
float pan;
float yoff = 0.0f;
float[] ypos;

//XMLElemnts - the feeds im using from the arch os site
XMLElement [] raindescription;
XMLElement [] winddescription;

//setup
void setup() {  - the setup of the canvas and how I want it to run

  println("0");
  size(500,500);
  smooth();
  frameRate(40); - increased frame rate to make the transistion of the animation more smother
  w = width ;
 

  println("1");


  // Rain
  String rainurl = "http://x2.i-dat.org/archos/archive.rss?source=.Rain_Sensor";
  XMLElement rainxml = new XMLElement(this, rainurl);
  raindescription = rainxml.getChildren("channel/item/description");
  println("2");

  // Wind Speed
  String windurl = "http://x2.i-dat.org/archos/archive.rss?source=.Windspeed";
  XMLElement  windxml = new XMLElement(this, windurl);
  winddescription = windxml.getChildren("channel/item/description");
  println("3");
}    - the feeds of where im drawing the raw data to effect the visulation
//draw

void draw ()
{
background(0); - placed my background colour in the draw section to white wash the screen, because i faced a problem of the visulation leaving a ghost trail on the screen
{
  for (int i = 0; i < raindescription.length;i++) - calculation for making the variables communicate with the feed to generate the animation
  {
    xpos = int(raindescription[i].getContent()); -Rain feed
    if(xpos !=0) {
      ypos = new float[w/xpos];
    }
    else {
      ypos = new float[0]; - This will stop the line becoming flat if the code goes below a value that will cause the wave to move such as "0" for rain being an example
    }
    calcWave();
     fill(RGB,39,226,17); - colour of my wave
    renderWave();
   
  }

  for (int i = 0; i < winddescription.length;i++)
  {
    xpos = int(winddescription[i].getContent()); - wind feed
    if(xpos !=0) {
    ypos = new float[w/xpos];
    }
    else {
      ypos = new float[0];
    }

calcWave();
   fill(HSB,100,300);
    renderWave();
  }
 
}
}

//wave calculation  - i can change the height of the wave and the angle it produces the feed
void calcWave() {
  float dx = -0.04f;
  float dy = 0.4f;
  float amplitude = 30.0f;

  yoff +=dy;

  float xoff = yoff;

  for (int i = 0; i < ypos.length; i++) {
    ypos[i] = (3*noise(xoff)-1)*amplitude;
    xoff+=dx;
  }
}

//wave render
void renderWave() {
  for (int x = 0; x < ypos.length;x++) {
    stroke(10);
 
   
   
    ellipseMode(CENTER);    - allows me the change the shape of the objects shown onscreen
    ellipse(x*xpos,width/2+ypos[x],18,18);
  }
}

No comments:

Post a Comment