Processing 2. Креативное программирование
.pdf3D:
beginShape(). ,, beginShape(). TRIANGLE_STRIP QUAD_STRIP,. for.
3D .. .
640 x 640 data. , , -2, , 2D.
, OpenGL PImage .
import processing.opengl.*; PImage texture1;
PImage texture2;
setup() .
void setup()
{
size( 640, 480, OPENGL ); noStroke();
texture1 = loadImage("stones.jpg"); texture2 = loadImage("lines.jpg");
}
80
3
draw() .texture(). - . IMAGE.:
background( 255 );
textureMode( IMAGE ); pushMatrix();
translate( width/4, height/2, 0 ); rotateY( radians( frameCount ) ); beginShape();
texture( texture1 ); vertex( -100, -100, 0, 0 );
vertex( 100, -100, 640, 0 ); vertex( 100, 100, 640, 640 ); vertex( -100, 100, 0, 640 ); endShape( CLOSE ); popMatrix();
NORMAL. --. ,vertex() .
textureMode( NORMAL ); pushMatrix(); translate( width*.75, height/2, 0 ); rotateY( radians( -frameCount ) ); beginShape();
texture( texture2 ); vertex( -100, -100, 0, 0 ); vertex( 100, -100, 1, 0 ); vertex( 100, 100, 1, 1 ); vertex( -100, 100, 0, 1 ); endShape( CLOSE ); popMatrix();
81
3D:
; , , .
- . , .
ftexture() Processing, -.
ftextureMode() , Processing. IMAGE NORMAL.IMAGE, -. NORMAL0 1.
fvertex() .,. IMAGE vertex( 100, -100, 640, 0 ) (100, -100),(640, 0) , .NORMAL (1, 0).
82
3
3D
3D, .camera().
, OpenGL 640 x 480 ., x z -setup(). .
import processing.opengl.*;
float x; float z;
void setup()
{
size( 640, 480, OPENGL );
x = 0; z = 0;
noStroke();
}
. ,. fill() ,. , ,Processing.
background( 255 ); lights();
beginShape(); fill( 255, 0, 0 );
vertex( 0, height, 0); fill( 255, 255, 0 );
vertex( 0, height, -1000 ); fill( 0, 255, 0 );
vertex( width, height, -1000 ); fill( 0, 0, 255 );
vertex( width, height, 0 ); endShape(CLOSE);
83
3D:
fill( 255 ); pushMatrix();
translate( width/2, height-50, -500 ); box( 100 );
popMatrix();
, , ., ,. lights().
x = cos( radians( frameCount ) ) * 1000; z = sin( radians( frameCount ) ) * 1000;
camera( x, 0, z, width/2, height-50, -500, 0, 1, 0 );
, , camera(). . ..
84
3
camera() . camera()Processing . .x, y z “ ” .x, y z .. -1.0 1.0; , -1.0, 0.0 1.0. (0, 1, 0). (0, -1, 0),180 Y ..
camera() . -PeasyCam .http://mrfeinberg.com/peasycam/.- Obsessive Camera Direction (OCD) ;: http://gdsstudios.com/processing/libraries/ocd/.
85
4
:
fCSV
fXML
fArrayList
fHashMap
, , .. XML CSV ,, .: ArrayList HashMap. ,.
. .
. -My life as a progress meter fridge.
http://opensourcepoetry. org/index.html?poemDisplay.php? poem_id=765. data Processing.
String. loadStrings()setup()
String.
String[] textLines;
void setup()
{
size( 640, 200 ); smooth();
textLines = loadStrings("poem.txt");
noLoop();
}
draw(), ..
void draw()
{
background( 255 ); translate( 20, height/2 );
stroke( 128 ); fill( 255, 128 );
for ( int i = 0; i < textLines.length; i++ ) { float d = textLines[i].length();
ellipse( i * 30, 0, d, d ); println( i + ". " + textLines[i] );
}
}
88
4
, :
PDE , .
loadStrings() .String. ., println( textLines[0] ). , , textLines.length.length - 1.println( textLines[ textLines.length - 1 ] ).
89