Grass 01

I’m working on an interactive grass mat with Tim Stutts. Using the subtleties in the grass movements, we can imprint text or figures into realistically rendered grass, projected from above. Here’s my first step. . .

Updated Here: Grass Type

grass01wk5.png

//grass
# define nBlades 10000

int randomX[nBlades];
int randomY[nBlades];
int randomHeight[nBlades];
float randomWindVelocity[nBlades];
float t[nBlades];
float distance[nBlades];
float angle[nBlades];
float sway[nBlades];

void drawBlade2(float x, float y, int i){

	angle[i]=atan2(mouseX-x,mouseY-y); //angle to mouse
	distance[i]=dist(x,mouseX,y,mouseY); //distance to mouse
	float tilt=sin(radians(t[i]))*randomHeight[i]/5;//sway distance

		Vec2d A=Vec2d(x,y);//grass root
			Vec2d B=Vec2d(x*3,y*3+randomHeight[i]*.1);//first control point at 1/4 of height
				Vec2d C=Vec2d(x*3,y*3+randomHeight[i]*.9);
				Vec2d D=Vec2d(x+tilt,y+randomHeight[i]);//grass tip

					if( distance[i]<100){
						sway[i]=randomWindVelocity[i]/50*constrain(angle[i],-1,1);//random velocity * direction in relationt to mouse
					}
					t[i]=t[i]+sway[i]; //sway speed

					//decay
					if (t[i]>.01|| t[i]<-.01){
						t[i]=t[i]*.997;
					}

					glColor3f(.2,(randomHeight[i]/80.0),.15);

					glBegin(GL_LINE_STRIP);
					for (float p=0;p<1.0;p=p+.4){
						float b=1.0-p;

						Vec2d y=A*b*b*b+B*b*b*p+C*p*p*b+D*p*p*p;

						float gradient=p;
						glColor4f(.2*gradient,(randomHeight[i]/60.0)*gradient,.15*gradient,.9);
						glVertex2f(y.x,y.y);
					}
					glEnd();
}