Rock Skipping

Description

I wanted to create a simulation of skipping rocks on water. Depending on the rock skips (or jumps) along the water, the water ripples a certain amount of times, with each hit, around the rock’s point of contact. I wanted to randomly generating beautiful ripple effects to simulate the rock skipping experience.

Precedents and inspirations can be viewed in my project proposal.

Code

I ended up using vectors and classes to draw the ripples and rocks, respectively. I developed a Rock class in order to create instances of the rock and had to store the “skip” points, the point where the rock “bounces” on the water, as a vector of an ofPoint in order to be able to draw a ripple at that point. Below is the section of my code that contains the rock skips and ripple draw.
[cpp]
void testApp::update(){
//if the rock is at a skip point, draw a ripple
if (rocks[i].rockPosition.y >= rocks[i].skip.y) {
float width = 0;
w.push_back( width );

float height = 0;
h.push_back( height );

ofPoint pos;
pos.x = rocks[i].skip.x;
pos.y = rocks[i].skip.y;
startPositions.push_back( pos );

int opacity = 255;
o.push_back( opacity );
}
}
[/cpp]

Download full source here.