Another attempt at making use of the noise() function.
ß e n
/**
* The Rolling Hills of Cramlington - v1.0.
*/
int kWidth = 800 ;
int kHeight = 400 ;
int kPlanes = 8 ;
int kHorizon = kHeight / 2 ;
void setup()
{
size( kWidth, kHeight ) ;
colorMode( RGB, 1.0 ) ;
smooth() ;
}
void draw()
{
background( 1.0 ) ;
//
// Animate using the current time.
//
float m = millis() * 0.01 ;
//
// Draw planes of hills/mountains.
//
for ( int i = 1 ; i <= kPlanes ; ++ i )
{
//
// Front planes scroll faster than abck planes.
//
float t = m * 1.6 * i ;
//
// Work out the baseline for the mountian range.
//
float startY = kHorizon + kHeight * i / kPlanes ;
//
// Scale the noise according to the plane.
// Front planes are stretched horizontally and .
//
float nx = i * 0.2 ;
float hrzScale = (kPlanes - i + 1 ) * 0.001 ;
float vrtScale = kHeight * ( i ) / kPlanes ;
//
// Fade planes from white to grey.
//
float whiteness = 0.95 - ( 0.95 - 0.2 ) * ( i - 1 ) / ( kPlanes - 1 ) ;
stroke( whiteness ) ;
//
// Draw this plane of moutnians.
//
drawNoise( t, nx, hrzScale, vrtScale, startY ) ;
}
}
//
// Draw a mountain range using th noise() function.
//
// t controls the horizontal poisiotn of the mountian range
// nx selects which mountian range
// hrzScale controls how fast the mountains change height horizontally
// vrtScale scales the height of the mountains
//
//
void drawNoise( float t, float nx, float hrzScale, float vrtScale, float startY )
{
beginShape( LINES ) ;
for ( int i = 0 ; i < kWidth ; ++ i )
{
float v = t + i ;
float h = vrtScale * noise( v * hrzScale, nx ) ;
vertex( i, startY ) ;
vertex( i, h ) ;
}
endShape() ;
}
6 comments:
Now that's a bit more like art. A surprisingly restrained pallete, given your previous contributions...
I'm working on the disco version...
ß e n
The perlin function is very useful. I'm about to do a lunar lander clone and can use it for generating landscapes. I've lifted up the Java Perlin source from processing.org so I can port it to Lua!
Regards - John
It's the Rolling Hills of Mare Imbrium at the moment.
Hello
im looking for ben im local and need some help with objective c and c++ conversion. sorry to spam its the only way i could find you
thanks
saul
Hi Saul
No problem.
I'm not sure how much help I can be if at all. Feel free to email me more details if you like and I'll see if it is something I can help with though at the moment I am very busy.
l...d..66@mac.com
b e n
Post a Comment