We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › why my splash effect look so strange
Page Index Toggle Pages: 1
why my splash effect look so strange? (Read 348 times)
why my splash effect look so strange?
May 8th, 2009, 2:23am
 
I'm a new in Processing ,recently I'm trying to learn the effect but why my effect look so strange? can someone else help me?

here is my code: Code:
int[] oldBuffer,newBuffer; 
float damping =0.9; // non-integer between 0 and 1
PImage bg;

void setup() {
size(320, 200);

oldBuffer = new int[width * height];
newBuffer = new int[width * height];

bg = loadImage("111.JPG");
background(bg);
}

void draw() {
int[] tempBuffer = new int[width * height];
boolean Changed;

Changed = processWater();
if (Changed == true) {
renderWater();
}

tempBuffer = newBuffer;
newBuffer = oldBuffer;
oldBuffer = tempBuffer;
}

void mousePressed() {
newBuffer[mouseX+mouseY*width] += 5000;
oldBuffer[mouseX+mouseY*width] += 5000;
}

boolean processWater() {
int x, y,tempHeight;
boolean Changed = false;
for (x = 1; x < width-1; x ++) {
for(y=1;y<height-1;y++){
int loc=x+y*width;
tempHeight = oldBuffer[loc - 1] + oldBuffer[loc + 1];
tempHeight += oldBuffer[loc -width] + oldBuffer[loc +width];
tempHeight = (tempHeight/2) - newBuffer[loc];
tempHeight *= damping;
if (newBuffer[loc] != tempHeight) {
Changed = true;
newBuffer[loc] = tempHeight;
}
}
}
return Changed;
}

void renderWater() {
int x, y, xOffset, yOffset;
color tempColor;
float shading;
loadPixels();
for (x =1; x < width-1; x ++) {
for(y=1;y<height-1;y++){
int loc=x+y*width;
xOffset = newBuffer[loc - 1] - newBuffer[loc + 1];
yOffset = newBuffer[loc - width] - newBuffer[loc + width];
int offsetLoc=constrain((x+xOffset)+(y+yOffset)*width,0,(width*height-1));
tempColor = bg.pixels[offsetLoc];
pixels[loc] = tempColor;
}
}
updatePixels();
}
Page Index Toggle Pages: 1