Processing 2. Креативное программирование
.pdfProcessing
, , , .1000 .
void setup()
{
size( 640, 480 ); smooth();
}
void draw()
{
background( 0 );
for ( int i = 0; i < 1000; i++ ) { fill( random( 255 ), 64 ); stroke( 255, 128 );
ellipse( random( width ), random( height ), 40, 40 );
}
if ( keyPressed ) {
saveFrame("images/artwork-####.png");
}
}
:
110
5
draw() keyPressed.true - false . saveFrame(). . images/ , Processing images. . #### ., . -. .png, Processing PNG..jpg, JPEG. .jpg,
.png, .tif .tga.
. Sketch | Show Sketch Folder .
, , , -. , Processing.ProcessingMac OS X, Windows Linux. , .
. , . displayWidth displayHeight size().
float x; float y; int b;
void setup()
{
size( displayWidth, displayHeight ); smooth();
x = 0; y = 0;
background( 0 );
111
Processing
noFill();
}
void draw()
{
b++;
if ( b > 255 ) { b = 0;
}
x += random( 2, 6 ); if ( x > width ) {
x = 0;
y += random( 20, 40 ); if ( y > height ) {
y = 0;
}
}
stroke( 0, random( 255 ), b, 64 ); float r = random( 6, 60 ); ellipse( x, y, r, r );
}
. File | Export Application Cmd + E Mac, Ctrl + E Windows Linux. Export Options ,. Export, .
Processing Java. Java source. Processing Java ..
,.,PDF. , Processing, , , , . Processing , PDF.
112
5
, - PDF.Sketch | Import Library | pdf.savePDF.
import processing.pdf.*;
boolean savePDF = false;
void setup()
{
size( 640, 480 ); smooth();
rectMode( CENTER ); stroke(0);
}
draw() savePDF Processing,PDF. , beginRecord()endRecord() PDF. keyPressed()savePDF.
void draw()
{
if ( savePDF ) {
beginRecord( PDF, "pdf/myartwork-####.pdf" );
}
background( 0 );
for ( int i = 0; i < 1000; i++ ) {
fill( 0, random( 255 ), random( 255 ), 64 ); pushMatrix();
translate( random( width ), random( height ) ); rotate( radians( random( 360 ) ) );
rect( 0, 0, 50, 50 ); popMatrix();
}
if ( savePDF ) { endRecord(); savePDF = false;
}
}
void keyPressed()
113
Processing
{
if ( key == 's' ) { savePDF = true;
}
}
, S. PDFpdf .
beginRecord() Processing, ,. ;PDF. - .pdf/myartwork-####.pdf. pdf;
#### .endRecord() , Processing .
PDF Processing. ,PDF PDF. . , , Processing : http:// processing.org/reference/ libraries/pdf/index.html.
, . , , PDF, .
. A4. 210 x 297 8.2677 x 11.6929 .595 x 842 . ,A4, :
void setup()
{
size( 595, 842 );
}
114
5
, , , Processing72 (DPI). ,. 25.4 . , .. 72. 8.5 x 11 .:
8.5 x 72 = 612
11 x 72 = 792
. ,.
, PrintWritercreateWriter().
PrintWriter textFile;
void setup()
{
textFile = createWriter("files/randomnumbers.txt");
}
draw() .frameCount 1000 .
void draw()
{
textFile.println( random( 200 ) ); if ( frameCount >= 1000 ) {
textFile.flush();
textFile.close();
exit();
}
}
115
Processing
createWriter() . - ( String) . , ,.
draw() textFile.println().println(), , .
flush(), close(). ,, .
3D
, PDF.ProcessingCinema 4D CAD-, .Processing DXF .
DXF OpenGL. Sketch | Import Library . saveDXF. , savePDFPDF.
import processing.opengl.*; import processing.dxf.*;
boolean saveDXF = false;
void setup()
{
size( 640, 480, OPENGL ); smooth();
}
116
5
draw() beginRaw() endRaw()..
void draw()
{
if ( saveDXF == true ) {
beginRaw( DXF, "files/myCubes.dxf" );
}
lights();
background( 255 ); fill( 128 ); noStroke();
for ( int i = 0; i < 100; i++ ) { pushMatrix();
translate(random(width), random(height), random(-1000,
0));
pushMatrix();
rotateX( radians( random( 360 ) ) ); rotateY( radians( random( 360 ) ) ); rotateZ( radians( random( 360 ) ) ); box( 50 );
popMatrix();
popMatrix();
}
if ( saveDXF == true ) { endRaw();
} saveDXF = false;
}
void keyPressed()
{
if ( key == 's' ) { saveDXF = true;
}
}
117
Processing
beginRaw() endRaw(). PDF, . ,
.dxf. beginRecord() DXF PDF, -.
DXF eDrawings Viewer, Windows Mac OS X. : http:// www.edrawingsviewer.com/. ,- :
118
5
Hemesh Toxiclibs. STL,.
, Processing ., . , .
setup() 1000. , ,.
int[] numbers = new int[1000];
void setup()
{
for ( int i = 0; i < numbers.length; i++ ) { if ( random( 100 ) < 50 ) {
// uppercase A - Z
numbers[i] = floor( random( 65, 91 ) ); } else {
// lowercase a - z
numbers[i] = floor( random( 97, 123 ) );
}
}
}
draw()saveBytes() .
void draw()
{
if ( keyPressed ) {
byte[] bytes = byte( numbers );
saveBytes( "strangefile-"+frameCount+".zzz", bytes
);
exit();
}
}
119