Monday, 19 April 2010

Processing Sketch - Evaluating

Overall I must say that I am mostly pleased with my sketch. Despite me not having the skill set to write the code for some things I wanted to implement I still managed to get a half decent looking processing sketch.

I am most pleased that I managed to get it to read the XML and then put the data into floats for me to use because this was a part I thought I would struggle with but once I found the correct code this was not that difficult. Another bit I am pleased with is that the balls bounce around all over the stage as originally I struggled to get them to do anything but bounce from the left to the right.

Things I am not too happy about is that I was not able to get the balls to bounce off eachother, it seems that collision detection is more than a bitch in processing than in flash! Also I was a bit upset, but not overly, that I was not able to use XML data to determine how many balls appeared on stage. This was purely because I had no idea what code to write that would achieve this. However I think 8 balls are more than enough for this sketch. Also some may say that its a little bland looking which I can understand as I am not too happy about the white background but there is little I could do really because white truely is the best colour to display things.

So to summarise, I am happy with this because despite enjoying processing I did find some parts difficult and also was not able to get some parts of my idea to work. But overall I am pleased with my sketch and I believe that it is far more interesting to look at than the ArchOS feed!

Sunday, 18 April 2010

Processing Sketch - Final Touches

Now that I had the code that would get the data I wanted and the code for the balls I had to do was setup the draw function and create the balls. Unfortunately I could not work out a way to get the balls to bounce off one another and neither could I find out how to use a number to generate objects randomly so I had to create the balls manually as such:

ball1 = new Ball(LT1_Hum);
ball2 = new Ball(LT1_Temp);
ball3 = new Ball(LT2_Hum);
ball4 = new Ball(LT2_Temp);
ball5 = new Ball(LT3_Hum);
ball6 = new Ball(LT3_Temp);
ball7 = new Ball(AtriumA3rd_Temp);
ball8 = new Ball(AtriumA5th_Temp);


And once that was done I entered the float name into the brackets and if you remember from an earlier post the number in the brackets would be the radius.

And here is my draw function that displays the balls:

void draw() {
background(255);
ball1.move();
ball2.move();
ball3.move();
ball4.move();
ball5.move();
ball6.move();
ball7.move();
ball8.move();
ball1.display();
ball2.display();
ball3.display();
ball4.display();
ball5.display();
ball6.display();
ball7.display();
ball8.display();
}


That is it, that is how my processing sketch was made. I will evaluate it properly at some point in the future.

Friday, 16 April 2010

Processing Sketch - Getting The Data

Now that my balls were practically finished I thought I would get onto writing the code that would collect the data I was going to use.

First of all I setup the floats that I was going to use:

float outsidetemperature;
float windspeed;
float windvane;
float humidity;
float LT1_Hum;
float LT1_Temp;
float LT2_Hum;
float LT2_Temp;
float LT3_Hum;
float LT3_Temp;
float AtriumA3rd_Temp;
float AtriumA5th_Temp;


I will state later on why I chose these particular bits of data.

Then I wrote these lines of code to get the numbers that I wanted.

outsidetemperature = float(description[21].getContent());
windspeed = float(description[37].getContent());
windvane = float(description[36].getContent());
humidity = float(description[20].getContent());
LT1_Hum = float(description[14].getContent());
LT1_Temp = float(description[15].getContent());
LT2_Hum = float(description[16].getContent());
LT2_Temp = float(description[17].getContent());
LT3_Hum = float(description[18].getContent());
LT3_Temp = float(description[19].getContent());
AtriumA3rd_Temp = float(description[23].getContent());
AtriumA5th_Temp = float(description[24].getContent());


I worked out that the XML feed was sort of like an array and thus by entering a number between the square brackets I could select what data I wanted using getContent. Now these were stored into the variables all I would have to do is type the float name and that number would be used.

Processing Sketch - The Bouncing Balls

Now that I have written the code that will read the XML I thought I would make a start on the balls which will appear in my sketch. I opened up a brand new tab and wrote the code to get the balls to bounce off the walls. I decided to leave the complicated collision detection stuff until later.

class Ball {

float r; //this is the circle's radius
float x,y;
float xspeed,yspeed;
color c;

Ball(float tempR) {
r = tempR;
x = random(width);
y = random(height);
xspeed = random( -5,5);
yspeed = random( -5,5);
}

void move() {
x += xspeed;
y += yspeed;

if (x > width || x < 0) {
xspeed *= - 1;
}

if (y > height || y < 0) {
yspeed *= - 1;

void display() {
stroke(0);
fill(c);
ellipse(x,y,r*2,r*2);
c = color(100,50);//using a basic grey colour for now


This code creates the Ball class and it sets it speed and colour (for now, later I will look to making these data from the XML feed). I have also set up for the ball to bounce of the sides of the stage.

Thursday, 15 April 2010

Processing Sketch - The Start

I have chosen to go with the bouncing balls idea and have just started work on it today. First off I have written my code that will read the XML data I will need and the setup.

import processing.xml.*;

XMLElement xml;
XMLElement[] title;
XMLElement[] pubDate;
XMLElement[] description;

void setup()
{
size(500,500);
background(255);
smooth();
frameRate(60);
String url = "http://arch-os.scce.plymouth.ac.uk/bms_data.rss";
XMLElement xml = new XMLElement(this, url);
title = xml.getChildren("channel/item/title");
pubDate = xml.getChildren("channel/item/pubDate");
description = xml.getChildren("channel/item/description");


And thats all for today folks. In the next view posts I will describe the process in making my sketch.

Processing Sketch - First Thoughts

Ah processing I was actually enjoying it during the sessions but now theres an assignment I think may begin to hate it. As always with assignments I go through the initial ideas stage. However it seems that I am stuck for ideas with this one. Currently I've only got these 2 ideas:

Bouncing Balls: I will have balls bouncing off the sides of the stage and off eachother changing colour and/or size based on the XML data. I will also hopefully be able to use some data to determine how many balls appear on the stage at one time.

Falling Objects: There will be objects falling from the top of the stage and falling through the bottom. Again I would use the data to change the colour/size and also determin how many objects appear.

I will post again soon stating which idea I have chosen or if I come up with a better one! (highly unlikely)

Issues with Flash

So we discovered that there are issues with Flash when it comes to using it for what we wanted to use it for. In Jon's Post he mentions issues with combining XML streams. If we continue to struggle we may have to change the software we using and at the moment we are considering using Processing. We will however continue to attempt to get stuff working in Flash before.