March 19, 2011 0

Rock Skipping

By in Code for Art, Spring 2011


Video with commentary

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.

I went through a few iterations of this project, mostly because we learned how to utilize vectors and classes during the duration of the assignment. My first step was to create the ripple effect. I drew concentric ellipses and did not refresh the background.

I ultimately decided to refresh the background at each frame in order to feel that the ripple was actually growing and moving along the water, instead of building.

In my next iteration, I used the mouseMoved function to create the ripples, instead of a mouseClicked. I felt this interaction was more natural and even random (vs. deliberate). I really loved this effect, but I was missing the rock. My finally iteration, posted at the top, includes the Rock class and interaction.

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.

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

Download full source here.

Tags: , ,

Leave a Reply