« November 2008 | Main | February 2009 »

January 2009 Archives

January 29, 2009

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

CTIN544 - processing script 2

//download the image to the data folder, and choose a movieclip for viewing
kid.png


import processing.video.*;
Movie myMovie;
PImage img;
int pwidth = 194;
int pheight = 246;

void setup() {
size(640, 480);
frameRate(30);

//choose a movieclip, replace the string below with its name
myMovie = new Movie(this, "P1040237.mov");
// Prints the duration of the movie
println(myMovie.duration());
myMovie.play();
myMovie.loop();

img = loadImage("kid.png");
}

void draw() {
if(myMovie.available()) {
myMovie.read();
}
image(myMovie, 0, 0);
blend(img, 0, 0, pwidth, pheight, mouseX-pwidth/2, mouseY-pheight/2, pwidth, pheight, EXCLUSION);
//stroke(255);
//fill(255);
//ellipse(mouseX,mouseY,150,150);
}


About January 2009

This page contains all entries posted to Hua Chen in January 2009. They are listed from oldest to newest.

November 2008 is the previous archive.

February 2009 is the next archive.

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

Powered by
Movable Type 3.31