Monday 27 July 2009

Program written

I've finally written the program for this chunk. It justs needs commenting and then I can write the text explanation:


float rotation;

int maxXCount;
int maxYCount;

int minXCount;
int minYCount;

int xCount;
int yCount;

boolean xIncreasing;
boolean yIncreasing;

float a;
float b;
float c;

int sideLength = 5;

void setup() {

size(900, 450, P3D);

c = sideLength;
a = c / 2;
b = sin(radians(60)) * c;

maxXCount = 80;
maxYCount = 80;

minXCount = 1;
minYCount = 1;

xCount = minXCount;
yCount = minYCount;

xIncreasing = true;
yIncreasing = true;

rotation = -PI;

frameRate(8);

}

void draw() {

determineDirection();

background(0);

rotateX(1.0);

drawLeftWave();

drawRightWave();

determineRotation();

determineIncreasingStatus();

}

void determineRotation() {
// reset rotation if maximum rotation reached
if (rotation > PI) {
rotation = -PI;
}
// increase the rotation with each draw()
rotation += 0.01;
}

void drawLeftWave() {

fill(238, 238, 0, 150);

for (int i = 0; i <= xCount; i++) {
pushMatrix();
translate(10 * i, 0, 0);

for (int j = 0; j <= yCount; j++) {
translate(10, 10, 0);
rotateY(rotation);
drawHexagon();
drawLines();
}

popMatrix();

}
}

void drawRightWave() {

fill(165, 42, 42, 150);

for (int i = 0; i <= xCount; i++) {
pushMatrix();
translate(width - (10 * i), 0, 0);

for (int j = 0; j <= yCount; j++) {
translate(10, 10, 0);
rotateY(rotation);
drawHexagon();
drawLines();
}

popMatrix();

}
}

void determineDirection() {
if (xIncreasing) {
xCount++;
}
else {
xCount--;
}

if (yIncreasing) {
yCount++;
}
else {
yCount--;
}
}

void determineIncreasingStatus() {

if (xCount > maxXCount) {
xIncreasing = false;
}

if (yCount > maxYCount) {
yIncreasing = false;
}

if (xCount < minXCount) {
xIncreasing = true;
}

if (yCount < minYCount) {
yIncreasing = true;
}

}

void drawHexagon() {
// draw hex shape
beginShape();
vertex(0, b);
vertex(a, 0);
vertex(a + c, 0);
vertex(2 * c, b);
vertex(a + c, 2 * b);
vertex(a + c, 2 * b);
vertex(a, 2 * b);
vertex(0, b);
endShape();
}

void drawLines() {

line(0, b, 2 * a, b);
line(a, 0, 2 * a, b);
line(a + c, 0, 2 * a, b);
line(2 * c, b, 2 * a, b);
line(a + c, 2 * b, 2 * a, b);
line(a + c, 2 * b, 2 * a, b);
line(a, 2 * b, 2 * a, b);

}

No comments:

Post a Comment