| 134 | } |
| 135 | |
| 136 | void perlinTestApp::draw() |
| 137 | { |
| 138 | #if defined( CINDER_LINUX ) || defined( CINDER_MAC ) |
| 139 | // On Linux/Mac, render to an image surface and then draw to window |
| 140 | cairo::SurfaceImage surface( getWindowWidth(), getWindowHeight(), true ); |
| 141 | cairo::Context ctx( surface ); |
| 142 | #else |
| 143 | cairo::Context ctx( cairo::createWindowSurface() ); |
| 144 | #endif |
| 145 | ctx.copySurface( *mNoiseSurface, mNoiseSurface->getBounds() ); |
| 146 | |
| 147 | // draw the gradient |
| 148 | ctx.setSourceRgb( 1.0, 0.5, 0.25 ); |
| 149 | ctx.moveTo( mGradientPos ); |
| 150 | vec3 norm = mPerlin.dfBm( vec3( mGradientPos.x, mGradientPos.y, mTime ) * mFrequency ) * 20.0f; |
| 151 | ctx.lineTo( mGradientPos.x + norm.x, mGradientPos.y + norm.y ); |
| 152 | ctx.stroke(); |
| 153 | |
| 154 | // draw gradient vector field |
| 155 | if( mDrawLines ) { |
| 156 | ctx.setLineWidth( 1.0f ); |
| 157 | ctx.setSourceRgba( 1.0, 1.0, 0.05, 0.25 ); |
| 158 | for( int y = 0; y < getWindowHeight(); y += 20 ) { |
| 159 | for( int x = 0; x < getWindowWidth(); x += 20 ) { |
| 160 | ctx.moveTo( vec2( x, y ) ); |
| 161 | vec3 norm = mPerlin.dfBm( vec3( x, y, mTime ) * mFrequency ) * 20.0f; |
| 162 | if( mDrawNormalized ) { |
| 163 | if( length2( vec2( norm.x, norm.y ) ) > 0 ) |
| 164 | ctx.lineTo( vec2( x, y ) + normalize( vec2( norm.x, norm.y ) ) * 20.0f ); |
| 165 | } |
| 166 | else |
| 167 | ctx.lineTo( vec2( x, y ) + vec2( norm.x, norm.y ) ); |
| 168 | /*float thisVal = mPerlin.fBm( vec3( x, y, mTime ) * mFrequency ); |
| 169 | float rightVal = mPerlin.fBm( vec3( x, y, mTime ) * mFrequency + vec3( 0.001f, 0, 0 ) ); |
| 170 | float downVal = mPerlin.fBm( vec3( x, y, mTime ) * mFrequency + vec3( 0, 0.001f, 0 ) ); |
| 171 | vec2 deriv = vec2( ( rightVal - thisVal ) / 0.001f, ( downVal - thisVal ) / 0.001f ); |
| 172 | ctx.lineTo( vec2( x, y ) + deriv.normalized() * 20.0f );*/ |
| 173 | } |
| 174 | } |
| 175 | ctx.stroke(); |
| 176 | } |
| 177 | |
| 178 | #if defined( CINDER_LINUX ) || defined( CINDER_MAC ) |
| 179 | // Convert to Cinder surface and draw to window |
| 180 | Surface8u cinderSurface = surface.getSurface(); |
| 181 | auto tex = gl::Texture2d::create( cinderSurface ); |
| 182 | gl::draw( tex ); |
| 183 | #endif |
| 184 | } |
| 185 | |
| 186 | |
| 187 | #if defined( CINDER_LINUX ) || defined( CINDER_MAC ) |
nothing calls this directly
no test coverage detected