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 › 2d water simulation with refraction
Pages: 1 2 
2d water simulation with refraction (Read 4787 times)
Re: 2d water simulation with refraction
Reply #15 - Mar 23rd, 2010, 4:13am
 
That's ok.

I will post the code here when I get it pretty close to what you are trying to achieve.
Re: 2d water simulation with refraction
Reply #16 - Mar 24th, 2010, 8:21am
 
Thank You Andrew,
in the while i will burn my brain with spaghetti (rectangular) code!
K.I.T [keep in touch]
sh
Re: 2d water simulation with refraction
Reply #17 - Apr 12th, 2010, 7:16am
 
at this point actually - found a simple circular ripple code on openprocessing and apply little changes:

Code:
Ripple[] rip; // Declare the object array
int numRipples = 50; // Max number of ripples
int currentRipple = 0; // To keep track
color bg = 255;

int c1 = 255; // Color array
int c2 = 127;
/*
color[] c = {
color(c1, c2, 0), color(c1, 0, c2), color(c2, c1, 0), color(c2, 0, c1), color(0, c2, c1), };
*/

void setup() {
size(500, 500);
smooth();
stroke(0);
strokeWeight(3);
noFill();
rip = new Ripple[numRipples]; // Create the object
for (int i = 0; i < numRipples; i++) {
rip[i] = new Ripple();
}
}

void draw() {
background(bg);
for (int i = 0; i < numRipples; i++) {
rip[i].resize(); // Change the parameters
rip[i].display(); // Actually draw 'em
}
}

void mousePressed() {
int which = round(random(4)); // pick a color, any color (or the number associateing to that color in the array)
rip[currentRipple].xy(mouseX, mouseY, which); // tell the upcoming ripple where it should be made and what color it should be
currentRipple++; // advance to the next ripple int the array
if (currentRipple >= numRipples) { // Reset if we max out numRipples
currentRipple = 0;
}
}

class Ripple { // The ripple class
float x, y; //
float diameter, alph;
boolean on = false;
color colors;

void xy(float xpos, float ypos, color shade) {
x = xpos;
y = ypos;
on = true;
diameter = 1;
colors = shade;

}

void resize() {
if (on == true) {
if (diameter < 200) {
diameter++;
alph = abs((diameter*1.275)-255);
} else {
on = false;
}
}
}

void display() {
noFill();
// stroke(c[colors], alph);
stroke(0, alph);
strokeWeight(3);
rectMode(CENTER);
rect(x, y, diameter, diameter);
}
}

void keyPressed() {
if (keyCode == ' ') {
if (bg == 0) {
bg = 255;
} else {
bg = 0;
}
draw();
}
}
Pages: 1 2