Processing 2. Креативное программирование
.pdfJavaScript
setup() Vec2D . Vec2D PVector Processing,. Polygon2D .ToxiclibsSupport:
gfx = new ToxiclibsSupport( this );
draw() for .for Vec2D.containsPoint() ,. ,, , . gfx.polygon2D().
for ( int i = 0; i < 4; i++ ) {
Vec2D m = new Vec2D( mouseX, mouseY );
if ( polygons[i].containsPoint( m ) ) { fill( 255, 64, 0 );
}else { fill( 0 );
}
gfx.polygon2D( polygons[i] );
}
220
10
Android
:
fAndroid SDK
fAndroid
fAndroid
fGPS
f3D Android
fAndroid
Mobile Processing., ProcessingJava, , .,.
Processing 2 Processing : Android mode. Android Emulator Android.
Processing global positioning system (GPS) . AndroidProcessing.
Android
Android SDK
Android .Android SDK Processing, .. Android.
, - , http:// developer.android.com/ sdk/index.html, Android Software Development Kit (SDK) . SDK , -. Documents .
tools android-sdk android. Unix.
Android SDK. Android SDK Platform-tools Android 2.3.3 (API 10)
Install 22 packages, . -, .
222
10
, Processing. ProcessingAndroid. , ,1, Processing 2: -, . , Android SDK, , . Yes :
Android SDK.Choose.
, Android. ,Processing . .
223
Android
SDK Processing , . Android 2.3.3 (API 10), , Processing.API,Android.
Processing Android SDK. Processing. Mac OS X, :
~/Users/username/Library/Processing/preferences.txt
, , android.sdk.path. Processing Android SDK. Mac OS X, Android SDK Documents, :
android.sdk.path=/Users/username/Documents/android-sdk-macosx
Processing SDK , .
Android
, SDK, .Android.Android,.
. . , , , size() -., - , .
float x; float y; float prevX; float prevY; float d; float h;
void setup()
{
size( displayWidth, displayHeight ); background( 0 );
224
10
smooth();
x = random( width ); y = random( height ); prevX = x;
prevY = y;
stroke( 255, 128 );
colorMode( HSB, 360, 100, 100, 100 );
}
void draw()
{
x += random( -30, 30 ); y += random( -30, 30 );
x = constrain( x, 0, width ); y = constrain( y, 0, height );
d = dist( x, y, prevX, prevY );
h = map( d, 0, 42, 0, 360 );
fill( h, 100, 100, 50 ); ellipse( x, y, d, d );
prevX = x; prevY = y;
}
Android Processing IDE, Sketch | Run in Emulator menu Cmd + RMac OS X Ctrl + R Windows Linux.
. - .
Processing, ,.
225
Android
, :
size() Android..: 2D 3D.
226
10
Android size() . ,. , .pde.java, ,Android. :
void setup()
{
size( displayWidth, displayHeight, P3D );
}
.java, Processing:
void setup() {}
public int sketchWidth() { return displayWidth;
}
public int sketchHeight() { return displayHeight;
}
public String sketchRenderer() { return P3D;
}
, ,Android., , -. ,. Android.
, -
sketch.properties AndroidManifest.xml. sketch.propertiesProcessing, Android. AndroidManifest. xml Android, , .
, stop Processing IDE.. ,.
227
Android
Android
, , ,Android. Android ,: , GPS, . .
USB.Settings | Applications | DevelopmentUSB debugging:
. :
float x; float y; float prevX; float prevY; float d; float h;
void setup()
{
size( displayWidth, displayHeight ); background( 0 );
smooth();
x = random( width ); y = random( height ); prevX = x;
prevY = y;
228
10
stroke( 255, 128 );
colorMode( HSB, 360, 100, 100, 100 ); }
void draw()
{
x += random( -30, 30 ); y += random( -30, 30 );
x = constrain( x, 0, width ); y = constrain( y, 0, height );
d = dist( x, y, prevX, prevY );
h = map( d, 0, 42, 0, 360 );
fill( h, 100, 100, 50 ); ellipse( x, y, d, d );
prevX = x; prevY = y;
}
Sketch | Run on Device.
229