Monday, 27 July 2009

Program written

I've finally written the program for this chunk, it justs needs commenting and then the chunk text explanation writing:



void setup() {

size(800, 600, P3D);

}

void draw() {

float clockwiseDirection = frameCount * PI;
float antiClockwiseDirection = frameCount * -PI;

background(255);
fill(138, 43, 226, 100);

pushMatrix();
// move to the centre of the screen
translate(width / 2, height / 2, 0);

rotateX(clockwiseDirection / 250);
rotateY(clockwiseDirection / 250);
rotateZ(clockwiseDirection / 250);
cuboctahedron(250);

rotateX(antiClockwiseDirection / 250);
rotateY(antiClockwiseDirection / 250);
rotateZ(antiClockwiseDirection / 250);
sphereDetail(1);
sphere(200);

rotateX(clockwiseDirection / 200);
rotateY(clockwiseDirection / 200);
rotateZ(clockwiseDirection / 200);
box(120);

rotateX(antiClockwiseDirection / 150);
rotateY(antiClockwiseDirection / 150);
rotateZ(antiClockwiseDirection / 150);
cuboctahedron(50);

popMatrix();

for (int i = 40; i < height + 40; i = i + 80) {
for (int j = 40; j < width; j = j + 80) {

pushMatrix();
translate(j, i, 0);

rotateZ(antiClockwiseDirection / 150);
rotateX(antiClockwiseDirection / 150);
rotateY(antiClockwiseDirection / 150);
draw2DPolygon(6, 40);

rotateZ(clockwiseDirection / 255);
rotateX(clockwiseDirection / 255);
rotateY(clockwiseDirection / 255);
draw2DPolygon(5, 30);

popMatrix();

}
}

}

void draw2DPolygon(int sides, int size) {

fill(85, 26, 139, 30);
stroke(138, 43, 226, 20);

int x = 0;
int y = 0;

float centreX = 0;
float centreY = 0;

for (int i = 0; i < sides; i++) {

float xCoord = (x + size * cos(i * 2 * PI / sides));
float yCoord = (y + size * sin(i * 2 * PI / sides));

centreX += xCoord;
centreY += yCoord;

}

centreX = (centreX / sides) * -1;
centreY = (centreY / sides) * -1;

beginShape();

for (int i = 0; i <= sides; i++) {

float xCoord = (centreX + size * cos(i * 2 * PI / sides));
float yCoord = (centreY + size * sin(i * 2 * PI / sides));

vertex(xCoord, yCoord);

}

endShape();

for (int i = 0; i < sides; i++) {

float xCoord = (centreX + size * cos(i * 2 * PI / sides));
float yCoord = (centreY + size * sin(i * 2 * PI / sides));

line(xCoord, yCoord, centreX, centreY);

}

stroke(0);

}

void cuboctahedron(int size) {

char[] vertices = new char[] {
'A',
'I',
'E',
'K',
'A',
'B',
'J',
'F',
'I',
'B',
'D',
'L',
'H',
'J',
'D',
'C',
'K',
'G',
'L',
'C',
'A',
'I',
'E',
'G',
'H',
'F',
'E' };

beginShape();
drawCuboctahedron(vertices, size);
endShape();

}

void drawCuboctahedron(char[] vertices, float edgeSize) {

float halfEdgeSize = edgeSize / 2;
float halfDiagonalSize = (sqrt((sq(edgeSize)) + (sq(edgeSize)))) / 2;

float x = 0;
float y = 0;
float z = -edgeSize;

for (int i = 0; i < vertices.length; i++) {
char vertex = vertices[i];
switch (vertex) {
case 'A':
vertex(x - halfEdgeSize, y - halfDiagonalSize, z + halfEdgeSize);
break;
case 'B':
vertex(x + halfEdgeSize, y - halfDiagonalSize, z + halfEdgeSize);
break;
case 'C':
vertex(x - halfEdgeSize, y - halfDiagonalSize, z + (halfEdgeSize * 3));
break;
case 'D':
vertex(x + halfEdgeSize, y - halfEdgeSize, z + (halfEdgeSize * 3));
break;
case 'E':
vertex(x - halfEdgeSize, y + halfEdgeSize, z + halfEdgeSize);
break;
case 'F':
vertex(x + halfEdgeSize, y + halfEdgeSize, z + halfEdgeSize);
break;
case 'G':
vertex(x - halfEdgeSize, y + halfDiagonalSize, z + (halfEdgeSize * 3));
break;
case 'H':
vertex(x + halfEdgeSize, y + halfDiagonalSize, z + (halfEdgeSize * 3));
break;
case 'I':
vertex(x, y, z);
break;
case 'J':
vertex(x + (halfEdgeSize * 2), y, z + (halfEdgeSize * 2));
break;
case 'K':
vertex(x - (halfEdgeSize * 2), y, z + (halfEdgeSize * 2));
break;
case 'L':
vertex(x, y, z + (halfEdgeSize * 4));
break;
}
}

}



Friday, 12 June 2009

Idea

I've been thinking about how I can implement this chunk whilst still having it carry on from chunk 46 and 47, in order to allow the reader to read through without it looking like it is jumping topics

So my idea is to continue with the theme from chunk 46, but introduce new features at each stage. I'm assuming that by 'lines' we mean straight lines (ie not curves), so I will attempt to do the following:

Chunk 47 - follow the chunk 46 theme but add animation to the patterns
Chunk 48 - follow the chunk 47 theme but add 3D aspects

Wednesday, 27 May 2009

Chunk 48

CHUNK 48
TITLE Bringing it together 3
DESCRIPTION This is a really difficult section. What we want you to do is to develop a program of about 200 lines which is visually stunning and which uses any of Processing's line functions.
OUTCOME
  • Understand a large Processing program
REFERENCE Any facility presented in Greenberg up to 237
HINT Don't attempt this unless you really feel that you are a practised Java programmer.
PROGRAM No program needed