« Luke Moloney | Main | 541 Homework, part 2 »

Processing HW:

my internet was down the entire weekend, so the majority of the hw is quarantined on my desktop.
However, i do have the code for the third example on page 192(?), which uses code and concepts from the other 5. Code now fixed

Code for the processing hw for 541 after the jump:

//glocal vars int arrayCounter = 0; Droplet [] dropSpread = { null, null, null};

//droplet class
class Droplet{
//the ripple's origin
int centerX;
int centerY;

//the ripple's lifespan, 0 == the ripple has run its course
int lifeSpan;
//should never be greater than 4
int maxPeaks = 4;

//constructors
//default
Droplet(){
centerX = centerY = 0;
lifeSpan = 0;
}
//generic
Droplet(int centX, int centY, int longevity){
centerX = centX;
centerY = centY;
lifeSpan = longevity;
drawDrop();
}

//draws the current iteration of the drop
void drawDrop(){
//println("ripple call number: " + this.lifeSpan);
if (lifeSpan > 0){
//println("largest, final call");
for (int x = 1; x < maxPeaks; x++){
ellipse(centerX, centerY, (20-2*this.lifeSpan)*(10/x), (20-2*this.lifeSpan)*(10/x));
ellipse(centerX, centerY, (18-2*this.lifeSpan)*(9/x), (18-2*this.lifeSpan)*(9/x));
//debug
//println("param outer: " + centerX +" "+ centerY +" "+ (20-2*this.lifeSpan)*(10/x) +" "+ (20-2*this.lifeSpan)*(10/x));
//println("param inner: " + centerX +" "+ centerY +" "+ (18-2*this.lifeSpan)*(9/x) +" "+ (18-2*this.lifeSpan)*(9/x));
}
lifeSpan--;
}
else{
//no longer draw, add kill call here
println("need method to remove from screen");
}
}
}


//programme bs
void setup(){
frameRate(4);
background(0,0,0);
size(400,400);
}

void draw(){
if( arrayCounter > 0){
for (int x = 0; x < arrayCounter; x++){
if(dropSpread[x].lifeSpan >= 0){
dropSpread[x].drawDrop();
}
}
}
}

void mousePressed(){
//reset counter
if (arrayCounter == 3) arrayCounter = 0;
//create new Droplet
//add droplet to the existing array at the current position
dropSpread[arrayCounter] = new Droplet(mouseX, mouseY, 8);
arrayCounter++;
println("cel in array: " + arrayCounter);
}



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 November 13, 2006 1:27 PM.

The previous post in this blog was Luke Moloney.

The next post in this blog is 541 Homework, part 2.

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

Powered by
Movable Type 3.31