Случайные движения и шум Перлина. Графика: вывод частей изображения

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

OpenFrameworks

.
:

:
www.uralvision.blogspot.com


perevalovds@gmail.com

/ 2011


(x,y).
"",
(x,y), (x+x1, y+y1),
x1 y1 - , "".
x1, y1?
1.
x1 = ofRandom(-10,10);
y1 = ofRandom(-10, 10);
. - ,
.


2.
, .
float jumpTime = 0;

// ,
//
float x1=0; float y1=0;
//
float x1Target=0; float y1Target=0; // ,
//
void testApp::update() {
float time = ofGetElapsedTimef (); //
if ( time > jumpTime + 0.5 ) {
// 0.5
jumpTime = time;
//
x1Target = ofRandom( -10, 10 ); // ,
y1Target = ofRandom( -10, 10 );
}
x1 = 0.95 * x1 + 0.05 * x1Target;
// (x1Target, y1Target)
y1 = 0.95 * y1 + 0.05 * y1Target;
}
, .


(.) 1983
.
Perlin noise ( ,
- .

.
, ..
( , - ,

. 2001 .)
- , .
Random .

.


- f( t ).
.
t .
openFrameworks
float ofNoise( float t )
- [-1, 1].
ofNoise - ,
.

t , ofNoise( t )
. , .
ofNoise( t ) . ?


.
3.
float tX, tY;

//

void testApp::setup()
{
tX = ofRandom( 0, 1000 );
tY = ofRandom( 0, 1000 );
}

//

void testApp:: update()


{
float time = ofGetElapsedTimef();
float velocity = 0.5;
float x1 = 10 * ofNoise( tX + time * velocity );
float y1 = 10 * ofNoise( tY + time * velocity );

//
//"" [-10,10]

}
void testApp::draw()
{
ofCircle( 100 + x1, 200 + y1, 20 );
}

//

.
http://vimeo.com/27772326


ofImage,
. ?
1.
,
image.pixels() image1.setFromPixels(...).
,
.
2.
2. OpenGL.
OpenGL,
.
.


- Rubber Mirror
http://www.youtube.com/watch?v=tk-g-sYb7-I

.
,
, .
. ,
. , .


ofTexture & texture = image.getTextureReference();

//

texture.bind(); // - OpenGL ,
texture

//

// , ,
,
ofSetColor( 255, 255, 255 );
glBegin( GL_QUADS ); // OpenGL : 4-
glTexCoord2f( 50, 50 ); //1- ,
glVertex2f( 100, 100 );
//
glTexCoord2f( 150, 50 ); //2-
glVertex2f( 300, 100 );
glTexCoord2f( 150, 150 ); //3-
glVertex2f( 250, 300 );
glTexCoord2f( 50, 150 ); //4-
glVertex2f( 150, 250 );
//... 2-, 3-, 4-, .
glEnd();
// 4-
tex.unbind();
// , bind
. 4-,
. - 4-
.


( )
n - 4-,
vector<float> pointTexture( 4 * 2 * n ); // ,
vector<float> pointScreen( 4 * 2 * n ); // ,
,
x1, y1, x2, y2, x3, y3, x4, y4 - ,
x1, y1, x2, y2, x3, y3, x4, y4 - ,
... n- .

:
ofTexture & texture = image.getTextureReference();
texture.bind();
ofSetColor( 255, 255, 255 );
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer( 2, GL_FLOAT, 0, &pointTexture[0] );
glVertexPointer(2, GL_FLOAT, 0, &pointScreen[0]);
// 2 , , x,y ( x,y,z).
// - pointTexture( 4 * 3 * n ), pointScreen( 4 * 3 * n ).
glDrawArrays(GL_QUADS, 0, n * 4);
// - n * 4
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
tex.unbind();

I
1.
image.loadImage( "image.png" );

2.
.
of
(tX,tY)

tX = 0.1 * time + i;
tY = 0.1 * time + j;
(i,j) -
.
,
.

II

vector<ofPoint> p;
p.resize( 100 );
for (int i=0; i<p.size(); i++) {
p[i] = ofPoint( ofRandom( 200, 600 ), ofRandom( 200, 600 ) );
}
.
vector<ofPoint> v, mass;
v.resize( 100 ); // -
m.resize( 100 ); // -
, .
.

You might also like