Thursday, 13 November 2008

Rotating Blocks

Still waiting for my book to arrive, but in the mean time I have been busy reading the information on the Processing Web Site.

I was recently discussing this project with a friend, and he suggested I may be interested in some computer generated art he had seen recently on the Krazydad blog and one particular piece by Daniel Piker inspired me to write my first Processing code showing some Rotating Blocks.
/**
* Rotating Blocks
* by Nigel Parker
*
* Each column of blocks rotates at a different rate with the centre
* column remaining static and the left an right sides rotating in
* a different direction
*/

int [] r = new int[6];
int [] rVal = new int[6];

void setup() {

// Set up initial rotation speeds
rVal[0]=5;
rVal[1]=4;
rVal[2]=3;
rVal[3]=2;
rVal[4]=1;
rVal[5]=0;

// Set the initial screen size etc
size(640,640);
smooth();
noStroke();

}

void draw()
{

background(0);

for(int i=0;i<6;i++)
{
int xxLeft = 65 + (50 * i);
int xxRight = 565 - (50 * i);

// We will be drawing 11 boxes in a line
for(int j=0;j<11;j++)
{
int yy = 65 + (50 * j);
drawBox(xxLeft,yy,30,30,radians(r[i]));

// Don't need to draw the centre column twice
if (i < 5)
{
drawBox(xxRight,yy,30,30,radians((-1 * r[i])));
}
}
r[i] = (r[i] + rVal[i]) % 360;
}

}

void drawBox(int x, int y, int w, int h, float rot)
{
fill(0,148,255);

// Move the origin of the co-ordinate system to be the
// centre of the box we are going to draw
translate(x,y);

// Rotate the co-ordinate system by the required amount
rotate(rot);

// Draw the rectangle based around the centre co-ordinates
rectMode(CENTER);
rect(0,0,w,h);

// Rotate the co-ordinate system back by the required amount
// We have to do this as rotate is cumulative
rotate((rot * -1));

// Move the origin of the co-ordinate system back to
// its original position
// We have to do this as translate is cumulative
translate(-x,-y);
}

Tuesday, 4 November 2008

A book buyer's tale ...


At the weekend I decided to get the processing book. I’m a bit impatient and didn’t want to wait for an online delivery so I phoned my local Waterstones store to check they had one in stock before going in to town. A very helpful member of staff checked on their computer system but unfortunately neither of the two stores in my nearest town had the book in stock, she also checked two other stores in neighbouring towns with the same result. I do live in the country so I thought maybe it is not the kind of book they get a lot of call for, but since I work in London I also asked if she could check the Ealing branch, same result. I thanked her for her efforts and decided to buy on line, I checked with Amazon, out of stock, before finally placing an order with Waterstones on line.

I have just received an email from Waterstones and they too are out of stock and will have to place another order with the publishers ….. This book must be in demand for some reason!

Initial thoughts

I have been writing software for a long time now, initially self taught during the early days of the BBC Model B; I subsequently studied computer science to degree level and made it my career. I guess after spending so much time in the business of writing software it is quite easy to become a bit jaded, to find it all a bit repetitive, but about a year ago I started studying and using Java and I have become such a fan of the language it has given me a new enthusiasm for programming, so when I heard about the Mass Writing Project with the Open University I just had to get involved ….