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();
}
}
}
