« The Best Recombinant Narrative Ever? | Main | CTIN544 - processing script 2 »

CTIN544 - processing script 1

class Cell {
float x,y; // x,y location
float w,h; // 2 parameters for the ellipse
float angle; // angle for oscillating brightness

// Cell Constructor
Cell(float tempX, float tempY, float tempW, float tempH, float tempAngle) {
x = tempX;
y = tempY;
w = tempW;
h = tempH;
angle = tempAngle;
}

void oscillate() {
if (count >= da){
count = 0;
angle = 90;
}
else if ((count > xiao) && (count < da)){
angle += 0.05;
}
count++;
}

void display() {
stroke(255);
// Color calculated using sine wave
fill(127+127*tan(angle));
ellipse(x+w/2,y+w/2,w,h);
}
}

// 2D Array of objects
Cell[][] grid;

// Number of columns and rows in the grid
int cols = 10;
int rows = 10;
int count = 0;
int xiao= 1000;
int da = 1100;

void setup() {
size(600,600);
grid = new Cell[cols][rows];
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
// Initialize each object
grid[i][j] = new Cell(i*60,j*60,60,60,i+j);
}
}
}

void draw() {
background(0);
// The counter variables i and j are also the column and row numbers and
// are used as arguments to the constructor for each object in the grid.
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
// Oscillate and display each object
grid[i][j].oscillate();
grid[i][j].display();
}
}
}

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on January 29, 2009 5:10 PM.

The previous post in this blog was The Best Recombinant Narrative Ever?.

The next post in this blog is CTIN544 - processing script 2.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.31