├── 9781484227183.jpg
├── LICENSE.txt
├── README.md
├── appendix a
├── layouts
│ ├── .idea
│ │ ├── compiler.xml
│ │ ├── copyright
│ │ │ └── profiles_settings.xml
│ │ ├── encodings.xml
│ │ ├── gradle.xml
│ │ ├── misc.xml
│ │ ├── modules.xml
│ │ └── runConfigurations.xml
│ ├── app
│ │ ├── build.gradle
│ │ ├── libs
│ │ │ └── processing-core.jar
│ │ ├── proguard-rules.pro
│ │ └── src
│ │ │ ├── androidTest
│ │ │ └── java
│ │ │ │ └── processing
│ │ │ │ └── book
│ │ │ │ └── layouts
│ │ │ │ └── ExampleInstrumentedTest.java
│ │ │ ├── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── assets
│ │ │ │ └── mosaic.jpg
│ │ │ ├── java
│ │ │ │ └── processing
│ │ │ │ │ └── book
│ │ │ │ │ └── layouts
│ │ │ │ │ ├── MainActivity.java
│ │ │ │ │ └── MySketch.java
│ │ │ └── res
│ │ │ │ ├── layout
│ │ │ │ ├── activity_main.xml
│ │ │ │ └── content_main.xml
│ │ │ │ ├── menu
│ │ │ │ └── menu_main.xml
│ │ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ │ └── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ └── test
│ │ │ └── java
│ │ │ └── processing
│ │ │ └── book
│ │ │ └── layouts
│ │ │ └── ExampleUnitTest.java
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ └── settings.gradle
└── listing_a_1
│ ├── code
│ └── sketch.properties
│ ├── data
│ └── World-map.svg
│ └── listing_a_1.pde
├── chapter 1
├── circle
│ ├── circle.pde
│ └── code
│ │ └── sketch.properties
└── listing_1_1
│ ├── code
│ └── sketch.properties
│ └── listing_1_1.pde
├── chapter 10
├── listing_10_1
│ ├── code
│ │ └── sketch.properties
│ └── listing_10_1.pde
├── listing_10_2
│ ├── code
│ │ └── sketch.properties
│ └── listing_10_2.pde
├── listing_10_3
│ ├── code
│ │ └── sketch.properties
│ └── listing_10_3.pde
├── listing_10_4
│ ├── code
│ │ └── sketch.properties
│ └── listing_10_4.pde
└── listing_10_5
│ ├── code
│ └── sketch.properties
│ └── listing_10_5.pde
├── chapter 11
├── listing_11_1
│ ├── code
│ │ └── sketch.properties
│ └── listing_11_1.pde
├── listing_11_2
│ ├── code
│ │ └── sketch.properties
│ └── listing_11_2.pde
├── listing_11_3
│ ├── code
│ │ └── sketch.properties
│ └── listing_11_3.pde
├── listing_11_4
│ ├── code
│ │ └── sketch.properties
│ └── listing_11_4.pde
├── listing_11_5
│ ├── code
│ │ └── sketch.properties
│ └── listing_11_5.pde
├── listing_11_6
│ ├── code
│ │ └── sketch.properties
│ └── listing_11_6.pde
└── listing_11_7
│ ├── code
│ └── sketch.properties
│ ├── data
│ ├── FullMoon2010.jpg
│ └── moon.png
│ └── listing_11_7.pde
├── chapter 12
├── listing_12_1
│ ├── code
│ │ └── sketch.properties
│ └── listing_12_1.pde
├── listing_12_10
│ ├── code
│ │ └── sketch.properties
│ └── listing_12_10.pde
├── listing_12_11
│ ├── code
│ │ └── sketch.properties
│ └── listing_12_11.pde
├── listing_12_12
│ ├── code
│ │ └── sketch.properties
│ └── listing_12_12.pde
├── listing_12_13
│ ├── code
│ │ └── sketch.properties
│ └── listing_12_13.pde
├── listing_12_2
│ ├── code
│ │ └── sketch.properties
│ └── listing_12_2.pde
├── listing_12_3
│ ├── code
│ │ └── sketch.properties
│ └── listing_12_3.pde
├── listing_12_4
│ ├── code
│ │ └── sketch.properties
│ └── listing_12_4.pde
├── listing_12_5
│ ├── code
│ │ └── sketch.properties
│ └── listing_12_5.pde
├── listing_12_6
│ ├── code
│ │ └── sketch.properties
│ └── listing_12_6.pde
├── listing_12_7
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── sensor-data.csv
│ └── listing_12_7.pde
├── listing_12_8
│ ├── code
│ │ └── sketch.properties
│ └── listing_12_8.pde
├── listing_12_9
│ ├── code
│ │ └── sketch.properties
│ └── listing_12_9.pde
└── runnning_tree
│ ├── AndroidManifest.xml
│ ├── code
│ └── sketch.properties
│ ├── icon-144.png
│ ├── icon-192.png
│ ├── icon-36.png
│ ├── icon-48.png
│ ├── icon-72.png
│ ├── icon-96.png
│ ├── preview_circular.png
│ ├── preview_rectangular.png
│ └── runnning_tree.pde
├── chapter 13
├── listing_13_1
│ ├── code
│ │ └── sketch.properties
│ └── listing_13_1.pde
├── listing_13_10
│ ├── code
│ │ └── sketch.properties
│ └── listing_13_10.pde
├── listing_13_11
│ ├── code
│ │ └── sketch.properties
│ └── listing_13_11.pde
├── listing_13_12
│ ├── code
│ │ └── sketch.properties
│ └── listing_13_12.pde
├── listing_13_13
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ ├── genera.py
│ │ └── points.txt
│ └── listing_13_13.pde
├── listing_13_14
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ ├── Deer.obj
│ │ ├── Raptor.mtl
│ │ ├── Raptor.obj
│ │ ├── lowpolytree.mtl
│ │ ├── lowpolytree.obj
│ │ ├── raptor.jpg
│ │ ├── raptor_normal.jpg
│ │ ├── rocket.mtl
│ │ ├── rocket.obj
│ │ └── rocket.png
│ └── listing_13_14.pde
├── listing_13_15
│ ├── code
│ │ └── sketch.properties
│ └── listing_13_15.pde
├── listing_13_16
│ ├── code
│ │ └── sketch.properties
│ └── listing_13_16.pde
├── listing_13_17
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── earthmap1k.jpg
│ └── listing_13_17.pde
├── listing_13_18
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ ├── shiva.jpg
│ │ ├── tiger.png
│ │ └── woodstock.png
│ └── listing_13_18.pde
├── listing_13_19
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ ├── shiva.jpg
│ │ ├── tiger.png
│ │ └── woodstock.png
│ └── listing_13_19.pde
├── listing_13_2
│ ├── code
│ │ └── sketch.properties
│ └── listing_13_2.pde
├── listing_13_20
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ ├── dirt.jpg
│ │ └── grass.png
│ └── listing_13_20.pde
├── listing_13_3
│ ├── code
│ │ └── sketch.properties
│ └── listing_13_3.pde
├── listing_13_4
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── mosaic.jpg
│ └── listing_13_4.pde
├── listing_13_5
│ ├── code
│ │ └── sketch.properties
│ └── listing_13_5.pde
├── listing_13_6
│ ├── code
│ │ └── sketch.properties
│ └── listing_13_6.pde
├── listing_13_7
│ ├── code
│ │ └── sketch.properties
│ └── listing_13_7.pde
├── listing_13_8
│ ├── code
│ │ └── sketch.properties
│ └── listing_13_8.pde
└── listing_13_9
│ ├── code
│ └── sketch.properties
│ └── listing_13_9.pde
├── chapter 14
├── listing_14_1
│ ├── code
│ │ └── sketch.properties
│ └── listing_14_1.pde
├── listing_14_10
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── dodecahedron.obj
│ └── listing_14_10.pde
├── listing_14_11
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── dodecahedron.obj
│ └── listing_14_11.pde
├── listing_14_12
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── dodecahedron.obj
│ └── listing_14_12.pde
├── listing_14_13
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── dodecahedron.obj
│ └── listing_14_13.pde
├── listing_14_2
│ ├── code
│ │ └── sketch.properties
│ └── listing_14_2.pde
├── listing_14_3
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── mosaic.jpg
│ └── listing_14_3.pde
├── listing_14_4
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── dodecahedron.obj
│ └── listing_14_4.pde
├── listing_14_5
│ ├── code
│ │ └── sketch.properties
│ └── listing_14_5.pde
├── listing_14_6
│ ├── code
│ │ └── sketch.properties
│ └── listing_14_6.pde
├── listing_14_7
│ ├── code
│ │ └── sketch.properties
│ └── listing_14_7.pde
├── listing_14_8
│ ├── code
│ │ └── sketch.properties
│ └── listing_14_8.pde
└── listing_14_9
│ ├── code
│ └── sketch.properties
│ └── listing_14_9.pde
├── chapter 15
├── listing_15_1
│ ├── code
│ │ └── sketch.properties
│ └── listing_15_1.pde
├── listing_15_2
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ ├── cross-icon.png
│ │ ├── left-icon.png
│ │ └── right-icon.png
│ └── listing_15_2.pde
├── listing_15_3
│ ├── Drawing.pde
│ ├── Geo.pde
│ ├── UI.pde
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ ├── cross-icon.png
│ │ ├── left-icon.png
│ │ └── right-icon.png
│ └── listing_15_3.pde
├── listing_15_4
│ ├── Drawing.pde
│ ├── Geo.pde
│ ├── UI.pde
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ ├── cross-icon.png
│ │ ├── fly-icon.png
│ │ ├── home-icon.png
│ │ ├── left-icon.png
│ │ └── right-icon.png
│ └── listing_15_4.pde
├── listing_15_5
│ ├── Drawing.pde
│ ├── Geo.pde
│ ├── UI.pde
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ ├── cross-icon.png
│ │ ├── fly-icon.png
│ │ ├── home-icon.png
│ │ ├── left-icon.png
│ │ └── right-icon.png
│ └── listing_15_5.pde
└── vr_draw
│ ├── AndroidManifest.xml
│ ├── Drawing.pde
│ ├── Geo.pde
│ ├── UI.pde
│ ├── code
│ └── sketch.properties
│ ├── data
│ ├── cross-icon.png
│ ├── fly-icon.png
│ ├── home-icon.png
│ ├── left-icon.png
│ └── right-icon.png
│ ├── icon-144.png
│ ├── icon-192.png
│ ├── icon-36.png
│ ├── icon-48.png
│ ├── icon-72.png
│ ├── icon-96.png
│ └── vr_draw.pde
├── chapter 2
├── listing_2_1
│ ├── code
│ │ └── sketch.properties
│ └── listing_2_1.pde
├── listing_2_10
│ ├── code
│ │ └── sketch.properties
│ └── listing_2_10.pde
├── listing_2_11
│ ├── code
│ │ └── sketch.properties
│ └── listing_2_11.pde
├── listing_2_12
│ ├── code
│ │ └── sketch.properties
│ └── listing_2_12.pde
├── listing_2_13
│ ├── code
│ │ └── sketch.properties
│ └── listing_2_13.pde
├── listing_2_14
│ ├── code
│ │ └── sketch.properties
│ └── listing_2_14.pde
├── listing_2_15
│ ├── code
│ │ └── sketch.properties
│ └── listing_2_15.pde
├── listing_2_16
│ ├── code
│ │ └── sketch.properties
│ └── listing_2_16.pde
├── listing_2_17
│ ├── code
│ │ └── sketch.properties
│ └── listing_2_17.pde
├── listing_2_18
│ ├── Flower.pde
│ ├── Spiral.pde
│ ├── code
│ │ └── sketch.properties
│ └── listing_2_18.pde
├── listing_2_2
│ ├── code
│ │ └── sketch.properties
│ └── listing_2_2.pde
├── listing_2_3
│ ├── code
│ │ └── sketch.properties
│ └── listing_2_3.pde
├── listing_2_4
│ ├── code
│ │ └── sketch.properties
│ └── listing_2_4.pde
├── listing_2_5
│ ├── code
│ │ └── sketch.properties
│ └── listing_2_5.pde
├── listing_2_6
│ ├── code
│ │ └── sketch.properties
│ └── listing_2_6.pde
├── listing_2_7
│ ├── code
│ │ └── sketch.properties
│ └── listing_2_7.pde
├── listing_2_8
│ ├── code
│ │ └── sketch.properties
│ └── listing_2_8.pde
└── listing_2_9
│ ├── code
│ └── sketch.properties
│ └── listing_2_9.pde
├── chapter 3
├── listing_3_1
│ ├── code
│ │ └── sketch.properties
│ └── listing_3_1.pde
├── listing_3_2
│ ├── code
│ │ └── sketch.properties
│ └── listing_3_2.pde
└── vines_draw
│ ├── AndroidManifest.xml
│ ├── Flower.pde
│ ├── Spiral.pde
│ ├── code
│ └── sketch.properties
│ ├── icon-144.png
│ ├── icon-192.png
│ ├── icon-36.png
│ ├── icon-48.png
│ ├── icon-72.png
│ ├── icon-96.png
│ └── vines_draw.pde
├── chapter 4
├── listing_4_1
│ ├── code
│ │ └── sketch.properties
│ └── listing_4_1.pde
├── listing_4_10
│ ├── code
│ │ └── sketch.properties
│ └── listing_4_10.pde
├── listing_4_11
│ ├── code
│ │ └── sketch.properties
│ └── listing_4_11.pde
├── listing_4_12
│ ├── code
│ │ └── sketch.properties
│ └── listing_4_12.pde
├── listing_4_13
│ ├── code
│ │ └── sketch.properties
│ └── listing_4_13.pde
├── listing_4_14
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ ├── cc.svg
│ │ ├── mozilla.svg
│ │ └── ruby.svg
│ └── listing_4_14.pde
├── listing_4_15
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── World-map.svg
│ └── listing_4_15.pde
├── listing_4_16
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── paine.jpg
│ └── listing_4_16.pde
├── listing_4_17
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── paine.jpg
│ └── listing_4_17.pde
├── listing_4_18
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── paine.jpg
│ └── listing_4_18.pde
├── listing_4_19
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── SansSerif-32.vlw
│ └── listing_4_19.pde
├── listing_4_2
│ ├── code
│ │ └── sketch.properties
│ └── listing_4_2.pde
├── listing_4_20
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── SansSerif-32.vlw
│ └── listing_4_20.pde
├── listing_4_21
│ ├── code
│ │ └── sketch.properties
│ └── listing_4_21.pde
├── listing_4_22
│ ├── code
│ │ └── sketch.properties
│ └── listing_4_22.pde
├── listing_4_23
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── borges.txt
│ └── listing_4_23.pde
├── listing_4_3
│ ├── code
│ │ └── sketch.properties
│ └── listing_4_3.pde
├── listing_4_4
│ ├── code
│ │ └── sketch.properties
│ └── listing_4_4.pde
├── listing_4_5
│ ├── code
│ │ └── sketch.properties
│ └── listing_4_5.pde
├── listing_4_6
│ ├── code
│ │ └── sketch.properties
│ └── listing_4_6.pde
├── listing_4_7
│ ├── code
│ │ └── sketch.properties
│ └── listing_4_7.pde
├── listing_4_8
│ ├── code
│ │ └── sketch.properties
│ └── listing_4_8.pde
└── listing_4_9
│ ├── code
│ └── sketch.properties
│ └── listing_4_9.pde
├── chapter 5
├── listing_5_1
│ ├── code
│ │ └── sketch.properties
│ └── listing_5_1.pde
├── listing_5_10
│ ├── code
│ │ └── sketch.properties
│ └── listing_5_10.pde
├── listing_5_11
│ ├── code
│ │ └── sketch.properties
│ └── listing_5_11.pde
├── listing_5_12
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── jelly.jpg
│ └── listing_5_12.pde
├── listing_5_13
│ ├── code
│ │ └── sketch.properties
│ └── listing_5_13.pde
├── listing_5_2
│ ├── code
│ │ └── sketch.properties
│ └── listing_5_2.pde
├── listing_5_3
│ ├── Circle.pde
│ ├── code
│ │ └── sketch.properties
│ └── listing_5_3.pde
├── listing_5_4
│ ├── code
│ │ └── sketch.properties
│ └── listing_5_4.pde
├── listing_5_5
│ ├── Circle.pde
│ ├── code
│ │ └── sketch.properties
│ └── listing_5_5.pde
├── listing_5_6
│ ├── Circle.pde
│ ├── code
│ │ └── sketch.properties
│ └── listing_5_6.pde
├── listing_5_7
│ ├── code
│ │ └── sketch.properties
│ └── listing_5_7.pde
├── listing_5_8
│ ├── code
│ │ └── sketch.properties
│ └── listing_5_8.pde
└── listing_5_9
│ ├── code
│ └── sketch.properties
│ ├── data
│ └── World-map.svg
│ └── listing_5_9.pde
├── chapter 6
├── image_flow
│ ├── AndroidManifest.xml
│ ├── Field.pde
│ ├── Particle.pde
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── default.jpg
│ ├── icon-144.png
│ ├── icon-192.png
│ ├── icon-36.png
│ ├── icon-48.png
│ ├── icon-72.png
│ ├── icon-96.png
│ └── image_flow.pde
├── listing_6_1
│ ├── code
│ │ └── sketch.properties
│ └── listing_6_1.pde
├── listing_6_10
│ ├── Field.pde
│ ├── Particle.pde
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── default.jpg
│ └── listing_6_10.pde
├── listing_6_11
│ ├── Field.pde
│ ├── Particle.pde
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── default.jpg
│ └── listing_6_11.pde
├── listing_6_12
│ ├── Field.pde
│ ├── Particle.pde
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── default.jpg
│ └── listing_6_12.pde
├── listing_6_2
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── paine.jpg
│ └── listing_6_2.pde
├── listing_6_3
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── paine.jpg
│ └── listing_6_3.pde
├── listing_6_4
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── paine.jpg
│ └── listing_6_4.pde
├── listing_6_5
│ ├── code
│ │ └── sketch.properties
│ └── listing_6_5.pde
├── listing_6_6
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── default.jpg
│ └── listing_6_6.pde
├── listing_6_7
│ ├── Field.pde
│ ├── Particle.pde
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ ├── brush.ai
│ │ ├── brush.png
│ │ ├── brush2.ai
│ │ └── brush2.png
│ └── listing_6_7.pde
├── listing_6_8
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ └── jupiter.jpg
│ └── listing_6_8.pde
└── listing_6_9
│ ├── code
│ └── sketch.properties
│ ├── data
│ └── default.jpg
│ └── listing_6_9.pde
├── chapter 7
├── listing_7_1
│ ├── code
│ │ └── sketch.properties
│ └── listing_7_1.pde
├── listing_7_2
│ ├── code
│ │ └── sketch.properties
│ └── listing_7_2.pde
├── listing_7_3
│ ├── code
│ │ └── sketch.properties
│ └── listing_7_3.pde
├── listing_7_4
│ ├── code
│ │ └── sketch.properties
│ └── listing_7_4.pde
├── listing_7_5
│ ├── code
│ │ └── sketch.properties
│ └── listing_7_5.pde
├── listing_7_6
│ ├── code
│ │ └── sketch.properties
│ └── listing_7_6.pde
└── listing_7_7
│ ├── code
│ └── sketch.properties
│ └── listing_7_7.pde
├── chapter 8
├── listing_8_1
│ ├── code
│ │ └── sketch.properties
│ └── listing_8_1.pde
├── listing_8_10
│ ├── code
│ │ └── sketch.properties
│ └── listing_8_10.pde
├── listing_8_11
│ ├── code
│ │ └── sketch.properties
│ └── listing_8_11.pde
├── listing_8_12
│ ├── code
│ │ └── sketch.properties
│ └── listing_8_12.pde
├── listing_8_13
│ ├── code
│ │ └── sketch.properties
│ └── listing_8_13.pde
├── listing_8_2
│ ├── code
│ │ └── sketch.properties
│ └── listing_8_2.pde
├── listing_8_3
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ ├── 4C.wav
│ │ ├── 4D.wav
│ │ ├── 4E.wav
│ │ ├── 4F.wav
│ │ ├── 4G.wav
│ │ └── 5A.wav
│ └── listing_8_3.pde
├── listing_8_4
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ ├── 4C.wav
│ │ ├── 4D.wav
│ │ ├── 4E.wav
│ │ ├── 4F.wav
│ │ ├── 4G.wav
│ │ └── 5A.wav
│ └── listing_8_4.pde
├── listing_8_5
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ ├── 4C.wav
│ │ ├── 4D.wav
│ │ ├── 4E.wav
│ │ ├── 4F.wav
│ │ ├── 4G.wav
│ │ └── 5A.wav
│ └── listing_8_5.pde
├── listing_8_6
│ ├── AudioPlayer.pde
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ ├── 4C.wav
│ │ ├── 4D.wav
│ │ ├── 4E.wav
│ │ ├── 4F.wav
│ │ ├── 4G.wav
│ │ └── 5A.wav
│ └── listing_8_6.pde
├── listing_8_7
│ ├── code
│ │ └── sketch.properties
│ └── listing_8_7.pde
├── listing_8_8
│ ├── code
│ │ └── sketch.properties
│ └── listing_8_8.pde
└── listing_8_9
│ ├── code
│ └── sketch.properties
│ └── listing_8_9.pde
├── chapter 9
├── listing_9_1
│ ├── code
│ │ └── sketch.properties
│ └── listing_9_1.pde
├── listing_9_10
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ ├── streetview0.jpg
│ │ ├── streetview1.jpg
│ │ ├── streetview2.jpg
│ │ ├── streetview3.jpg
│ │ ├── streetview4.jpg
│ │ ├── streetview5.jpg
│ │ ├── streetview6.jpg
│ │ ├── streetview7.jpg
│ │ ├── streetview8.jpg
│ │ └── streetview9.jpg
│ └── listing_9_10.pde
├── listing_9_11
│ ├── LocationListener.pde
│ ├── LocationQueue.pde
│ ├── Voronoi.pde
│ ├── code
│ │ └── sketch.properties
│ └── listing_9_11.pde
├── listing_9_2
│ ├── code
│ │ └── sketch.properties
│ └── listing_9_2.pde
├── listing_9_3
│ ├── code
│ │ └── sketch.properties
│ └── listing_9_3.pde
├── listing_9_4
│ ├── code
│ │ └── sketch.properties
│ └── listing_9_4.pde
├── listing_9_5
│ ├── code
│ │ └── sketch.properties
│ └── listing_9_5.pde
├── listing_9_6
│ ├── code
│ │ └── sketch.properties
│ └── listing_9_6.pde
├── listing_9_7
│ ├── code
│ │ └── sketch.properties
│ └── listing_9_7.pde
├── listing_9_8
│ ├── code
│ │ └── sketch.properties
│ └── listing_9_8.pde
├── listing_9_9
│ ├── code
│ │ └── sketch.properties
│ ├── data
│ │ ├── streetview0.jpg
│ │ ├── streetview1.jpg
│ │ ├── streetview2.jpg
│ │ ├── streetview3.jpg
│ │ ├── streetview4.jpg
│ │ ├── streetview5.jpg
│ │ ├── streetview6.jpg
│ │ ├── streetview7.jpg
│ │ ├── streetview8.jpg
│ │ └── streetview9.jpg
│ └── listing_9_9.pde
└── street_collage
│ ├── AndroidManifest.xml
│ ├── LocationListener.pde
│ ├── LocationQueue.pde
│ ├── Voronoi.pde
│ ├── code
│ └── sketch.properties
│ ├── data
│ └── default.png
│ ├── icon-144.png
│ ├── icon-192.png
│ ├── icon-36.png
│ ├── icon-48.png
│ ├── icon-72.png
│ ├── icon-96.png
│ └── street_collage.pde
├── contributing.md
└── processing-for-android-examples.txt
/9781484227183.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/9781484227183.jpg
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/LICENSE.txt
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Apress Source Code
2 |
3 | This repository hosts all the code examples included in the book [*Processing for Android: Create Mobile, Sensor-Aware, and VR Applications Using Processing*](http://www.apress.com/us/book/9781484227183), by Andrés Colubri (Apress, 2017).
4 |
5 | [comment]: #cover
6 | 
7 |
8 | Download the files as a zip using the green button, or clone the repository to your machine using Git.
9 |
10 | You can also install all the examples through the Contributions Manager in the Processing Development Environment (PDE).
11 |
12 | ## Releases
13 |
14 | Release v1.0 corresponds to the code in the published book, without corrections or updates.
15 |
16 | ## Contributions
17 |
18 | See the file Contributing.md for more information on how you can contribute to this repository.
--------------------------------------------------------------------------------
/appendix a/layouts/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/appendix a/layouts/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/appendix a/layouts/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/appendix a/layouts/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/appendix a/layouts/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/appendix a/layouts/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/appendix a/layouts/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "processing.book.layouts"
8 | minSdkVersion 21
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.3.1'
28 | compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
29 | compile 'com.android.support:design:25.3.1'
30 | testCompile 'junit:junit:4.12'
31 | compile files('libs/processing-core.jar')
32 | }
33 |
--------------------------------------------------------------------------------
/appendix a/layouts/app/libs/processing-core.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/appendix a/layouts/app/libs/processing-core.jar
--------------------------------------------------------------------------------
/appendix a/layouts/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/andres/code/android/android-studio/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/appendix a/layouts/app/src/androidTest/java/processing/book/layouts/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package processing.book.layouts;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("processing.book.layouts", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/appendix a/layouts/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/appendix a/layouts/app/src/main/assets/mosaic.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/appendix a/layouts/app/src/main/assets/mosaic.jpg
--------------------------------------------------------------------------------
/appendix a/layouts/app/src/main/java/processing/book/layouts/MySketch.java:
--------------------------------------------------------------------------------
1 | package processing.book.layouts;
2 |
3 | import processing.core.PShape;
4 | import processing.core.PImage;
5 | import processing.core.PApplet;
6 |
7 | public class MySketch extends PApplet {
8 | float angle = 0;
9 | PShape cube;
10 |
11 | public void settings() {
12 | fullScreen(P3D);
13 | }
14 |
15 | public void setup() {
16 | fullScreen(P3D);
17 | PImage tex = loadImage("mosaic.jpg");
18 | cube = createShape(BOX, 400);
19 | cube.setTexture(tex);
20 | }
21 |
22 | public void draw() {
23 | background(0x81B771);
24 | lights();
25 | translate(width/2, height/2);
26 | rotateY(angle);
27 | rotateX(angle*2);
28 | shape(cube);
29 | angle += 0.01;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/appendix a/layouts/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/appendix a/layouts/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/appendix a/layouts/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/appendix a/layouts/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/appendix a/layouts/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/appendix a/layouts/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/appendix a/layouts/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/appendix a/layouts/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/appendix a/layouts/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/appendix a/layouts/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/appendix a/layouts/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/appendix a/layouts/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/appendix a/layouts/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/appendix a/layouts/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/appendix a/layouts/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/appendix a/layouts/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/appendix a/layouts/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/appendix a/layouts/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/appendix a/layouts/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/appendix a/layouts/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/appendix a/layouts/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/appendix a/layouts/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/appendix a/layouts/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/appendix a/layouts/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 |
4 |
--------------------------------------------------------------------------------
/appendix a/layouts/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | layouts
3 | Settings
4 |
5 |
--------------------------------------------------------------------------------
/appendix a/layouts/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/appendix a/layouts/app/src/test/java/processing/book/layouts/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package processing.book.layouts;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/appendix a/layouts/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.3'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/appendix a/layouts/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/appendix a/layouts/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/appendix a/layouts/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/appendix a/layouts/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Apr 28 22:40:38 KST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/appendix a/layouts/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/appendix a/listing_a_1/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/appendix a/listing_a_1/listing_a_1.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | PShape world;
7 |
8 | void setup() {
9 | fullScreen(P2D);
10 | orientation(LANDSCAPE);
11 | world = loadShape("World-map.svg");
12 | world.scale(height/world.getHeight());
13 | shapeMode(CENTER);
14 | }
15 |
16 | void draw() {
17 | background(255);
18 | translate(width/2, height/2);
19 | shape(world);
20 | }
--------------------------------------------------------------------------------
/chapter 1/circle/circle.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | color bg = 150;
7 |
8 | void setup() {
9 | size(200, 200);
10 | }
11 |
12 | void draw() {
13 | background(bg);
14 | ellipse(mouseX, mouseY, 100, 100);
15 | }
--------------------------------------------------------------------------------
/chapter 1/circle/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Java
2 | component=app
3 | mode.id=processing.mode.java.JavaMode
4 |
--------------------------------------------------------------------------------
/chapter 1/listing_1_1/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 1/listing_1_1/listing_1_1.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fill(0);
8 | }
9 |
10 | void draw() {
11 | background(204);
12 | if (mousePressed) {
13 | if (mouseX < width/2) rect(0, 0, width/2, height);
14 | else rect(width/2, 0, width/2, height);
15 | }
16 | }
--------------------------------------------------------------------------------
/chapter 10/listing_10_1/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=watchface
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 10/listing_10_1/listing_10_1.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen();
8 | strokeCap(ROUND);
9 | stroke(255);
10 | noFill();
11 | }
12 |
13 | void draw() {
14 | background(0);
15 | if (wearAmbient()) strokeWeight(1);
16 | else strokeWeight(10);
17 | float angle = map(millis() % 60000, 0, 60000, 0, TWO_PI);
18 | arc(width/2, height/2, width/2, width/2, 0, angle);
19 | }
--------------------------------------------------------------------------------
/chapter 10/listing_10_2/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=watchface
2 |
--------------------------------------------------------------------------------
/chapter 10/listing_10_2/listing_10_2.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen();
8 | frameRate(1);
9 | textFont(createFont("Serif-Bold", 48 * displayDensity));
10 | textAlign(CENTER, CENTER);
11 | fill(255);
12 | }
13 |
14 | void draw() {
15 | background(0);
16 | if (wearInteractive()) {
17 | String str = hour() + ":" + nfs(minute(), 2) + ":" + nfs(second(), 2);
18 | text(str, width/2, height/2);
19 | }
20 | }
--------------------------------------------------------------------------------
/chapter 10/listing_10_3/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=watchface
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 10/listing_10_4/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=watchface
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 10/listing_10_4/listing_10_4.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen();
8 | if (wearSquare()) rectMode(CENTER);
9 | }
10 |
11 | void draw() {
12 | background(0);
13 | if (wearAmbient()) {
14 | stroke(255);
15 | noFill();
16 | } else {
17 | noStroke();
18 | fill(255);
19 | }
20 | float scale = map(second(), 0, 59, 0, 1);
21 | if (wearRound()) {
22 | ellipse(width/2, height/2, scale * width, scale * width);
23 | } else {
24 | rect(width/2, height/2, scale * width, scale * height);
25 | }
26 | }
--------------------------------------------------------------------------------
/chapter 10/listing_10_5/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=watchface
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 10/listing_10_5/listing_10_5.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen();
8 | if (wearSquare()) rectMode(CENTER);
9 | }
10 |
11 | void draw() {
12 | background(0);
13 | if (wearAmbient()) {
14 | stroke(255);
15 | noFill();
16 | } else {
17 | noStroke();
18 | fill(255);
19 | }
20 | translate(0, wearInsets().bottom/2);
21 | float scale = map(second(), 0, 59, 0, 1);
22 | if (wearRound()) {
23 | ellipse(width/2, height/2, scale * width, scale * width);
24 | } else {
25 | rect(width/2, height/2, scale * width, scale * height);
26 | }
27 | }
--------------------------------------------------------------------------------
/chapter 11/listing_11_1/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=watchface
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 11/listing_11_1/listing_11_1.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | noStroke();
8 | strokeWeight(2);
9 | }
10 |
11 | void draw() {
12 | background(0);
13 |
14 | float hAngle = map(hour() % 12, 0, 12, 0, TWO_PI);
15 | float mAngle = map(minute(), 0, 60, 0, TWO_PI);
16 | float sAngle = map(second(), 0, 60, 0, TWO_PI);
17 |
18 | translate(width/2, height/2 + wearInsets().bottom/2);
19 | fill(wearAmbient() ? 0 : #F0DB3F);
20 | ellipse(0, 0, width, width);
21 | drawLine(hAngle, width/2);
22 |
23 | fill(wearAmbient() ? 0 : #FFB25F);
24 | ellipse(0, 0, 0.75 * width, 0.75 * width);
25 | drawLine(mAngle, 0.75 * width/2);
26 |
27 | fill(wearAmbient() ? 0 : #ED774D);
28 | ellipse(0, 0, 0.5 * width, 0.5 * width);
29 | drawLine(sAngle, 0.5 * width/2);
30 |
31 | fill(0);
32 | ellipse(0, 0, 0.25 * width, 0.25 * width);
33 | }
34 |
35 | void drawLine(float a, float r) {
36 | pushStyle();
37 | stroke(wearAmbient() ? 255 : 0);
38 | pushMatrix();
39 | rotate(a);
40 | line(0, 0, 0, -r);
41 | popMatrix();
42 | popStyle();
43 | }
--------------------------------------------------------------------------------
/chapter 11/listing_11_2/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=watchface
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 11/listing_11_2/listing_11_2.pde:
--------------------------------------------------------------------------------
1 | int s0;
2 | int m0;
3 |
4 | void setup() {
5 | noStroke();
6 | strokeWeight(2);
7 | }
8 |
9 | void draw() {
10 | background(0);
11 |
12 | int h = hour() % 12;
13 | int m = minute();
14 | int s = second();
15 |
16 | if (s0 != s) {
17 | m0 = millis();
18 | s0 = s;
19 | }
20 | float f = (millis() - m0)/1000.0;
21 |
22 | float sf = s + f;
23 | float mf = m + sf/60.0;
24 | float hf = h + mf/60.0;
25 |
26 | float hAngle = map(hf, 0, 12, 0, TWO_PI);
27 | float mAngle = map(mf, 0, 60, 0, TWO_PI);
28 | float sAngle = map(sf, 0, 60, 0, TWO_PI);
29 |
30 | translate(width/2, height/2 + wearInsets().bottom/2);
31 | fill(wearAmbient() ? 0 : #F0DB3F);
32 | ellipse(0, 0, width, width);
33 | drawLine(hAngle, width/2);
34 |
35 | fill(wearAmbient() ? 0 : #FFB25F);
36 | ellipse(0, 0, 0.75 * width, 0.75 * width);
37 | drawLine(mAngle, 0.75 * width/2);
38 |
39 | fill(wearAmbient() ? 0 : #ED774D);
40 | ellipse(0, 0, 0.5 * width, 0.5 * width);
41 | drawLine(sAngle, 0.5 * width/2);
42 |
43 | fill(0);
44 | ellipse(0, 0, 0.25 * width, 0.25 * width);
45 | }
46 |
47 | void drawLine(float a, float r) {
48 | pushStyle();
49 | stroke(wearAmbient() ? 255 : 0);
50 | pushMatrix();
51 | rotate(a);
52 | line(0, 0, 0, -r);
53 | popMatrix();
54 | popStyle();
55 | }
--------------------------------------------------------------------------------
/chapter 11/listing_11_3/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=watchface
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 11/listing_11_3/listing_11_3.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | textFont(createFont("Monospaced", 15 * displayDensity));
8 | textAlign(CENTER, CENTER);
9 | noStroke();
10 | }
11 |
12 | void draw() {
13 | background(0);
14 | int h = hour();
15 | int m = minute();
16 | float cellW = 0.9 * width/4.0;
17 | float cellH = 0.9 * height/6.0;
18 | translate(0.05 * cellW, 0.05 * cellH + wearInsets().bottom/2);
19 | for (int n = 0; n < 24; n++) {
20 | int i = n % 4;
21 | int j = n / 4;
22 | float x = map(i, 0, 4, 0, width);
23 | float y = map(j, 0, 6, 0, height);
24 | float w = n == h ? map(m, 0, 60, 0, cellW) : cellW;
25 |
26 | if (!wearAmbient()) {
27 | fill(#578CB7);
28 | rect(x, y, cellW, cellH);
29 | }
30 |
31 | fill(255);
32 | text(str(n), x, y, cellW, cellH);
33 |
34 | if (n <= h) {
35 | fill(0, 170);
36 | rect(x, y, w, cellH);
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/chapter 11/listing_11_4/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=watchface
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 11/listing_11_5/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=watchface
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 11/listing_11_6/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=watchface
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 11/listing_11_7/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=watchface
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 11/listing_11_7/data/FullMoon2010.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 11/listing_11_7/data/FullMoon2010.jpg
--------------------------------------------------------------------------------
/chapter 11/listing_11_7/data/moon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 11/listing_11_7/data/moon.png
--------------------------------------------------------------------------------
/chapter 12/listing_12_1/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=watchface
2 |
--------------------------------------------------------------------------------
/chapter 12/listing_12_10/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=watchface
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 12/listing_12_11/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=watchface
2 |
--------------------------------------------------------------------------------
/chapter 12/listing_12_12/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=watchface
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 12/listing_12_13/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=watchface
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 12/listing_12_2/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=watchface
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 12/listing_12_3/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=watchface
2 |
--------------------------------------------------------------------------------
/chapter 12/listing_12_4/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=watchface
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 12/listing_12_5/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=watchface
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 12/listing_12_6/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=watchface
2 |
--------------------------------------------------------------------------------
/chapter 12/listing_12_7/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 12/listing_12_7/listing_12_7.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(700, 200, P2D);
7 | Table table = loadTable("sensor-data.csv", "header");
8 | background(90);
9 | stroke(247, 47, 47);
10 | strokeWeight(4);
11 | beginShape(LINE_STRIP);
12 | for (int i = 0; i < table.getRowCount(); i++) {
13 | TableRow row = table.getRow(i);
14 | int r = row.getInt("rate");
15 | float x = map(i, 0, table.getRowCount() - 1, 0, width);
16 | float y = map(r, 0, 100, height, 0);
17 | vertex(x, y);
18 | }
19 | endShape();
--------------------------------------------------------------------------------
/chapter 12/listing_12_8/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=watchface
2 |
--------------------------------------------------------------------------------
/chapter 12/listing_12_8/listing_12_8.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | int bpm;
7 |
8 | void setup() {
9 | fullScreen();
10 | frameRate(1);
11 | textFont(createFont("SansSerif", 28 * displayDensity));
12 | textAlign(CENTER, CENTER);
13 | thread("generateData");
14 | }
15 |
16 | void draw() {
17 | background(0);
18 | translate(0, wearInsets().bottom/2);
19 | text(bpm + " beats/min", 0, 0, width, height);
20 | }
21 |
22 | void generateData() {
23 | while (true) {
24 | bpm = int(random(60, 100));
25 | delay(2000);
26 | }
27 | }
--------------------------------------------------------------------------------
/chapter 12/listing_12_9/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Java
2 | component=app
3 | mode.id=processing.mode.java.JavaMode
4 |
--------------------------------------------------------------------------------
/chapter 12/runnning_tree/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=watchface
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 12/runnning_tree/icon-144.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 12/runnning_tree/icon-144.png
--------------------------------------------------------------------------------
/chapter 12/runnning_tree/icon-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 12/runnning_tree/icon-192.png
--------------------------------------------------------------------------------
/chapter 12/runnning_tree/icon-36.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 12/runnning_tree/icon-36.png
--------------------------------------------------------------------------------
/chapter 12/runnning_tree/icon-48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 12/runnning_tree/icon-48.png
--------------------------------------------------------------------------------
/chapter 12/runnning_tree/icon-72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 12/runnning_tree/icon-72.png
--------------------------------------------------------------------------------
/chapter 12/runnning_tree/icon-96.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 12/runnning_tree/icon-96.png
--------------------------------------------------------------------------------
/chapter 12/runnning_tree/preview_circular.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 12/runnning_tree/preview_circular.png
--------------------------------------------------------------------------------
/chapter 12/runnning_tree/preview_rectangular.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 12/runnning_tree/preview_rectangular.png
--------------------------------------------------------------------------------
/chapter 13/listing_13_1/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_1/listing_13_1.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | float angle = 0;
7 |
8 | void setup() {
9 | fullScreen(P3D);
10 | fill(#AD71B7);
11 | }
12 |
13 | void draw() {
14 | background(#81B771);
15 | lights();
16 | translate(width/2, height/2);
17 | rotateY(angle);
18 | rotateX(angle*2);
19 | box(300);
20 | angle += 0.01;
21 | }
--------------------------------------------------------------------------------
/chapter 13/listing_13_10/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_10/listing_13_10.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen(P3D);
8 | }
9 |
10 | void draw() {
11 | background(150);
12 | lights();
13 | translate(width/2, height/2);
14 | rotateX(QUARTER_PI);
15 | beginShape(QUADS);
16 | float t = 0.0001 * millis();
17 | for (int i = 0; i < 50; i++) {
18 | for (int j = 0; j < 50; j++) {
19 | float x0 = map(i, 0, 50, -width/2, width/2);
20 | float y0 = map(j, 0, 50, -height/2, height/2);
21 | float x1 = x0 + width/50.0;
22 | float y1 = y0 + height/50.0;
23 | float z1 = 200 * noise(0.1 * i, 0.1 * j, t);
24 | float z2 = 200 * noise(0.1 * (i + 1), 0.1 * j, t);
25 | float z3 = 200 * noise(0.1 * (i + 1), 0.1 * (j + 1), t);
26 | float z4 = 200 * noise(0.1 * i, 0.1 * (j + 1), t);
27 | vertex(x0, y0, z1);
28 | vertex(x1, y0, z2);
29 | vertex(x1, y1, z3);
30 | vertex(x0, y1, z4);
31 | }
32 | }
33 | endShape();
34 | }
--------------------------------------------------------------------------------
/chapter 13/listing_13_11/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_11/listing_13_11.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | PShape terrain;
7 |
8 | void setup() {
9 | fullScreen(P3D);
10 | terrain = createShape();
11 | terrain.beginShape(QUADS);
12 | for (int i = 0; i < 50; i++) {
13 | for (int j = 0; j < 50; j++) {
14 | float x0 = map(i, 0, 50, -width/2, width/2);
15 | float y0 = map(j, 0, 50, -height/2, height/2);
16 | float x1 = x0 + width/50.0;
17 | float y1 = y0 + height/50.0;
18 | float z1 = 200 * noise(0.1 * i, 0.1 * j, 0);
19 | float z2 = 200 * noise(0.1 * (i + 1), 0.1 * j, 0);
20 | float z3 = 200 * noise(0.1 * (i + 1), 0.1 * (j + 1), 0);
21 | float z4 = 200 * noise(0.1 * i, 0.1 * (j + 1), 0);
22 | terrain.vertex(x0, y0, z1);
23 | terrain.vertex(x1, y0, z2);
24 | terrain.vertex(x1, y1, z3);
25 | terrain.vertex(x0, y1, z4);
26 | }
27 | }
28 | terrain.endShape();
29 | }
30 |
31 | void draw() {
32 | background(150);
33 | lights();
34 | translate(width/2, height/2);
35 | rotateX(QUARTER_PI);
36 | shape(terrain);
37 | }
--------------------------------------------------------------------------------
/chapter 13/listing_13_12/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_13/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_13/data/genera.py:
--------------------------------------------------------------------------------
1 | import numpy
2 |
3 | x = numpy.random.uniform(-800, 800, size=1000)
4 | y = numpy.random.uniform(-800, 800, size=1000)
5 | z = numpy.random.uniform(-800, 800, size=1000)
6 |
7 | with open("puntos.txt", "w") as of:
8 | for i in range(0, 1000):
9 | of.write(str(x[i]) + " " + str(y[i]) + " " + str(z[i]) + "\n")
--------------------------------------------------------------------------------
/chapter 13/listing_13_13/listing_13_13.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | PVector[] coords;
7 | PShape group;
8 |
9 | void setup() {
10 | fullScreen(P3D);
11 | textFont(createFont("SansSerif", 20 * displayDensity));
12 | sphereDetail(10);
13 | group = createShape(GROUP);
14 | String[] lines = loadStrings("points.txt");
15 | coords = new PVector[lines.length];
16 | for (int i = 0; i < lines.length; i++) {
17 | String line = lines[i];
18 | String[] valores = line.split(" ");
19 | float x = float(valores[0]);
20 | float y = float(valores[1]);
21 | float z = float(valores[2]);
22 | coords[i] = new PVector(x, y, z);
23 | PShape sh;
24 | if (random(1) < 0.5) {
25 | sh = createShape(SPHERE, 20);
26 | sh.setFill(#E8A92A);
27 | } else {
28 | sh = createShape(BOX, 20);
29 | sh.setFill(#4876B2);
30 | }
31 | sh.translate(x, y, z);
32 | sh.setStroke(false);
33 | group.addChild(sh);
34 | }
35 | noStroke();
36 | }
37 |
38 | void draw() {
39 | background(255);
40 | fill(0);
41 | text(frameRate, 50, 50);
42 | fill(255, 0, 0);
43 | lights();
44 | translate(width/2, height/2, 0);
45 | rotateY(map(mouseX, 0, width, 0, TWO_PI));
46 | shape(group);
47 | }
--------------------------------------------------------------------------------
/chapter 13/listing_13_14/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_14/data/Raptor.mtl:
--------------------------------------------------------------------------------
1 | # Max2Mtl Version 4.0 Mar 10th, 2001
2 | #
3 | newmtl default02
4 | Ka 0.4 0.4 0.4
5 | Kd 0.9 0.9 0.9
6 | Ks 1.0 1.0 1.0
7 | d 1.0
8 | Ns 1.3
9 | illum 2
10 | map_Kd raptor.jpg
11 | #
12 | # EOF
13 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_14/data/lowpolytree.mtl:
--------------------------------------------------------------------------------
1 | # Blender MTL File: 'lowpolytree.blend'
2 | # Material Count: 2
3 |
4 | newmtl Bark
5 | Ns 96.078431
6 | Ka 0.000000 0.000000 0.000000
7 | Kd 0.176206 0.051816 0.016055
8 | Ks 0.015532 0.005717 0.002170
9 | Ni 1.000000
10 | d 1.000000
11 | illum 2
12 |
13 | newmtl Leaves
14 | Ns 96.078431
15 | Ka 0.000000 0.000000 0.000000
16 | Kd 0.029850 0.306291 0.017666
17 | Ks 0.085514 0.355277 0.074845
18 | Ni 1.000000
19 | d 1.000000
20 | illum 2
21 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_14/data/raptor.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 13/listing_13_14/data/raptor.jpg
--------------------------------------------------------------------------------
/chapter 13/listing_13_14/data/raptor_normal.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 13/listing_13_14/data/raptor_normal.jpg
--------------------------------------------------------------------------------
/chapter 13/listing_13_14/data/rocket.mtl:
--------------------------------------------------------------------------------
1 | newmtl Default
2 | illum 2
3 | Ka 0.698039 0.698039 0.698039
4 | Kd 0.698039 0.698039 0.698039
5 | Ks 0.710000 0.710000 0.710000
6 | Ns 76.109253
7 | map_Kd rocket.png
8 |
9 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_14/data/rocket.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 13/listing_13_14/data/rocket.png
--------------------------------------------------------------------------------
/chapter 13/listing_13_15/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_15/listing_13_15.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen(P3D);
8 | noStroke();
9 | }
10 |
11 | void draw() {
12 | background(20);
13 | translate(width/2, height/2);
14 |
15 | float pointX = map(mouseX, 0, width, -width/2, +width/2);
16 | float dirZ = map(mouseY, 0, height, 0, -1);
17 | pointLight(200, 200, 200, pointX, 0, 600);
18 | directionalLight(100, 220, 100, 0, 1, dirZ);
19 |
20 | rotateY(QUARTER_PI);
21 |
22 | fill(255, 250, 200);
23 | box(320);
24 |
25 | translate(-400, 0);
26 | fill(200, 200, 250);
27 | sphere(160);
28 |
29 | translate(0, +110, 360);
30 | fill(255, 200, 200);
31 | box(100);
32 | }
--------------------------------------------------------------------------------
/chapter 13/listing_13_16/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Java
2 | component=app
3 | mode.id=processing.mode.java.JavaMode
4 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_16/listing_13_16.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen(P3D);
8 | noStroke();
9 | }
10 |
11 | void draw() {
12 | background(0);
13 | translate(width/2, height/2);
14 |
15 | directionalLight(255, 255, 255, 0, 0, -1);
16 |
17 | pushMatrix();
18 | translate(-width/3, 0);
19 | fill(250, 100, 50);
20 | specular(200, 250, 200);
21 | emissive(0, 0, 0);
22 | shininess(10.0);
23 | sphere(200);
24 | popMatrix();
25 |
26 | pushMatrix();
27 | fill(250, 100, 50);
28 | specular(255);
29 | shininess(1.0);
30 | emissive(0, 20, 0);
31 | sphere(200);
32 | popMatrix();
33 |
34 | pushMatrix();
35 | translate(+width/3, 0);
36 | fill(250, 100, 50);
37 | specular(255);
38 | shininess(2.0);
39 | emissive(50, 10, 100);
40 | sphere(200);
41 | popMatrix();
42 | }
--------------------------------------------------------------------------------
/chapter 13/listing_13_17/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_17/data/earthmap1k.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 13/listing_13_17/data/earthmap1k.jpg
--------------------------------------------------------------------------------
/chapter 13/listing_13_17/listing_13_17.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | PShape earth;
7 | PImage texmap;
8 |
9 | void setup() {
10 | fullScreen(P3D);
11 | texmap = loadImage("earthmap1k.jpg");
12 | earth = createShape(SPHERE, 300);
13 | earth.setStroke(false);
14 | earth.setTexture(texmap);
15 | }
16 |
17 | void draw() {
18 | background(255);
19 | translate(width/2, height/2);
20 | rotateY(0.01 * frameCount);
21 | shape(earth);
22 | }
--------------------------------------------------------------------------------
/chapter 13/listing_13_18/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_18/data/shiva.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 13/listing_13_18/data/shiva.jpg
--------------------------------------------------------------------------------
/chapter 13/listing_13_18/data/tiger.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 13/listing_13_18/data/tiger.png
--------------------------------------------------------------------------------
/chapter 13/listing_13_18/data/woodstock.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 13/listing_13_18/data/woodstock.png
--------------------------------------------------------------------------------
/chapter 13/listing_13_18/listing_13_18.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | PImage texmap;
7 |
8 | void setup() {
9 | fullScreen(P3D);
10 | texmap = loadImage("woodstock.png");
11 | noStroke();
12 | }
13 |
14 | void draw() {
15 | background(255);
16 | translate(width/2, height/2);
17 | rotateY(0.01 * frameCount);
18 | scale(displayDensity);
19 | beginShape(QUAD);
20 | texture(texmap);
21 | vertex(-150, -150, 0, 0);
22 | vertex(-150, 150, 0, texmap.height);
23 | vertex(150, 150, texmap.width, texmap.height);
24 | vertex(150, -150, texmap.width, 0);
25 | endShape();
26 | }
--------------------------------------------------------------------------------
/chapter 13/listing_13_19/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_19/data/shiva.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 13/listing_13_19/data/shiva.jpg
--------------------------------------------------------------------------------
/chapter 13/listing_13_19/data/tiger.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 13/listing_13_19/data/tiger.png
--------------------------------------------------------------------------------
/chapter 13/listing_13_19/data/woodstock.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 13/listing_13_19/data/woodstock.png
--------------------------------------------------------------------------------
/chapter 13/listing_13_19/listing_13_19.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | PImage texmap;
7 |
8 | void setup() {
9 | fullScreen(P3D);
10 | texmap = loadImage("woodstock.png");
11 | textureMode(NORMAL);
12 | noStroke();
13 | }
14 |
15 | void draw() {
16 | background(255);
17 | translate(width/2, height/2);
18 | rotateY(0.01 * frameCount);
19 | scale(displayDensity);
20 | beginShape(QUAD);
21 | texture(texmap);
22 | vertex(-150, -150, 0, 0);
23 | vertex(-150, 150, 0, 1);
24 | vertex(150, 150, 1, 1);
25 | vertex(150, -150, 1, 0);
26 | endShape();
27 | }
--------------------------------------------------------------------------------
/chapter 13/listing_13_2/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_2/listing_13_2.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen(P3D);
8 | fill(#AD71B7);
9 | }
10 |
11 | void draw() {
12 | background(#81B771);
13 | float t = millis()/1000.0;
14 | float ex = width/2 + 500 * cos(t);
15 | float ey = height/2 + 500 * sin(t);
16 | float ez = 1000 + 100 * cos(millis()/1000.0);
17 | camera(ex, ey, ez, width/2, height/2, 0, 0, 1, 0);
18 | lights();
19 | translate(width/2, height/2);
20 | box(300);
21 | }
--------------------------------------------------------------------------------
/chapter 13/listing_13_20/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_20/data/dirt.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 13/listing_13_20/data/dirt.jpg
--------------------------------------------------------------------------------
/chapter 13/listing_13_20/data/grass.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 13/listing_13_20/data/grass.png
--------------------------------------------------------------------------------
/chapter 13/listing_13_3/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_3/listing_13_3.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | float angle = 0;
7 |
8 | void setup() {
9 | fullScreen(P3D);
10 | fill(#AD71B7);
11 | noStroke();
12 | }
13 |
14 | void draw() {
15 | background(#81B771);
16 | float fov = radians(map(cos(millis()/1000.0), -1, +1, 10, 80));
17 | float ratio = float(width)/height;
18 | perspective(fov, ratio, 1, 2000);
19 | lights();
20 | translate(width/2, height/2);
21 | rotateY(angle);
22 | rotateX(angle*2);
23 | box(300);
24 | angle += 0.01;
25 | }
--------------------------------------------------------------------------------
/chapter 13/listing_13_4/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_4/data/mosaic.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 13/listing_13_4/data/mosaic.jpg
--------------------------------------------------------------------------------
/chapter 13/listing_13_4/listing_13_4.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | float angle = 0;
7 | PShape cube;
8 |
9 | void setup() {
10 | fullScreen(P3D);
11 | PImage tex = loadImage("mosaic.jpg");
12 | cube = createShape(BOX, 400);
13 | cube.setTexture(tex);
14 | }
15 |
16 | void draw() {
17 | background(#81B771);
18 | lights();
19 | translate(width/2, height/2);
20 | rotateY(angle);
21 | rotateX(angle*2);
22 | shape(cube);
23 | angle += 0.01;
24 | }
--------------------------------------------------------------------------------
/chapter 13/listing_13_5/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_5/listing_13_5.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen(P3D);
8 | fill(120);
9 | }
10 |
11 | void draw() {
12 | background(157);
13 | float x = map(cos(millis()/1000.0), -1, +1, 0, width);
14 | translate(x, height/2);
15 | box(200);
16 | }
--------------------------------------------------------------------------------
/chapter 13/listing_13_6/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Java
2 | component=app
3 | mode.id=processing.mode.java.JavaMode
4 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_6/listing_13_6.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen(P3D);
8 | fill(120);
9 | }
10 |
11 | void draw() {
12 | background(157);
13 | translate(width/2, height/2);
14 | rotateY(millis()/1000.0);
15 | box(200);
16 | }
--------------------------------------------------------------------------------
/chapter 13/listing_13_7/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_7/listing_13_7.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen(P3D);
8 | fill(120);
9 | }
10 |
11 | void draw() {
12 | background(157);
13 | translate(width/2, height/2);
14 | float f = map(cos(millis()/1000.0), -1, +1, 0.1, 5);
15 | scale(f);
16 | box(200);
17 | }
--------------------------------------------------------------------------------
/chapter 13/listing_13_8/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_8/listing_13_8.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | float[] r1, r2;
7 |
8 | void setup() {
9 | fullScreen(P3D);
10 | noStroke();
11 | r1 = new float[100];
12 | r2 = new float[100];
13 | for (int i = 0; i < 100; i++) {
14 | r1[i] = random(0, 1);
15 | r2[i] = random(0, 1);
16 | }
17 | }
18 |
19 | void draw() {
20 | background(157);
21 | lights();
22 | translate(width/2, height/2);
23 | scale(4);
24 | for (int i = 0; i < 100; i++) {
25 | float tx = 0, ty = 0, tz = 0;
26 | float sx = 1, sy = 1, sz = 1;
27 | if (r1[i] < 1.0/3.0) {
28 | rotateX(millis()/1000.0);
29 | tz = sz = 10;
30 | } else if (1.0/3.0 < r1[i] && r1[i] < 2.0/3.0) {
31 | rotateY(millis()/1000.0);
32 | tz = sz = 10;
33 | } else {
34 | rotateZ(millis()/1000.0);
35 | if (r2[i] < 0.5) {
36 | tx = sx = 10;
37 | } else {
38 | ty = sy = 10;
39 | }
40 | }
41 | translate(tx/2, ty/2, tz/2);
42 | pushMatrix();
43 | scale(sx, sy, sz);
44 | box(1);
45 | popMatrix();
46 | translate(tx/2, ty/2, tz/2);
47 | }
48 | }
--------------------------------------------------------------------------------
/chapter 13/listing_13_9/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 13/listing_13_9/listing_13_9.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen(P3D);
8 | }
9 |
10 | void draw() {
11 | background(157);
12 |
13 | translate(width/2, height/2);
14 |
15 | pushMatrix();
16 | translate(-width/3, -height/4);
17 | rotateY(millis()/2000.0);
18 | ellipse(0, 0, 200, 200);
19 | popMatrix();
20 |
21 | pushMatrix();
22 | translate(0, -height/4);
23 | rotateY(millis()/2000.0);
24 | triangle(0, +150, -150, -150, +150, -150);
25 | popMatrix();
26 |
27 | pushMatrix();
28 | translate(+width/3, -height/4);
29 | rotateY(millis()/2000.0);
30 | rect(-100, -100, 200, 200, 20);
31 | popMatrix();
32 |
33 | pushMatrix();
34 | translate(-width/3, +height/4);
35 | rotateY(millis()/2000.0);
36 | quad(-40, -100, 120, -80, 120, 150, -80, 150);
37 | popMatrix();
38 |
39 | pushMatrix();
40 | translate(0, +height/4);
41 | rotateY(millis()/2000.0);
42 | box(200);
43 | popMatrix();
44 |
45 | pushMatrix();
46 | translate(+width/3, +height/4);
47 | rotateY(millis()/2000.0);
48 | sphere(150);
49 | popMatrix();
50 | }
--------------------------------------------------------------------------------
/chapter 14/listing_14_1/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=vr
2 |
--------------------------------------------------------------------------------
/chapter 14/listing_14_1/listing_14_1.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | import processing.vr.*;
7 |
8 | void setup() {
9 | fullScreen(STEREO);
10 | fill(#AD71B7);
11 | }
12 |
13 | void draw() {
14 | background(#81B771);
15 | translate(width/2, height/2);
16 | lights();
17 | rotateY(millis()/1000.0);
18 | box(300);
19 | }
--------------------------------------------------------------------------------
/chapter 14/listing_14_10/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=vr
2 |
--------------------------------------------------------------------------------
/chapter 14/listing_14_11/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=vr
2 |
--------------------------------------------------------------------------------
/chapter 14/listing_14_12/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=vr
2 |
--------------------------------------------------------------------------------
/chapter 14/listing_14_13/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=vr
2 |
--------------------------------------------------------------------------------
/chapter 14/listing_14_2/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=vr
2 |
--------------------------------------------------------------------------------
/chapter 14/listing_14_2/listing_14_2.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | import processing.vr.*;
7 |
8 | void setup() {
9 | fullScreen(STEREO);
10 | strokeWeight(2);
11 | }
12 |
13 | void draw() {
14 | background(0);
15 | translate(width/2, height/2);
16 | lights();
17 | drawAxis();
18 | drawGrid();
19 | }
20 |
21 | void drawAxis() {
22 | line(0, 0, 0, 200, 0, 0);
23 | drawBox(200, 0, 0, 50, #E33E3E);
24 | line(0, 0, 0, 0, -200, 0);
25 | drawBox(0, -200, 0, 50, #3E76E3);
26 | line(0, 0, 0, 0, 0, 200);
27 | drawBox(0, 0, 200, 50, #3EE379);
28 | }
29 |
30 | void drawGrid() {
31 | beginShape(LINES);
32 | stroke(255);
33 | for (int x = -10000; x < +10000; x += 500) {
34 | vertex(x, +500, +10000);
35 | vertex(x, +500, -10000);
36 | }
37 | for (int z = -10000; z < +10000; z += 500) {
38 | vertex(+10000, +500, z);
39 | vertex(-10000, +500, z);
40 | }
41 | endShape();
42 | }
43 |
44 | void drawBox(float x, float y, float z, float s, color c) {
45 | pushStyle();
46 | pushMatrix();
47 | translate(x, y, z);
48 | noStroke();
49 | fill(c);
50 | box(s);
51 | popMatrix();
52 | popStyle();
53 | }
--------------------------------------------------------------------------------
/chapter 14/listing_14_3/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=vr
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 14/listing_14_3/data/mosaic.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 14/listing_14_3/data/mosaic.jpg
--------------------------------------------------------------------------------
/chapter 14/listing_14_3/listing_14_3.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | import processing.vr.*;
7 |
8 | float angle = 0;
9 | PShape cube;
10 |
11 | void setup() {
12 | fullScreen(MONO);
13 | PImage tex = loadImage("mosaic.jpg");
14 | cube = createShape(BOX, 400);
15 | cube.setTexture(tex);
16 | }
17 |
18 | void draw() {
19 | background(#81B771);
20 | translate(width/2, height/2);
21 | lights();
22 | rotateY(angle);
23 | rotateX(angle*2);
24 | shape(cube);
25 | angle += 0.01;
26 | }
--------------------------------------------------------------------------------
/chapter 14/listing_14_4/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=vr
2 |
--------------------------------------------------------------------------------
/chapter 14/listing_14_4/listing_14_4.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | import processing.vr.*;
7 |
8 | public void setup() {
9 | fullScreen(STEREO);
10 | textFont(createFont("SansSerif", 30));
11 | textAlign(CENTER, CENTER);
12 | }
13 |
14 | public void draw() {
15 | background(255);
16 | translate(width/2, height/2);
17 | lights();
18 | fill(#EAB240);
19 | noStroke();
20 | rotateY(millis()/1000.0);
21 | box(300);
22 | drawEye();
23 | }
24 |
25 | void drawEye() {
26 | eye();
27 |
28 | float s = 50;
29 | float d = 200;
30 | float h = 100;
31 |
32 | noFill();
33 | stroke(0);
34 | strokeWeight(10);
35 | beginShape(QUADS);
36 | vertex(-s, -s, d);
37 | vertex(+s, -s, d);
38 | vertex(+s, +s, d);
39 | vertex(-s, +s, d);
40 | endShape();
41 |
42 | pushMatrix();
43 | translate(0, 0, d);
44 | rotateX(millis()/1000.0);
45 | rotateY(millis()/2000.0);
46 | fill(#6AA4FF);
47 | noStroke();
48 | box(50);
49 | popMatrix();
50 |
51 | fill(0);
52 | text("Welcome to VR!", 0, -h * 0.75, d);
53 | }
--------------------------------------------------------------------------------
/chapter 14/listing_14_5/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=vr
2 |
--------------------------------------------------------------------------------
/chapter 14/listing_14_5/listing_14_5.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | import processing.vr.*;
7 |
8 | PMatrix3D mat = new PMatrix3D();
9 |
10 | void setup() {
11 | fullScreen(STEREO);
12 | hint(ENABLE_STROKE_PERSPECTIVE);
13 | }
14 |
15 | void draw() {
16 | background(120);
17 | translate(width/2, height/2);
18 | lights();
19 |
20 | noStroke();
21 | pushMatrix();
22 | rotateY(millis()/1000.0);
23 | fill(#E3993E);
24 | box(150);
25 | popMatrix();
26 |
27 | eye();
28 | stroke(#2FB1EA);
29 | strokeWeight(50);
30 | line(100, -100, 0, 0, 0, 10000);
31 | }
--------------------------------------------------------------------------------
/chapter 14/listing_14_6/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=vr
2 |
--------------------------------------------------------------------------------
/chapter 14/listing_14_6/listing_14_6.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | import processing.vr.*;
7 |
8 | void setup() {
9 | fullScreen(STEREO);
10 | }
11 |
12 | void draw() {
13 | background(120);
14 | translate(width/2, height/2);
15 |
16 | lights();
17 |
18 | noStroke();
19 | fill(#E3993E);
20 | beginShape(QUAD);
21 | vertex(-75, -75);
22 | vertex(+75, -75);
23 | vertex(+75, +75);
24 | vertex(-75, +75);
25 | endShape(QUAD);
26 |
27 | eye();
28 | stroke(47, 177, 234, 150);
29 | strokeWeight(50);
30 | point(0, 0, 100);
31 | }
--------------------------------------------------------------------------------
/chapter 14/listing_14_7/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=vr
2 |
--------------------------------------------------------------------------------
/chapter 14/listing_14_8/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=vr
2 |
--------------------------------------------------------------------------------
/chapter 14/listing_14_9/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=vr
2 |
--------------------------------------------------------------------------------
/chapter 15/listing_15_1/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=vr
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 15/listing_15_2/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=vr
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 15/listing_15_2/data/cross-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/listing_15_2/data/cross-icon.png
--------------------------------------------------------------------------------
/chapter 15/listing_15_2/data/left-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/listing_15_2/data/left-icon.png
--------------------------------------------------------------------------------
/chapter 15/listing_15_2/data/right-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/listing_15_2/data/right-icon.png
--------------------------------------------------------------------------------
/chapter 15/listing_15_3/Geo.pde:
--------------------------------------------------------------------------------
1 | PShape base;
2 |
3 | void drawBase() {
4 | pushMatrix();
5 | translate(0, +300, 0);
6 | rotateY(angle);
7 | shape(base);
8 | popMatrix();
9 | }
10 |
11 | void createBase(float r, float h, int ndiv) {
12 | base = createShape(GROUP);
13 | PShape side = createShape();
14 | side.beginShape(QUAD_STRIP);
15 | side.noStroke();
16 | side.fill(#59C5F5);
17 | for (int i = 0; i <= ndiv; i++) {
18 | float a = map(i, 0, ndiv, 0, TWO_PI);
19 | float x = r * cos(a);
20 | float z = r * sin(a);
21 | side.vertex(x, +h/2, z);
22 | side.vertex(x, -h/2, z);
23 | }
24 | side.endShape();
25 | PShape top = createShape();
26 | top.beginShape(TRIANGLE_FAN);
27 | top.noStroke();
28 | top.fill(#59C5F5);
29 | top.vertex(0, 0, 0);
30 | for (int i = 0; i <= ndiv; i++) {
31 | float a = map(i, 0, ndiv, 0, TWO_PI);
32 | float x = r * cos(a);
33 | float z = r * sin(a);
34 | top.vertex(x, -h/2, z);
35 | }
36 | top.endShape();
37 | base.addChild(side);
38 | base.addChild(top);
39 | }
--------------------------------------------------------------------------------
/chapter 15/listing_15_3/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=vr
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 15/listing_15_3/data/cross-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/listing_15_3/data/cross-icon.png
--------------------------------------------------------------------------------
/chapter 15/listing_15_3/data/left-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/listing_15_3/data/left-icon.png
--------------------------------------------------------------------------------
/chapter 15/listing_15_3/data/right-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/listing_15_3/data/right-icon.png
--------------------------------------------------------------------------------
/chapter 15/listing_15_3/listing_15_3.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | import processing.vr.*;
7 |
8 | float angle;
9 |
10 | void setup() {
11 | fullScreen(STEREO);
12 | textureMode(NORMAL);
13 | createBase(300, 70, 20);
14 | createButtons(300, 100, 380, 130);
15 | }
16 |
17 | void calculate() {
18 | if (mousePressed) {
19 | if (leftButton.selected) angle -= 0.01;
20 | if (rightButton.selected) angle += 0.01;
21 | }
22 | if (mousePressed && !selectingUI()) {
23 | updateStrokes();
24 | }
25 | }
26 |
27 | void draw() {
28 | background(0);
29 | translate(width/2, height/2);
30 | directionalLight(200, 200, 200, 0, +1, -1);
31 | drawBase();
32 | drawStrokes();
33 | drawUI();
34 | }
35 |
36 | void mouseReleased() {
37 | if (resetButton.selected) {
38 | clearDrawing();
39 | angle = 0;
40 | } else {
41 | startNewStroke();
42 | }
43 | }
--------------------------------------------------------------------------------
/chapter 15/listing_15_4/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=vr
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 15/listing_15_4/data/cross-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/listing_15_4/data/cross-icon.png
--------------------------------------------------------------------------------
/chapter 15/listing_15_4/data/fly-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/listing_15_4/data/fly-icon.png
--------------------------------------------------------------------------------
/chapter 15/listing_15_4/data/home-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/listing_15_4/data/home-icon.png
--------------------------------------------------------------------------------
/chapter 15/listing_15_4/data/left-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/listing_15_4/data/left-icon.png
--------------------------------------------------------------------------------
/chapter 15/listing_15_4/data/right-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/listing_15_4/data/right-icon.png
--------------------------------------------------------------------------------
/chapter 15/listing_15_5/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=vr
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 15/listing_15_5/data/cross-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/listing_15_5/data/cross-icon.png
--------------------------------------------------------------------------------
/chapter 15/listing_15_5/data/fly-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/listing_15_5/data/fly-icon.png
--------------------------------------------------------------------------------
/chapter 15/listing_15_5/data/home-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/listing_15_5/data/home-icon.png
--------------------------------------------------------------------------------
/chapter 15/listing_15_5/data/left-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/listing_15_5/data/left-icon.png
--------------------------------------------------------------------------------
/chapter 15/listing_15_5/data/right-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/listing_15_5/data/right-icon.png
--------------------------------------------------------------------------------
/chapter 15/vr_draw/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=vr
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 15/vr_draw/data/cross-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/vr_draw/data/cross-icon.png
--------------------------------------------------------------------------------
/chapter 15/vr_draw/data/fly-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/vr_draw/data/fly-icon.png
--------------------------------------------------------------------------------
/chapter 15/vr_draw/data/home-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/vr_draw/data/home-icon.png
--------------------------------------------------------------------------------
/chapter 15/vr_draw/data/left-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/vr_draw/data/left-icon.png
--------------------------------------------------------------------------------
/chapter 15/vr_draw/data/right-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/vr_draw/data/right-icon.png
--------------------------------------------------------------------------------
/chapter 15/vr_draw/icon-144.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/vr_draw/icon-144.png
--------------------------------------------------------------------------------
/chapter 15/vr_draw/icon-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/vr_draw/icon-192.png
--------------------------------------------------------------------------------
/chapter 15/vr_draw/icon-36.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/vr_draw/icon-36.png
--------------------------------------------------------------------------------
/chapter 15/vr_draw/icon-48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/vr_draw/icon-48.png
--------------------------------------------------------------------------------
/chapter 15/vr_draw/icon-72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/vr_draw/icon-72.png
--------------------------------------------------------------------------------
/chapter 15/vr_draw/icon-96.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 15/vr_draw/icon-96.png
--------------------------------------------------------------------------------
/chapter 2/listing_2_1/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 2/listing_2_1/listing_2_1.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | int x = 0;
7 |
8 | void setup() {
9 | size(600, 200);
10 | strokeWeight(2);
11 | stroke(255);
12 | }
13 |
14 | void draw() {
15 | background(50);
16 | line(x, 0, x, height); //<>//
17 | x = (x + 1) % width;
18 | }
--------------------------------------------------------------------------------
/chapter 2/listing_2_10/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 2/listing_2_10/listing_2_10.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(600, 300);
7 | strokeWeight(5);
8 | fill(214, 87, 58);
9 | stroke(53, 124, 115);
10 | rect(10, 10, 180, 280);
11 | stroke(115, 48, 128);
12 | fill(252, 215, 51);
13 | rect(210, 10, 180, 280);
14 | stroke(224, 155, 73);
15 | fill(17, 76, 131);
16 | rect(410, 10, 180, 280);
--------------------------------------------------------------------------------
/chapter 2/listing_2_11/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 2/listing_2_11/listing_2_11.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(300, 300);
7 | colorMode(HSB, TWO_PI, 1, 1);
8 | float centerX = width/2;
9 | float centerY = height/2;
10 | float maxRad = width/2;
11 | strokeWeight(2);
12 | stroke(0, 0, 1);
13 | for (int i = 0; i < 6; i++) {
14 | float r0 = map(i, 0, 6, 0, 1);
15 | float r1 = map(i + 1, 0, 6, 0, 1);
16 | beginShape(QUADS);
17 | for (int j = 0; j <= 10; j++) {
18 | float a0 = map(j, 0, 10, 0, TWO_PI);
19 | float a1 = map(j + 1, 0, 10, 0, TWO_PI);
20 | float x0 = centerX + maxRad * r0 * cos(a0);
21 | float y0 = centerY + maxRad * r0 * sin(a0);
22 | float x1 = centerX + maxRad * r1 * cos(a0);
23 | float y1 = centerY + maxRad * r1 * sin(a0);
24 | float x2 = centerX + maxRad * r1 * cos(a1);
25 | float y2 = centerY + maxRad * r1 * sin(a1);
26 | float x3 = centerX + maxRad * r0 * cos(a1);
27 | float y3 = centerY + maxRad * r0 * sin(a1);
28 | fill(a0, r0, 1);
29 | vertex(x0, y0);
30 | vertex(x1, y1);
31 | vertex(x2, y2);
32 | vertex(x3, y3);
33 | }
34 | endShape();
35 | }
--------------------------------------------------------------------------------
/chapter 2/listing_2_12/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 2/listing_2_12/listing_2_12.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | float angle;
7 |
8 | void setup() {
9 | size(400, 400);
10 | rectMode(CENTER);
11 | noStroke();
12 | }
13 |
14 | void draw() {
15 | background(170);
16 | translate(width/2, height/2);
17 | rotate(angle);
18 | rect(0, 0, 100, 100);
19 | pushMatrix();
20 | translate(150, 0);
21 | rotate(2 * angle);
22 | scale(0.5);
23 | rect(0, 0, 100, 100);
24 | popMatrix();
25 | translate(0, 180);
26 | ellipse(0, 0, 30, 30);
27 | angle += 0.01;
28 | }
--------------------------------------------------------------------------------
/chapter 2/listing_2_13/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 2/listing_2_13/listing_2_13.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | size(1000, 500);
8 | noStroke();
9 | fill(255, 100);
10 | }
11 |
12 | void draw() {
13 | if (mousePressed) {
14 | ellipse(mouseX, mouseY, 50, 50);
15 | }
16 | }
--------------------------------------------------------------------------------
/chapter 2/listing_2_14/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 2/listing_2_14/listing_2_14.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen();
8 | }
9 |
10 | void draw() {
11 | if (mousePressed) {
12 | line(pmouseX, pmouseY, mouseX, mouseY);
13 | }
14 | }
--------------------------------------------------------------------------------
/chapter 2/listing_2_15/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 2/listing_2_15/listing_2_15.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | size(600, 160);
8 | frameRate(1);
9 | }
10 |
11 | void draw() {
12 | background(180);
13 | drawFlower(100, 80);
14 | drawFlower(300, 80);
15 | drawFlower(500, 80);
16 | }
17 |
18 | void drawFlower(float posx, float posy) {
19 | pushMatrix();
20 | translate(posx, posy);
21 | fill(random(255), random(255), random(255), 200);
22 | beginShape();
23 | int n = int(random(4, 10));
24 | for (int i = 0; i < n; i++) {
25 | float a = map(i, 0, n, 0, TWO_PI);
26 | float a1 = map(i + 1, 0, n, 0, TWO_PI);
27 | float r = random(10, 100);
28 | float x = r * cos(a);
29 | float y = r * sin(a);
30 | float x1 = r * cos(a1);
31 | float y1 = r * sin(a1);
32 | vertex(0, 0);
33 | bezierVertex(x, y, x1, y1, 0, 0);
34 | }
35 | endShape();
36 | popMatrix();
37 | }
--------------------------------------------------------------------------------
/chapter 2/listing_2_16/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 2/listing_2_16/listing_2_16.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(300, 300);
7 | noFill();
8 | translate(width/2, height/2);
9 | beginShape();
10 | float maxt = 10;
11 | float maxr = 150;
12 | for (float t = 1; t < maxt; t += 0.1) {
13 | float r = maxr/t;
14 | float x = r * cos(t);
15 | float y = r * sin(t);
16 | vertex(x, y);
17 | }
18 | endShape();
--------------------------------------------------------------------------------
/chapter 2/listing_2_17/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 2/listing_2_17/listing_2_17.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | size(600, 160);
8 | frameRate(1);
9 | }
10 |
11 | void draw() {
12 | background(180);
13 | drawSpiral(100, 80, 0);
14 | drawSpiral(300, 80, QUARTER_PI);
15 | drawSpiral(500, 80, PI);
16 | }
17 |
18 | void drawSpiral(float posx, float posy, float angle) {
19 | pushMatrix();
20 | translate(posx, posy);
21 | rotate(angle + PI);
22 | noFill();
23 | beginShape();
24 | float maxt = random(5, 20);
25 | float maxr = random(50, 70);
26 | float x0 = maxr * cos(1);
27 | float y0 = maxr * sin(1);
28 | for (float t = 1; t < maxt; t += 0.1) {
29 | float r = maxr/t;
30 | float x = r * cos(t) - x0;
31 | float y = r * sin(t) - y0;
32 | vertex(x, y);
33 | }
34 | endShape();
35 | popMatrix();
36 | }
--------------------------------------------------------------------------------
/chapter 2/listing_2_18/Flower.pde:
--------------------------------------------------------------------------------
1 | void drawFlower(float xc, float yc) {
2 | pushMatrix();
3 | pushStyle();
4 | noStroke();
5 | translate(xc, yc);
6 | fill(random(60, 79), random(50, 60), 85, 190);
7 | beginShape();
8 | int numLobes = int(random(4, 10));
9 | for (int i = 0; i <= numLobes; i++) {
10 | float a = map(i, 0, numLobes, 0, TWO_PI);
11 | float a1 = map(i + 1, 0, numLobes, 0, TWO_PI);
12 | float r = random(10, 50);
13 | float x = r * cos(a);
14 | float y = r * sin(a);
15 | float x1 = r * cos(a1);
16 | float y1 = r * sin(a1);
17 | vertex(0, 0);
18 | vertex(0, 0);
19 | bezierVertex(x, y, x1, y1, 0, 0);
20 | }
21 | endShape();
22 | popStyle();
23 | popMatrix();
24 | }
--------------------------------------------------------------------------------
/chapter 2/listing_2_18/Spiral.pde:
--------------------------------------------------------------------------------
1 | void drawSpiral(float xc, float yc, float a) {
2 | pushMatrix();
3 | pushStyle();
4 | translate(xc, yc);
5 | rotate(PI + a);
6 | noFill();
7 | beginShape();
8 | float maxt = random(5, 10);
9 | float maxr = random(20, 70);
10 | float sign = (random(1) < 0.5) ? -1 : +1;
11 | float x0 = maxr * cos(sign);
12 | float y0 = maxr * sin(sign);
13 | for (float t = 1; t < maxt; t += 0.5) {
14 | float r = maxr/t;
15 | float x = r * cos(sign * t) - x0;
16 | float y = r * sin(sign * t) - y0;
17 | vertex(x, y);
18 | }
19 | endShape();
20 | noStroke();
21 | fill(random(310, 360), 80, 80);
22 | float x1 = (maxr/maxt) * cos(sign * maxt) - x0;
23 | float y1 = (maxr/maxt) * sin(sign * maxt) - y0;
24 | float r = random(5, 10);
25 | ellipse(x1, y1, r, r);
26 | popStyle();
27 | popMatrix();
28 | }
--------------------------------------------------------------------------------
/chapter 2/listing_2_18/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 2/listing_2_18/listing_2_18.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen();
8 | noFill();
9 | colorMode(HSB, 360, 99, 99);
10 | strokeWeight(2);
11 | stroke(210);
12 | background(0, 0, 99);
13 | }
14 |
15 | void draw() {
16 | if (mousePressed) {
17 | line(pmouseX, pmouseY, mouseX, mouseY);
18 | if (random(1) < 0.05) {
19 |
20 | PVector dir = new PVector(mouseX - pmouseX, mouseY - pmouseY);
21 | float a = dir.heading();
22 | drawSpiral(mouseX, mouseY, a);
23 | }
24 | if (random(1) < 0.05) {
25 | drawFlower(mouseX, mouseY);
26 | }
27 | }
28 | }
29 |
30 | void keyPressed() {
31 | background(0, 0, 99);
32 | }
--------------------------------------------------------------------------------
/chapter 2/listing_2_2/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 2/listing_2_2/listing_2_2.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | int x = 0;
7 |
8 | void setup() {
9 | size(600, 200);
10 | strokeWeight(2);
11 | stroke(255);
12 | }
13 |
14 | void draw() {
15 | background(50);
16 | line(x, 0, x, height);
17 | x = (x + 1) % width;
18 | }
19 |
20 | void keyPressed() {
21 | if (looping) {
22 | noLoop();
23 | } else {
24 | loop();
25 | }
26 | }
--------------------------------------------------------------------------------
/chapter 2/listing_2_3/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 2/listing_2_3/listing_2_3.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(200, 200);
7 | ellipse(100, 100, 150, 150);
--------------------------------------------------------------------------------
/chapter 2/listing_2_4/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 2/listing_2_4/listing_2_4.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(460, 200);
7 | strokeWeight(5);
8 | fill(255, 0, 0);
9 | stroke(0, 255, 0);
10 | ellipse(100, 100, 200, 200);
11 | fill(255, 0, 200); // Comment this line out to make second circle red
12 | stroke(0);
13 | ellipse(250, 100, 100, 100);
14 | fill(0, 200, 200);
15 | ellipse(380, 100, 160, 160);
--------------------------------------------------------------------------------
/chapter 2/listing_2_5/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 2/listing_2_5/listing_2_5.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(800, 800);
7 | stroke(0);
8 | fill(180);
9 | background(97);
10 | line(width/2, 0, width/2, height);
11 | line(0, height/2, width, height/2);
12 | rect(0, 0, 200, 200);
13 | rect(width - 200, 0, 199, 200);
14 | rect(width - 200, height - 200, 199, 199);
15 | rect(0, height - 200, 199, 199);
16 | rect(200, 200, width - 400, height - 400);
--------------------------------------------------------------------------------
/chapter 2/listing_2_6/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 2/listing_2_6/listing_2_6.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(600, 300);
7 |
8 | beginShape(QUADS);
9 | vertex(5, 250);
10 | vertex(590, 250);
11 | vertex(590, 290);
12 | vertex(5, 290);
13 | endShape();
14 |
15 | beginShape();
16 | vertex(30, 25);
17 | vertex(90, 90);
18 | vertex(210, 10);
19 | vertex(160, 120);
20 | vertex(210, 270);
21 | vertex(110, 180);
22 | vertex(10, 270);
23 | vertex(60, 150);
24 | endShape(CLOSE);
25 |
26 | beginShape(TRIANGLES);
27 | vertex(50, 30);
28 | vertex(90, 75);
29 | vertex(110, 30);
30 | endShape();
31 |
32 | ellipse(470, 80, 70, 70);
--------------------------------------------------------------------------------
/chapter 2/listing_2_7/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 2/listing_2_7/listing_2_7.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(300, 300);
7 | int numTriangles = 10;
8 | beginShape(TRIANGLE_FAN);
9 | vertex(width/2, height/2);
10 | for (int i = 0; i <= numTriangles; i++) {
11 | float a = map(i, 0, numTriangles, 0, TWO_PI);
12 | float x = width/2 + 100 * cos(a);
13 | float y = height/2 + 100 * sin(a);
14 | vertex(x, y);
15 | }
16 | endShape();
--------------------------------------------------------------------------------
/chapter 2/listing_2_8/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 2/listing_2_8/listing_2_8.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(300, 300);
7 | beginShape(QUAD_STRIP);
8 | int numQuads = 10;
9 | for (int i = 0; i <= numQuads; i++) {
10 | float a = map(i, 0, numQuads, 0, TWO_PI);
11 | float x0 = width/2 + 100 * cos(a);
12 | float y0 = height/2 + 100 * sin(a);
13 | float x1 = width/2 + 130 * cos(a);
14 | float y1 = height/2 + 130 * sin(a);
15 | vertex(x0, y0);
16 | vertex(x1, y1);
17 | }
18 | endShape();
--------------------------------------------------------------------------------
/chapter 2/listing_2_9/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 2/listing_2_9/listing_2_9.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(300, 300);
7 | int numLobes = 4;
8 | float radAnchor = 50;
9 | float radControl = 150;
10 | float centerX = width/2;
11 | float centerY = height/2;
12 | beginShape();
13 | for (int i = 0; i < numLobes; i++) {
14 | float a = map(i, 0, numLobes, 0, TWO_PI);
15 | float a1 = map(i + 1, 0, numLobes, 0, TWO_PI);
16 | float cx0 = centerX + radControl * cos(a);
17 | float cy0 = centerY + radControl * sin(a);
18 | float cx1 = centerX + radControl * cos(a1);
19 | float cy1 = centerY + radControl * sin(a1);
20 | float x0 = centerX + radAnchor * cos(a);
21 | float y0 = centerY + radAnchor * sin(a);
22 | float x1 = centerX + radAnchor * cos(a1);
23 | float y1 = centerY + radAnchor * sin(a1);
24 | vertex(x0, y0);
25 | bezierVertex(cx0, cy0, cx1, cy1, x1, y1);
26 | }
27 | endShape();
--------------------------------------------------------------------------------
/chapter 3/listing_3_1/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 3/listing_3_1/listing_3_1.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen();
8 | }
9 |
10 | void draw() {
11 | println("frame #", frameCount);
12 | }
13 |
14 | void mousePressed() {
15 | println("Press event");
16 | }
--------------------------------------------------------------------------------
/chapter 3/listing_3_2/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 3/listing_3_2/listing_3_2.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen();
8 | noStroke();
9 | }
10 |
11 | void draw() {
12 | background(0);
13 | float r = 50 * displayDensity;
14 | int maxi = int(width/r);
15 | int maxj = int(height/r);
16 | for (int i = 0; i <= maxi; i++) {
17 | float x = map(i, 0, maxi, 0, width);
18 | for (int j = 0; j <= maxj; j++) {
19 | float y = map(j, 0, maxj, 0, height);
20 | ellipse(x, y, r, r);
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/chapter 3/vines_draw/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/chapter 3/vines_draw/Flower.pde:
--------------------------------------------------------------------------------
1 | void drawFlower(float xc, float yc) {
2 | pushMatrix();
3 | pushStyle();
4 | noStroke();
5 | translate(xc, yc);
6 | fill(random(60, 79), random(50, 60), 85, 190);
7 | beginShape();
8 | int numLobes = int(random(4, 10));
9 | for (int i = 0; i <= numLobes; i++) {
10 | float a = map(i, 0, numLobes, 0, TWO_PI);
11 | float a1 = map(i + 1, 0, numLobes, 0, TWO_PI);
12 | float r = random(10, 50) * displayDensity;
13 | float x = r * cos(a);
14 | float y = r * sin(a);
15 | float x1 = r * cos(a1);
16 | float y1 = r * sin(a1);
17 | vertex(0, 0);
18 | vertex(0, 0);
19 | bezierVertex(x, y, x1, y1, 0, 0);
20 | }
21 | endShape();
22 | popStyle();
23 | popMatrix();
24 | }
--------------------------------------------------------------------------------
/chapter 3/vines_draw/Spiral.pde:
--------------------------------------------------------------------------------
1 | void drawSpiral(float xc, float yc, float a) {
2 | pushMatrix();
3 | pushStyle();
4 | translate(xc, yc);
5 | rotate(PI + a);
6 | noFill();
7 | beginShape();
8 | float maxr = random(20, 70) * displayDensity;
9 | float maxt = random(5, 10);
10 | float sign = (random(1) < 0.5) ? -1 : +1;
11 | float x0 = maxr * cos(sign);
12 | float y0 = maxr * sin(sign);
13 | for (float t = 1; t < maxt; t += 0.5) {
14 | float r = maxr/t;
15 | float x = r * cos(sign * t) - x0;
16 | float y = r * sin(sign * t) - y0;
17 | vertex(x, y);
18 | }
19 | endShape();
20 | noStroke();
21 | fill(random(310, 360), 80, 80);
22 | float x1 = (maxr/maxt) * cos(sign * maxt) - x0;
23 | float y1 = (maxr/maxt) * sin(sign * maxt) - y0;
24 | float r = random(5, 10) * displayDensity;
25 | ellipse(x1, y1, r, r);
26 | popStyle();
27 | popMatrix();
28 | }
--------------------------------------------------------------------------------
/chapter 3/vines_draw/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 3/vines_draw/icon-144.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 3/vines_draw/icon-144.png
--------------------------------------------------------------------------------
/chapter 3/vines_draw/icon-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 3/vines_draw/icon-192.png
--------------------------------------------------------------------------------
/chapter 3/vines_draw/icon-36.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 3/vines_draw/icon-36.png
--------------------------------------------------------------------------------
/chapter 3/vines_draw/icon-48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 3/vines_draw/icon-48.png
--------------------------------------------------------------------------------
/chapter 3/vines_draw/icon-72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 3/vines_draw/icon-72.png
--------------------------------------------------------------------------------
/chapter 3/vines_draw/icon-96.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 3/vines_draw/icon-96.png
--------------------------------------------------------------------------------
/chapter 3/vines_draw/vines_draw.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen();
8 | noFill();
9 | colorMode(HSB, 360, 99, 99);
10 | strokeWeight(2);
11 | stroke(210);
12 | background(0, 0, 99);
13 | }
14 |
15 | void draw() {
16 | if (mousePressed) {
17 | line(pmouseX, pmouseY, mouseX, mouseY);
18 | if (random(1) < 0.05) {
19 |
20 | PVector dir = new PVector(mouseX - pmouseX, mouseY - pmouseY);
21 | float a = dir.heading();
22 | drawSpiral(mouseX, mouseY, a);
23 | }
24 | if (random(1) < 0.05) {
25 | drawFlower(mouseX, mouseY);
26 | }
27 | }
28 | }
29 |
30 | void keyPressed() {
31 | background(0, 0, 99);
32 | }
--------------------------------------------------------------------------------
/chapter 4/listing_4_1/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_1/listing_4_1.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen(P2D);
8 | background(255);
9 | noFill();
10 | rectMode(CENTER);
11 | }
12 |
13 | void draw() {
14 | float w = 2*(width/2-mouseX);
15 | rect(width/2, height/2, w, w/width * height);
16 | }
--------------------------------------------------------------------------------
/chapter 4/listing_4_10/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Java
2 | component=app
3 | mode.id=processing.mode.java.JavaMode
4 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_10/listing_4_10.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | Circle[] circles = new Circle[100];
7 |
8 | void setup() {
9 | size(800, 800);
10 | for (int i = 0; i < circles.length; i++) {
11 | circles[i] = new Circle();
12 | }
13 | }
14 |
15 | void draw() {
16 | translate(width/2, height/2);
17 | rotate(frameCount * 0.01);
18 | for (int i = 0; i < circles.length; i++) {
19 | circles[i].display();
20 | }
21 | }
22 |
23 | class Circle {
24 | float x, y, r, w;
25 | color fc, sc;
26 | Circle() {
27 | x = random(-width/2, width/2);
28 | y = random(-height/2, height/2);
29 | r = random(10, 100);
30 | w = random(2, 10);
31 | fc = color(random(255), random(255), random(255));
32 | sc = color(random(255), random(255), random(255));
33 | }
34 | void display() {
35 | pushStyle();
36 | stroke(sc);
37 | strokeWeight(w);
38 | fill(fc);
39 | ellipse(x, y, r, r);
40 | popStyle();
41 | }
42 | }
--------------------------------------------------------------------------------
/chapter 4/listing_4_11/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_11/listing_4_11.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | size(300, 300);
8 | }
9 |
10 | void draw() {
11 | background(190);
12 | translate(width/2, height/2);
13 | float r = width/2;
14 | beginShape();
15 | circleVertices(0, 0, r, 0, TWO_PI);
16 | makeContour(0, 0, r/4);
17 | makeContour(-r/2, -r/2, r/4);
18 | makeContour(+r/2, -r/2, r/4);
19 | makeContour(-r/2, +r/2, r/4);
20 | makeContour(+r/2, +r/2, r/4);
21 | endShape();
22 | }
23 |
24 | void makeContour(float xc, float yc, float r) {
25 | beginContour();
26 | circleVertices(xc, yc, r, TWO_PI, 0);
27 | endContour();
28 | }
29 |
30 | void circleVertices(float xc, float yc, float r, float a0, float a1) {
31 | for (int i = 0; i <= 30; i++) {
32 | float a = map(i, 0, 30, a0, a1);
33 | vertex(xc + r * cos(a), yc + r * sin(a));
34 | }
35 | }
--------------------------------------------------------------------------------
/chapter 4/listing_4_12/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_12/listing_4_12.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(650, 200, P2D);
7 | PShape circle = createShape(ELLIPSE, 100, 100, 100, 100);
8 | PShape poly = createShape();
9 | poly.beginShape(QUADS);
10 | poly.vertex(200, 50);
11 | poly.vertex(300, 50);
12 | poly.vertex(300, 150);
13 | poly.vertex(200, 150);
14 | poly.endShape();
15 | PShape group = createShape(GROUP);
16 | group.addChild(circle);
17 | group.addChild(poly);
18 | shape(circle);
19 | shape(poly);
20 | translate(300, 0);
21 | shape(group);
--------------------------------------------------------------------------------
/chapter 4/listing_4_13/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_13/listing_4_13.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | PShape grid, sel;
7 |
8 | void setup() {
9 | fullScreen(P2D);
10 | orientation(LANDSCAPE);
11 | grid = createShape(GROUP);
12 | for (int j = 0; j < 4; j++) {
13 | float y0 = map(j, 0, 4, 0, height) + 10;
14 | float y1 = map(j+1, 0, 4, 0, height) - 10;
15 | for (int i = 0; i < 8; i++) {
16 | float x0 = map(i, 0, 8, 0, width) + 10;
17 | float x1 = map(i+1, 0, 8, 0, width) - 10;
18 | PShape sh = createShape(RECT, x0, y0, x1 - x0, y1 - y0, 30);
19 | grid.addChild(sh);
20 | }
21 | }
22 | }
23 |
24 | void draw() {
25 | background(180);
26 | shape(grid);
27 | }
28 |
29 | void mousePressed() {
30 | int i = int(float(mouseX) / width * 8);
31 | int j = int(float(mouseY) / height * 4);
32 | int idx = j * 8 + i;
33 | sel = grid.getChild(idx);
34 | sel.setFill(color(#FA2D45));
35 | }
36 |
37 | void mouseReleased() {
38 | sel.setFill(color(#C252FF));
39 | }
--------------------------------------------------------------------------------
/chapter 4/listing_4_14/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_14/data/cc.svg:
--------------------------------------------------------------------------------
1 |
6 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_14/data/ruby.svg:
--------------------------------------------------------------------------------
1 |
13 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_14/listing_4_14.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(450, 200, P2D);
7 | PShape cc = loadShape("cc.svg");
8 | PShape moz = loadShape("mozilla.svg");
9 | PShape ruby = loadShape("ruby.svg");
10 | translate(30, 50);
11 | cc.setFill(color(170, 116, 0));
12 | cc.setStroke(color(255, 155, 0));
13 | shape(cc);
14 | translate(cc.width + 30, 0);
15 | shape(moz);
16 | translate(moz.width + 30, 0);
17 | shape(ruby);
--------------------------------------------------------------------------------
/chapter 4/listing_4_15/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_15/listing_4_15.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | PShape world;
7 |
8 | void setup() {
9 | size(950, 620, P2D);
10 | world = loadShape("World-map.svg");
11 | for (PShape child: world.getChildren()) {
12 | if (child.getName().equals("algeria")) child.setFill(color(255, 0, 0));
13 | }
14 | }
15 |
16 | void draw() {
17 | background(255);
18 | shape(world);
19 | }
--------------------------------------------------------------------------------
/chapter 4/listing_4_16/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_16/data/paine.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 4/listing_4_16/data/paine.jpg
--------------------------------------------------------------------------------
/chapter 4/listing_4_16/listing_4_16.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | fullScreen();
7 | PImage img = loadImage("paine.jpg");
8 | image(img, 0, 0, width, height);
--------------------------------------------------------------------------------
/chapter 4/listing_4_17/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_17/data/paine.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 4/listing_4_17/data/paine.jpg
--------------------------------------------------------------------------------
/chapter 4/listing_4_17/listing_4_17.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | PImage img;
7 | void setup() {
8 | size(800, 533);
9 | img = loadImage("paine.jpg");
10 | }
11 |
12 | void draw() {
13 | image(img, 0, 0, width/2, height/2);
14 | tint(255, 0, 0);
15 | image(img, width/2, 0, width/2, height/2);
16 | tint(0, 255, 0);
17 | image(img, 0, height/2, width/2, height/2);
18 | tint(0, 0, 255);
19 | image(img, width/2, height/2, width/2, height/2);
20 | noTint();
21 | }
--------------------------------------------------------------------------------
/chapter 4/listing_4_18/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_18/data/paine.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 4/listing_4_18/data/paine.jpg
--------------------------------------------------------------------------------
/chapter 4/listing_4_18/listing_4_18.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | PImage img;
7 | size(800, 533, P2D);
8 | img = loadImage("paine.jpg");
9 | beginShape();
10 | texture(img);
11 | vertex(100, 0, 0, 0);
12 | vertex(width - 100, 0, img.width, 0);
13 | vertex(width, height, img.width, img.height);
14 | vertex(0, height, 0, img.height);
15 | endShape();
--------------------------------------------------------------------------------
/chapter 4/listing_4_19/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_19/data/SansSerif-32.vlw:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 4/listing_4_19/data/SansSerif-32.vlw
--------------------------------------------------------------------------------
/chapter 4/listing_4_19/listing_4_19.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(450, 100);
7 | PFont font = loadFont("SansSerif-32.vlw");
8 | textFont(font);
9 | fill(120);
10 | text("On Exactitude in Science", 40, 60);
--------------------------------------------------------------------------------
/chapter 4/listing_4_2/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Java
2 | component=app
3 | mode.id=processing.mode.java.JavaMode
4 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_2/listing_4_2.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | int[] types = {POINTS, LINES, TRIANGLES,
7 | TRIANGLE_STRIP, TRIANGLE_FAN,
8 | QUADS, QUAD_STRIP, POLYGON};
9 | int selected = 0;
10 |
11 | void setup() {
12 | size(300, 300);
13 | strokeWeight(2);
14 | }
15 |
16 | void draw() {
17 | background(150);
18 | beginShape(types[selected]);
19 | for (int i = 0; i <= 10; i++) {
20 | float a = map(i, 0, 10, 0, TWO_PI);
21 | float x0 = width/2 + 100 * cos(a);
22 | float y0 = height/2 + 100 * sin(a);
23 | float x1 = width/2 + 130 * cos(a);
24 | float y1 = height/2 + 130 * sin(a);
25 | vertex(x0, y0);
26 | vertex(x1, y1);
27 | }
28 | endShape();
29 | }
30 |
31 | void mousePressed() {
32 | selected = (selected + 1) % types.length;
33 | println("Drawing shape", selected);
34 | }
--------------------------------------------------------------------------------
/chapter 4/listing_4_20/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_20/data/SansSerif-32.vlw:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 4/listing_4_20/data/SansSerif-32.vlw
--------------------------------------------------------------------------------
/chapter 4/listing_4_20/listing_4_20.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(450, 100);
7 | PFont font = createFont("SansSerif", 32);
8 | textFont(font);
9 | fill(120);
10 | text("On Exactitude in Science", 40, 60);
--------------------------------------------------------------------------------
/chapter 4/listing_4_21/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_21/listing_4_21.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(900, 300);
7 | PFont font = createFont("Monospaced", 32);
8 | textFont(font);
9 | fill(120);
10 | text("...In that Empire, the Art of Cartography attained such Perfection " +
11 | "that the map of a single Province occupied the entirety of a City, " +
12 | "and the map of the Empire, the entirety of a Province.", 20, 20,
13 | width - 40, height - 40);
--------------------------------------------------------------------------------
/chapter 4/listing_4_22/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_22/listing_4_22.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(900, 300);
7 | PFont titleFont = createFont("Serif", 32);
8 | PFont textFont = createFont("Serif", 28);
9 | textFont(titleFont);
10 | textAlign(CENTER);
11 | fill(120);
12 | text("On Exactitude in Science", width/2, 60);
13 | textFont(textFont);
14 | textAlign(RIGHT);
15 | textLeading(60);
16 | text("...In that Empire, the Art of Cartography attained such Perfection " +
17 | "that the map of a single Province occupied the entirety of a City, " +
18 | "and the map of the Empire, the entirety of a Province.",
19 | 20, 100, width - 40, height - 20);
--------------------------------------------------------------------------------
/chapter 4/listing_4_23/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_23/data/borges.txt:
--------------------------------------------------------------------------------
1 | On Exactitude in Science
2 | ... In that Empire, the Art of Cartography attained such Perfection that the map of a single Province occupied the entirety of a City, and the map of the Empire, the entirety of a Province. In time, those Unconscionable Maps no longer satisfied, and the Cartographers Guilds struck a Map of the Empire whose size was that of the Empire, and which coincided point for point with it. The following Generations, who were not so fond of the Study of Cartography as their Forebears had been, saw that that vast map was Useless, and not without some Pitilessness was it, that they delivered it up to the Inclemencies of Sun and Winters. In the Deserts of the West, still today, there are Tattered Ruins of that Map, inhabited by Animals and Beggars; in all the Land there is no other Relic of the Disciplines of Geography.
3 | purportedly from Suárez Miranda, Travels of Prudent Men, Book Four, Ch. XLV, Lérida, 1658
--------------------------------------------------------------------------------
/chapter 4/listing_4_23/listing_4_23.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | fullScreen();
7 | orientation(PORTRAIT);
8 | PFont titleFont = createFont("Serif-Bold", 25 * displayDensity);
9 | PFont bodyFont = createFont("Serif", 18 * displayDensity);
10 | PFont footFont = createFont("Serif-Italic", 15 * displayDensity);
11 | String[] lines = loadStrings("borges.txt");
12 | String title = lines[0];
13 | String body = lines[1];
14 | String footer = lines[2];
15 | textFont(titleFont);
16 | textAlign(CENTER, CENTER);
17 | fill(120);
18 | text(title, 10, 10, width - 20, height * 0.1 - 20);
19 | textFont(bodyFont);
20 | text(body, 10, height * 0.1, width - 20, height * 0.8);
21 | textAlign(RIGHT, BOTTOM);
22 | textFont(footFont);
23 | text(footer, 10, height * 0.9 + 10, width - 20, height * 0.1 - 20);
--------------------------------------------------------------------------------
/chapter 4/listing_4_3/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_3/listing_4_3.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(480, 480);
7 | translate(width/2, height/2);
8 | int numPoints = 100;
9 | int degree = 5;
10 | beginShape();
11 | float[] coeffs = new float[degree];
12 | for (int d = 0; d < degree; d++) {
13 | coeffs[d] = random(0, 1);
14 | }
15 | float phase = random(0, TWO_PI);
16 | for (int i = 0; i <= numPoints; i++) {
17 | float theta = map(i, 0, numPoints, 0, TWO_PI);
18 | float rho = 5;
19 | for (int d = 1; d <= degree; d++) {
20 | rho += coeffs[d - 1] * sin(d*theta+phase);
21 | }
22 | float x = 30 * rho * cos(theta);
23 | float y = 30 * rho * sin(theta);
24 | vertex(x, y);
25 | }
26 | endShape();
--------------------------------------------------------------------------------
/chapter 4/listing_4_4/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_4/listing_4_4.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(480, 480);
7 |
8 | PVector[] points = new PVector[11];
9 | for (int i = 0; i <= 10; i++) {
10 | if (i < 10) {
11 | float a = map(i, 0, 10, 0, TWO_PI);
12 | float r = random(100, 200);
13 | points[i] = new PVector(r * cos(a), r * sin(a));
14 | } else {
15 | points[10] = points[0].copy();
16 | }
17 | }
18 |
19 | translate(width/2, height/2);
20 | fill(255);
21 | beginShape();
22 | for (int i = 0; i <= 10; i++) {
23 | if (i == 0 || i == 10) curveVertex(points[i].x, points[i].y);
24 | curveVertex(points[i].x, points[i].y);
25 | }
26 | endShape();
27 |
28 | fill(0);
29 | for (int i = 0; i <= 10; i++) {
30 | ellipse(points[i].x, points[i].y, 10, 10);
31 | }
--------------------------------------------------------------------------------
/chapter 4/listing_4_5/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_5/listing_4_5.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(480, 480);
7 |
8 | PVector[] points = new PVector[11];
9 | PVector[] directions = new PVector[11];
10 | for (int i = 0; i <= 10; i++) {
11 | if (i < 10) {
12 | float a = map(i, 0, 10, 0, TWO_PI);
13 | float r = random(100, 200);
14 | points[i] = new PVector(r * cos(a), r * sin(a));
15 | directions[i] = PVector.fromAngle(points[i].heading() +
16 | random(0, QUARTER_PI));
17 | directions[i].mult(60);
18 | } else {
19 | points[10] = points[0].copy();
20 | directions[10] = directions[0].copy();
21 | }
22 | }
23 |
24 | translate(width/2, height/2);
25 | strokeWeight(2);
26 | fill(255);
27 | beginShape();
28 | for (int i = 0; i < 10; i++) {
29 | vertex(points[i].x, points[i].y);
30 | PVector CP1 = PVector.add(points[i], directions[i]);
31 | PVector CP2 = PVector.sub(points[i+1], directions[i+1]);
32 | bezierVertex(CP1.x, CP1.y, CP2.x, CP2.y, points[i+1].x, points[i+1].y);
33 | }
34 | endShape();
--------------------------------------------------------------------------------
/chapter 4/listing_4_6/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_7/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_8/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_8/listing_4_8.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(800, 480);
7 | float x = width/2;
8 | float y = height/2;
9 | stroke(0, 150);
10 | strokeWeight(10);
11 | strokeJoin(ROUND);
12 | strokeCap(ROUND);
13 | beginShape(LINES);
14 | for (int i = 0; i < 100; i++) {
15 | float px = x;
16 | float py = y;
17 | float nx = x + (random(0, 1) > 0.5? -1: +1) * 50;
18 | float ny = y + (random(0, 1) > 0.5? -1: +1) * 50;
19 | if (0 <= nx && nx < width && 0 <= ny && ny < height) {
20 | vertex(px, py);
21 | vertex(nx, ny);
22 | x = nx;
23 | y = ny;
24 | }
25 | }
26 | endShape();
--------------------------------------------------------------------------------
/chapter 4/listing_4_9/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 4/listing_4_9/listing_4_9.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | size(300, 300, P2D);
7 | colorMode(HSB, 360, 100, 100);
8 | background(0, 0, 100);
9 | translate(width/2, height/2);
10 | noStroke();
11 | beginShape(TRIANGLE_FAN);
12 | fill(TWO_PI, 0, 100);
13 | vertex(0, 0);
14 | for (int i = 0; i <= 10; i++) {
15 | float a = map(i, 0, 10, 0, 360);
16 | float x = 150 * cos(radians(a));
17 | float y = 150 * sin(radians(a));
18 | fill(a, 100, 100);
19 | vertex(x, y);
20 | }
21 | endShape();
--------------------------------------------------------------------------------
/chapter 5/listing_5_1/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Java
2 | component=app
3 | mode.id=processing.mode.java.JavaMode
4 |
--------------------------------------------------------------------------------
/chapter 5/listing_5_1/listing_5_1.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen();
8 | strokeWeight(20);
9 | fill(#3B91FF);
10 | }
11 |
12 | void draw() {
13 | background(#FFD53B);
14 | stroke(#3B91FF);
15 | line(0, 0, mouseX, mouseY);
16 | line(width, 0, mouseX, mouseY);
17 | line(width, height, mouseX, mouseY);
18 | line(0, height, mouseX, mouseY);
19 | noStroke();
20 | ellipse(mouseX, mouseY, 200, 200);
21 | }
--------------------------------------------------------------------------------
/chapter 5/listing_5_10/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 5/listing_5_11/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 5/listing_5_12/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 5/listing_5_12/data/jelly.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 5/listing_5_12/data/jelly.jpg
--------------------------------------------------------------------------------
/chapter 5/listing_5_12/listing_5_12.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | import android.os.Looper;
7 | import android.view.MotionEvent;
8 | import android.view.ScaleGestureDetector;
9 | import android.view.ScaleGestureDetector.SimpleOnScaleGestureListener;
10 |
11 | ScaleGestureDetector detector;
12 | PImage img;
13 | float scaleFactor = 1;
14 |
15 | void setup() {
16 | fullScreen();
17 | img = loadImage("jelly.jpg");
18 | Looper.prepare();
19 | detector = new ScaleGestureDetector(surface.getActivity(), new ScaleListener());
20 | imageMode(CENTER);
21 | }
22 |
23 | boolean surfaceTouchEvent(MotionEvent event) {
24 | detector.onTouchEvent(event);
25 | return super.surfaceTouchEvent(event);
26 | }
27 |
28 | void draw() {
29 | background(180);
30 | translate(width/2, height/2);
31 | scale(scaleFactor);
32 | image(img, 0, 0);
33 | }
34 |
35 | class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
36 | public boolean onScale(ScaleGestureDetector detector) {
37 | scaleFactor *= detector.getScaleFactor();
38 | scaleFactor = constrain(scaleFactor, 0.1, 5);
39 | return true;
40 | }
41 | }
--------------------------------------------------------------------------------
/chapter 5/listing_5_13/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 5/listing_5_13/listing_5_13.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | String text = "touch the screen to type something";
7 | boolean keyboard = false;
8 |
9 | void setup() {
10 | fullScreen();
11 | textFont(createFont("Monospaced", 25 * displayDensity));
12 | textAlign(CENTER);
13 | fill(100);
14 | }
15 |
16 | void draw() {
17 | background(200);
18 | text(text, 0, 20, width, height - 40);
19 | }
20 |
21 | void keyReleased() {
22 | if (key == DELETE || key == BACKSPACE) {
23 | text = text.substring(text.length() - 1);
24 | } else {
25 | text += key;
26 | }
27 | }
28 |
29 | void mouseReleased() {
30 | if (!keyboard) {;
31 | text = "";
32 | openKeyboard();
33 | keyboard = true;
34 | } else {
35 | closeKeyboard();
36 | keyboard = false;
37 | }
38 | }
--------------------------------------------------------------------------------
/chapter 5/listing_5_2/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Java
2 | component=app
3 | mode.id=processing.mode.java.JavaMode
4 |
--------------------------------------------------------------------------------
/chapter 5/listing_5_2/listing_5_2.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | boolean drawing = false;
7 | float radius;
8 |
9 | void setup() {
10 | fullScreen();
11 | noStroke();
12 | fill(100, 100);
13 | }
14 |
15 | void draw() {
16 | background(255);
17 | if (drawing) {
18 | ellipse(mouseX, mouseY, radius, radius);
19 | }
20 | }
21 |
22 | void mousePressed() {
23 | drawing = true;
24 | radius = 70 * displayDensity;
25 | }
26 |
27 | void mouseReleased() {
28 | drawing = false;
29 | }
30 |
31 | void mouseDragged() {
32 | radius += 0.5 * displayDensity;
33 | }
--------------------------------------------------------------------------------
/chapter 5/listing_5_3/Circle.pde:
--------------------------------------------------------------------------------
1 | class Circle {
2 | color c;
3 | float x, y, r;
4 | Circle(float x, float y) {
5 | this.x = x;
6 | this.y = y;
7 | r = 70 * displayDensity;
8 | c = color(random(255), random(255), random(255), 100);
9 | }
10 | void grow() {
11 | r += 0.5 * displayDensity;
12 | }
13 | void setPosition(float x, float y) {
14 | this.x = x;
15 | this.y = y;
16 | }
17 | void draw() {
18 | fill(c);
19 | ellipse(x, y, r, r);
20 | }
21 | }
--------------------------------------------------------------------------------
/chapter 5/listing_5_3/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Java
2 | component=app
3 | mode.id=processing.mode.java.JavaMode
4 |
--------------------------------------------------------------------------------
/chapter 5/listing_5_3/listing_5_3.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | ArrayList circles;
7 | Circle newCircle;
8 |
9 | void setup() {
10 | fullScreen();
11 | circles = new ArrayList();
12 | noStroke();
13 | }
14 |
15 | void draw() {
16 | background(255);
17 | for (Circle c: circles) {
18 | c.draw();
19 | }
20 | if (newCircle != null) newCircle.draw();
21 | }
22 |
23 | void mousePressed() {
24 | newCircle = new Circle(mouseX, mouseY);
25 | }
26 |
27 | void mouseReleased() {
28 | circles.add(newCircle);
29 | newCircle = null;
30 | }
31 |
32 | void mouseDragged() {
33 | newCircle.setPosition(mouseX, mouseY);
34 | newCircle.grow();
35 | }
--------------------------------------------------------------------------------
/chapter 5/listing_5_4/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Java
2 | component=app
3 | mode.id=processing.mode.java.JavaMode
4 |
--------------------------------------------------------------------------------
/chapter 5/listing_5_4/listing_5_4.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen();
8 | background(180);
9 | strokeWeight(10 * displayDensity);
10 | stroke(100, 100);
11 | }
12 |
13 | void draw() {
14 | if (mousePressed) line(pmouseX, pmouseY, mouseX, mouseY);
15 | }
16 |
17 |
--------------------------------------------------------------------------------
/chapter 5/listing_5_5/Circle.pde:
--------------------------------------------------------------------------------
1 | class Circle {
2 | color c;
3 | float x, y, r, vx, vy;
4 | Circle(float x, float y) {
5 | this.x = x;
6 | this.y = y;
7 | r = 70 * displayDensity;
8 | c = color(random(255), random(255), random(255), 100);
9 | }
10 | void grow() {
11 | r += 0.5 * displayDensity;
12 | }
13 | void setPosition(float x, float y) {
14 | this.x = x;
15 | this.y = y;
16 | }
17 | void setVelocity(float vx, float vy) {
18 | this.vx = vx;
19 | this.vy = vy;
20 | }
21 | void draw() {
22 | x += vx;
23 | y += vy;
24 | if (x < 0 || x > width) vx = -vx;
25 | if (y < 0 || y > height) vy = -vy;
26 | fill(c);
27 | ellipse(x, y, r, r);
28 | }
29 | }
--------------------------------------------------------------------------------
/chapter 5/listing_5_5/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 5/listing_5_5/listing_5_5.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | ArrayList circles;
7 | Circle newCircle;
8 |
9 | void setup() {
10 | fullScreen();
11 | circles = new ArrayList();
12 | noStroke();
13 | }
14 |
15 | void draw() {
16 | background(255);
17 | for (Circle c: circles) {
18 | c.draw();
19 | }
20 | if (newCircle != null) newCircle.draw();
21 | }
22 |
23 | void mousePressed() {
24 | newCircle = new Circle(mouseX, mouseY);
25 | }
26 |
27 | void mouseReleased() {
28 | newCircle.setVelocity(mouseX - pmouseX, mouseY - pmouseY);
29 | circles.add(newCircle);
30 | newCircle = null;
31 | }
32 |
33 | void mouseDragged() {
34 | newCircle.setPosition(mouseX, mouseY);
35 | newCircle.grow();
36 | }
--------------------------------------------------------------------------------
/chapter 5/listing_5_6/Circle.pde:
--------------------------------------------------------------------------------
1 | class Circle {
2 | color c;
3 | float x, y, r, vx, vy;
4 | Circle(float x, float y) {
5 | this.x = x;
6 | this.y = y;
7 | r = 70 * displayDensity;
8 | c = color(random(255), random(255), random(255), 100);
9 | }
10 | void grow() {
11 | r += 0.5 * displayDensity;
12 | }
13 | void setPosition(float x, float y) {
14 | this.x = x;
15 | this.y = y;
16 | }
17 | void setVelocity(float vx, float vy) {
18 | this.vx = vx;
19 | this.vy = vy;
20 | }
21 | void draw() {
22 | x += vx;
23 | y += vy;
24 | if (x < 0 || x > width) vx = -vx;
25 | if (y < 0 || y > height) vy = -vy;
26 | fill(c);
27 | ellipse(x, y, r, r);
28 | }
29 | }
--------------------------------------------------------------------------------
/chapter 5/listing_5_6/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 5/listing_5_6/listing_5_6.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | ArrayList circles;
7 | Circle newCircle;
8 | float buttonHeight = 200 * displayDensity;
9 |
10 | void setup() {
11 | fullScreen();
12 | circles = new ArrayList();
13 | noStroke();
14 | textFont(createFont("SansSerif", 23 * displayDensity));
15 | textAlign(CENTER, CENTER);
16 | }
17 |
18 | void draw() {
19 | background(255);
20 | for (Circle c: circles) {
21 | c.draw();
22 | }
23 | if (newCircle != null) newCircle.draw();
24 | fill(100, 180);
25 | rect(0, height - buttonHeight, width, buttonHeight);
26 | fill(80);
27 | text("Touch this area to clear", 0, height - buttonHeight, width, buttonHeight);
28 | }
29 |
30 | void mousePressed() {
31 | newCircle = new Circle(mouseX, mouseY);
32 | }
33 |
34 | void mouseReleased() {
35 | newCircle.setVelocity(mouseX - pmouseX, mouseY - pmouseY);
36 | circles.add(newCircle);
37 | newCircle = null;
38 | if (height - buttonHeight < mouseY) circles.clear();
39 | }
40 |
41 | void mouseDragged() {
42 | newCircle.setPosition(mouseX, mouseY);
43 | newCircle.grow();
44 | }
--------------------------------------------------------------------------------
/chapter 5/listing_5_7/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 5/listing_5_7/listing_5_7.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen();
8 | noStroke();
9 | colorMode(HSB, 350, 100, 100);
10 | textFont(createFont("SansSerif", displayDensity * 24));
11 | }
12 |
13 | void draw() {
14 | background(30, 0, 100);
15 | fill(30, 0, 20);
16 | text("Number of touch points: " + touches.length, 20, displayDensity * 50);
17 | for (int i = 0; i < touches.length; i++) {
18 | float s = displayDensity * map(touches[i].area, 0, 1, 30, 300);
19 | fill(30, map(touches[i].pressure, 0.6, 1.6, 0, 100), 70, 200);
20 | ellipse(touches[i].x, touches[i].y, s, s);
21 | }
22 | }
23 |
24 | void touchStarted() {
25 | println("Touch started");
26 | }
27 |
28 | void touchEnded() {
29 | println("Touch ended");
30 | }
31 |
32 | void touchMoved() {
33 | println("Touch moved");
34 | }
--------------------------------------------------------------------------------
/chapter 5/listing_5_8/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 5/listing_5_9/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Java
2 | component=app
3 | mode.id=processing.mode.java.JavaMode
4 |
--------------------------------------------------------------------------------
/chapter 6/image_flow/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/chapter 6/image_flow/Field.pde:
--------------------------------------------------------------------------------
1 | class Field {
2 | PImage flowImage;
3 |
4 | synchronized void update(String fn) {
5 | flowImage = loadImage(fn);
6 | flowImage.loadPixels();
7 | }
8 |
9 | synchronized PVector lookupVector(PVector v) {
10 | if (flowImage == null) return PVector.random2D();
11 | color c = flowImage.pixels[getPixelIndex(v.x, v.y)];
12 | float theta = map(brightness(c), 0, 255, 0, TWO_PI);
13 | return PVector.fromAngle(theta);
14 | }
15 |
16 | synchronized color lookupColor(PVector v) {
17 | if (flowImage == null) return color(0, 0, 100, 0);
18 | color c = flowImage.pixels[getPixelIndex(v.x, v.y)];
19 | float h = hue(c);
20 | float s = saturation(c);
21 | float b = 50;
22 | return color(h, s, b, 70);
23 | }
24 |
25 | int getPixelIndex(float x, float y) {
26 | int ix = int(map(x, 0, width, 0, flowImage.width - 1));
27 | int iy = int(map(y, 0, height, 0, flowImage.height - 1));
28 | return constrain(ix + iy * flowImage.width, 0, flowImage.pixels.length - 1);
29 | }
30 | }
--------------------------------------------------------------------------------
/chapter 6/image_flow/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=wallpaper
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 6/image_flow/data/default.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 6/image_flow/data/default.jpg
--------------------------------------------------------------------------------
/chapter 6/image_flow/icon-144.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 6/image_flow/icon-144.png
--------------------------------------------------------------------------------
/chapter 6/image_flow/icon-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 6/image_flow/icon-192.png
--------------------------------------------------------------------------------
/chapter 6/image_flow/icon-36.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 6/image_flow/icon-36.png
--------------------------------------------------------------------------------
/chapter 6/image_flow/icon-48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 6/image_flow/icon-48.png
--------------------------------------------------------------------------------
/chapter 6/image_flow/icon-72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 6/image_flow/icon-72.png
--------------------------------------------------------------------------------
/chapter 6/image_flow/icon-96.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 6/image_flow/icon-96.png
--------------------------------------------------------------------------------
/chapter 6/listing_6_1/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=wallpaper
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 6/listing_6_1/listing_6_1.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | void setup() {
7 | fullScreen();
8 | frameRate(25);
9 | noStroke();
10 | fill(#FF03F3);
11 | }
12 |
13 | void draw() {
14 | background(#6268FF);
15 | float maxRad = 50 * displayDensity;
16 | for (int i = 0; i < width/maxRad; i++) {
17 | float x = map(i, 0, int(width/maxRad) - 1, 0, width);
18 | for (int j = 0; j < height/maxRad; j++) {
19 | float y = map(j, 0, int(height/maxRad) - 1, 0, height);
20 | float t = millis() / 1000.0;
21 | float r = maxRad * cos(t + 0.1 * PI * i * j);
22 | ellipse(x, y, r, r);
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/chapter 6/listing_6_10/Field.pde:
--------------------------------------------------------------------------------
1 | class Field {
2 | PImage flowImage;
3 |
4 | void update(String fn) {
5 | flowImage = loadImage(fn);
6 | flowImage.loadPixels();
7 | }
8 |
9 | PVector lookupVector(PVector v) {
10 | if (flowImage == null) return PVector.random2D();
11 | color c = flowImage.pixels[getPixelIndex(v.x, v.y)];
12 | float theta = map(brightness(c), 0, 255, 0, TWO_PI);
13 | return PVector.fromAngle(theta);
14 | }
15 |
16 | color lookupColor(PVector v) {
17 | if (flowImage == null) return color(0, 0, 100, 0);
18 | return flowImage.pixels[getPixelIndex(v.x, v.y)];
19 | }
20 |
21 | int getPixelIndex(float x, float y) {
22 | int ix = int(map(x, 0, width, 0, flowImage.width - 1));
23 | int iy = int(map(y, 0, height, 0, flowImage.height - 1));
24 | return constrain(ix + iy * flowImage.width, 0, flowImage.pixels.length - 1);
25 | }
26 | }
--------------------------------------------------------------------------------
/chapter 6/listing_6_10/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=wallpaper
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 6/listing_6_10/data/default.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 6/listing_6_10/data/default.jpg
--------------------------------------------------------------------------------
/chapter 6/listing_6_11/Field.pde:
--------------------------------------------------------------------------------
1 | class Field {
2 | PImage flowImage;
3 |
4 | synchronized void update(String fn) {
5 | flowImage = loadImage(fn);
6 | flowImage.loadPixels();
7 | }
8 |
9 | synchronized PVector lookupVector(PVector v) {
10 | if (flowImage == null) return PVector.random2D();
11 | color c = flowImage.pixels[getPixelIndex(v.x, v.y)];
12 | float theta = map(brightness(c), 0, 255, 0, TWO_PI);
13 | return PVector.fromAngle(theta);
14 | }
15 |
16 | synchronized color lookupColor(PVector v) {
17 | if (flowImage == null) return color(0, 0, 100, 0);
18 | return flowImage.pixels[getPixelIndex(v.x, v.y)];
19 | }
20 |
21 | int getPixelIndex(float x, float y) {
22 | int ix = int(map(x, 0, width, 0, flowImage.width - 1));
23 | int iy = int(map(y, 0, height, 0, flowImage.height - 1));
24 | return constrain(ix + iy * flowImage.width, 0, flowImage.pixels.length - 1);
25 | }
26 | }
--------------------------------------------------------------------------------
/chapter 6/listing_6_11/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=wallpaper
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 6/listing_6_11/data/default.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 6/listing_6_11/data/default.jpg
--------------------------------------------------------------------------------
/chapter 6/listing_6_12/Field.pde:
--------------------------------------------------------------------------------
1 | class Field {
2 | PImage flowImage;
3 |
4 | synchronized void update(String fn) {
5 | flowImage = loadImage(fn);
6 | flowImage.loadPixels();
7 | }
8 |
9 | synchronized PVector lookupVector(PVector v) {
10 | if (flowImage == null) return PVector.random2D();
11 | color c = flowImage.pixels[getPixelIndex(v.x, v.y)];
12 | float theta = map(brightness(c), 0, 255, 0, TWO_PI);
13 | return PVector.fromAngle(theta);
14 | }
15 |
16 | synchronized color lookupColor(PVector v) {
17 | if (flowImage == null) return color(0, 0, 100, 0);
18 | color c = flowImage.pixels[getPixelIndex(v.x, v.y)];
19 | float h = hue(c);
20 | float s = saturation(c);
21 | float b = 50;
22 | return color(h, s, b, 70);
23 | }
24 |
25 | int getPixelIndex(float x, float y) {
26 | int ix = int(map(x, 0, width, 0, flowImage.width - 1));
27 | int iy = int(map(y, 0, height, 0, flowImage.height - 1));
28 | return constrain(ix + iy * flowImage.width, 0, flowImage.pixels.length - 1);
29 | }
30 | }
--------------------------------------------------------------------------------
/chapter 6/listing_6_12/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=wallpaper
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 6/listing_6_12/data/default.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 6/listing_6_12/data/default.jpg
--------------------------------------------------------------------------------
/chapter 6/listing_6_2/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=wallpaper
2 |
--------------------------------------------------------------------------------
/chapter 6/listing_6_2/data/paine.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 6/listing_6_2/data/paine.jpg
--------------------------------------------------------------------------------
/chapter 6/listing_6_2/listing_6_2.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | PImage pic;
7 | fullScreen();
8 | pic = loadImage("paine.jpg");
9 | image(pic, 0, 0, width, height);
--------------------------------------------------------------------------------
/chapter 6/listing_6_3/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=wallpaper
2 |
--------------------------------------------------------------------------------
/chapter 6/listing_6_3/data/paine.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 6/listing_6_3/data/paine.jpg
--------------------------------------------------------------------------------
/chapter 6/listing_6_3/listing_6_3.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | PImage pic;
7 | fullScreen();
8 | pic = loadImage("paine.jpg");
9 | imageMode(CENTER);
10 | float r = float(pic.width) / float(pic.height);
11 | float h = width/r;
12 | image(pic, width/2, height/2, width, h);
--------------------------------------------------------------------------------
/chapter 6/listing_6_4/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=wallpaper
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 6/listing_6_4/data/paine.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 6/listing_6_4/data/paine.jpg
--------------------------------------------------------------------------------
/chapter 6/listing_6_4/listing_6_4.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | PImage pic;
7 | float ratio;
8 |
9 | void setup() {
10 | fullScreen();
11 | pic = loadImage("paine.jpg");
12 | ratio = float(pic.width)/float(pic.height);
13 | }
14 |
15 | void draw() {
16 | background(0);
17 | float w = wallpaperHomeCount() * width;
18 | float h = w/ratio;
19 | float x = map(wallpaperOffset(), 0, 1, 0, -(wallpaperHomeCount()-1) * width);
20 | image(pic, x, 0, w, h);
21 | }
--------------------------------------------------------------------------------
/chapter 6/listing_6_5/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 6/listing_6_5/listing_6_5.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | color bckColor = #EA6411;
7 |
8 | void setup() {
9 | fullScreen();
10 | requestPermission("android.permission.READ_EXTERNAL_STORAGE", "handlePermission");
11 | }
12 |
13 | void draw() {
14 | background(bckColor);
15 | }
16 |
17 | void handlePermission(boolean granted) {
18 | if (granted) bckColor = #58EA11;
19 | }
--------------------------------------------------------------------------------
/chapter 6/listing_6_6/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=wallpaper
2 |
--------------------------------------------------------------------------------
/chapter 6/listing_6_6/data/default.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 6/listing_6_6/data/default.jpg
--------------------------------------------------------------------------------
/chapter 6/listing_6_7/Particle.pde:
--------------------------------------------------------------------------------
1 | class Particle {
2 | PVector position;
3 | PVector velocity;
4 | PVector acceleration;
5 | float size;
6 | int life;
7 | float maxAccel;
8 | float maxSpeed;
9 | int maxLife;
10 |
11 | Particle(float x, float y) {
12 | position = new PVector(x, y);
13 | size = random(15, 25);
14 | velocity = new PVector(0, 0);
15 | acceleration = new PVector(0, 0);
16 | maxSpeed = random(2, 5);
17 | maxAccel = random(0.1, 0.5);
18 | maxLife = int(random(100, 200));
19 | }
20 |
21 | boolean dead() {
22 | return maxLife < life;
23 | }
24 |
25 | public void setPosition(float x, float y) {
26 | position.set(x, y);
27 | }
28 |
29 | void update(Field flow) {
30 | PVector desired = flow.lookup(int(position.x), int(position.y));
31 | acceleration.x = maxSpeed * desired.x - velocity.x;
32 | acceleration.y = maxSpeed * desired.y - velocity.y;
33 | acceleration.limit(maxAccel);
34 | velocity.add(acceleration);
35 | velocity.limit(maxSpeed);
36 | position.add(velocity);
37 | life++;
38 | }
39 |
40 | void display() {
41 | noStroke();
42 | fill(180, 150);
43 | ellipse(position.x, position.y, size, size);
44 | }
45 | }
--------------------------------------------------------------------------------
/chapter 6/listing_6_7/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Java
2 | component=app
3 | mode.id=processing.mode.java.JavaMode
4 |
--------------------------------------------------------------------------------
/chapter 6/listing_6_7/data/brush.ai:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 6/listing_6_7/data/brush.ai
--------------------------------------------------------------------------------
/chapter 6/listing_6_7/data/brush.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 6/listing_6_7/data/brush.png
--------------------------------------------------------------------------------
/chapter 6/listing_6_7/data/brush2.ai:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 6/listing_6_7/data/brush2.ai
--------------------------------------------------------------------------------
/chapter 6/listing_6_7/data/brush2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 6/listing_6_7/data/brush2.png
--------------------------------------------------------------------------------
/chapter 6/listing_6_7/listing_6_7.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | ArrayList particles;
7 | Field field;
8 |
9 | void setup() {
10 | size(1200, 600);
11 | field = new Field();
12 | particles = new ArrayList();
13 | }
14 |
15 | void draw() {
16 | background(255);
17 | field.display();
18 | for (int i = particles.size() - 1; i >= 0; i--) {
19 | Particle p = particles.get(i);
20 | p.update(field);
21 | p.display();
22 | if (p.dead()) particles.remove(i);
23 | }
24 |
25 | }
26 |
27 | void mouseDragged() {
28 | field.update(mouseX, mouseY, mouseX - pmouseX, mouseY - pmouseY);
29 | particles.add(new Particle(mouseX, mouseY));
30 | }
--------------------------------------------------------------------------------
/chapter 6/listing_6_8/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 6/listing_6_8/data/jupiter.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 6/listing_6_8/data/jupiter.jpg
--------------------------------------------------------------------------------
/chapter 6/listing_6_9/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=wallpaper
2 |
--------------------------------------------------------------------------------
/chapter 6/listing_6_9/data/default.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 6/listing_6_9/data/default.jpg
--------------------------------------------------------------------------------
/chapter 7/listing_7_1/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 7/listing_7_1/listing_7_1.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | import android.content.Context;
7 | import android.hardware.Sensor;
8 | import android.hardware.SensorManager;
9 |
10 | Context context;
11 | SensorManager manager;
12 | Sensor sensor;
13 |
14 | void setup() {
15 | fullScreen();
16 | context = getContext();
17 | manager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
18 | sensor = manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
19 | }
20 |
21 | void draw() {
22 | }
--------------------------------------------------------------------------------
/chapter 7/listing_7_2/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 7/listing_7_2/listing_7_2.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | import android.content.Context;
7 | import android.hardware.Sensor;
8 | import android.hardware.SensorManager;
9 | import android.hardware.SensorEvent;
10 | import android.hardware.SensorEventListener;
11 |
12 | Context context;
13 | SensorManager manager;
14 | Sensor sensor;
15 | AccelerometerListener listener;
16 |
17 | void setup() {
18 | fullScreen();
19 | context = getActivity();
20 | manager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
21 | sensor = manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
22 | listener = new AccelerometerListener();
23 | manager.registerListener(listener, sensor,
24 | SensorManager.SENSOR_DELAY_NORMAL);
25 | }
26 |
27 | void draw() {
28 | }
29 |
30 | class AccelerometerListener implements SensorEventListener {
31 | public void onSensorChanged(SensorEvent event) {
32 | }
33 | public void onAccuracyChanged(Sensor sensor, int accuracy) {
34 | }
35 | }
--------------------------------------------------------------------------------
/chapter 7/listing_7_3/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 7/listing_7_4/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 7/listing_7_5/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 7/listing_7_5/listing_7_5.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | import ketai.sensors.*;
7 |
8 | KetaiSensor sensor;
9 | float accelerometerX, accelerometerY, accelerometerZ;
10 |
11 | void setup() {
12 | fullScreen();
13 | sensor = new KetaiSensor(this);
14 | sensor.start();
15 | textAlign(CENTER, CENTER);
16 | textSize(displayDensity * 36);
17 | }
18 |
19 | void draw() {
20 | background(78, 93, 75);
21 | text("Accelerometer: \n" +
22 | "x: " + nfp(accelerometerX, 1, 3) + "\n" +
23 | "y: " + nfp(accelerometerY, 1, 3) + "\n" +
24 | "z: " + nfp(accelerometerZ, 1, 3), 0, 0, width, height);
25 | }
26 |
27 | void onAccelerometerEvent(float x, float y, float z) {
28 | accelerometerX = x;
29 | accelerometerY = y;
30 | accelerometerZ = z;
31 | }
--------------------------------------------------------------------------------
/chapter 7/listing_7_6/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 7/listing_7_6/listing_7_6.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | import ketai.sensors.*;
7 |
8 | KetaiSensor sensor;
9 | float rotationX, rotationY, rotationZ;
10 |
11 | void setup() {
12 | fullScreen();
13 | sensor = new KetaiSensor(this);
14 | sensor.start();
15 | textAlign(CENTER, CENTER);
16 | textSize(displayDensity * 24);
17 | }
18 |
19 | void draw() {
20 | background(78, 93, 75);
21 | text("Gyroscope: \n" +
22 | "x: " + nfp(rotationX, 1, 3) + "\n" +
23 | "y: " + nfp(rotationY, 1, 3) + "\n" +
24 | "z: " + nfp(rotationZ, 1, 3), 0, 0, width, height);
25 | }
26 |
27 | void onGyroscopeEvent(float x, float y, float z) {
28 | rotationX = x;
29 | rotationY = y;
30 | rotationZ = z;
31 | }
--------------------------------------------------------------------------------
/chapter 7/listing_7_7/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 8/listing_8_1/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 8/listing_8_1/listing_8_1.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | import ketai.sensors.*;
7 | import android.hardware.SensorManager;
8 |
9 | KetaiSensor sensor;
10 | PVector accel = new PVector();
11 | int shakeTime;
12 |
13 | color bColor = color(78, 93, 75);
14 |
15 | void setup() {
16 | fullScreen();
17 | sensor = new KetaiSensor(this);
18 | sensor.start();
19 | textAlign(CENTER, CENTER);
20 | textSize(displayDensity * 36);
21 | }
22 |
23 | void draw() {
24 | background(bColor);
25 | text("Accelerometer: \n" +
26 | "x: " + nfp(accel.x, 1, 3) + "\n" +
27 | "y: " + nfp(accel.y, 1, 3) + "\n" +
28 | "z: " + nfp(accel.z, 1, 3), 0, 0, width, height);
29 | }
30 |
31 | void onAccelerometerEvent(float x, float y, float z) {
32 | accel.set(x, y, z);
33 | int now = millis();
34 | if (now - shakeTime > 250) {
35 | if (1.2 * SensorManager.GRAVITY_EARTH < accel.mag()) {
36 | bColor = color(216, 100, 46);
37 | shakeTime = now;
38 | } else {
39 | bColor = color(78, 93, 75);
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/chapter 8/listing_8_10/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 8/listing_8_10/listing_8_10.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | import ketai.sensors.*;
7 |
8 | KetaiSensor sensor;
9 | float rotationX, rotationY, rotationZ;
10 |
11 | void setup() {
12 | fullScreen(P3D);
13 | orientation(LANDSCAPE);
14 | sensor = new KetaiSensor(this);
15 | sensor.start();
16 | rectMode(CENTER);
17 | fill(180);
18 | }
19 |
20 | void draw() {
21 | background(255);
22 | translate(width/2, height/2);
23 | rotateZ(rotationZ);
24 | rotateY(rotationX);
25 | rotateX(rotationY);
26 | box(height * 0.3);
27 | }
28 |
29 | void onGyroscopeEvent(float x, float y, float z) {
30 | rotationX += 0.1 * x;
31 | rotationY += 0.1 * y;
32 | rotationZ += 0.1 * z;
33 | }
--------------------------------------------------------------------------------
/chapter 8/listing_8_11/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 8/listing_8_11/listing_8_11.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | import ketai.sensors.*;
7 |
8 | KetaiSensor sensor;
9 | float rotationX, rotationY, rotationZ;
10 | float offsetX, offsetY, offsetZ;
11 |
12 | void setup() {
13 | fullScreen(P3D);
14 | orientation(LANDSCAPE);
15 | sensor = new KetaiSensor(this);
16 | sensor.start();
17 | rectMode(CENTER);
18 | fill(180);
19 | }
20 |
21 | void draw() {
22 | background(255);
23 | translate(width/2, height/2);
24 | rotateZ(rotationZ - offsetZ);
25 | rotateY(rotationX - offsetX);
26 | rotateX(rotationY - offsetY);
27 | box(height * 0.3);
28 | }
29 |
30 | void onGyroscopeEvent(float x, float y, float z) {
31 | rotationX += 0.1 * x;
32 | rotationY += 0.1 * y;
33 | rotationZ += 0.1 * z;
34 | }
35 |
36 | void mousePressed() {
37 | offsetX = rotationX;
38 | offsetY = rotationY;
39 | offsetZ = rotationZ;
40 | }
--------------------------------------------------------------------------------
/chapter 8/listing_8_12/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 8/listing_8_12/listing_8_12.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | import ketai.sensors.*;
7 |
8 | KetaiSensor sensor;
9 | float rotationZ, offsetZ;
10 |
11 | void setup() {
12 | fullScreen(P2D);
13 | orientation(LANDSCAPE);
14 | sensor = new KetaiSensor(this);
15 | sensor.start();
16 | rectMode(CENTER);
17 | fill(180);
18 | }
19 |
20 | void draw() {
21 | background(255);
22 | translate(width/2, height/2);
23 | rotate(rotationZ - offsetZ);
24 | rect(0, 0, height * 0.3, height * 0.3);
25 | }
26 |
27 | void onGyroscopeEvent(float x, float y, float z) {
28 | rotationZ += 0.1 * z;
29 | }
30 |
31 | void mousePressed() {
32 | offsetZ = rotationZ;
33 | }
--------------------------------------------------------------------------------
/chapter 8/listing_8_13/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 8/listing_8_2/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 8/listing_8_2/listing_8_2.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | import ketai.sensors.*;
7 |
8 | KetaiSensor sensor;
9 | color bColor = color(78, 93, 75);
10 | int stepTime = 0;
11 | int stepCount = 0;
12 |
13 | void setup() {
14 | fullScreen();
15 | orientation(PORTRAIT);
16 | sensor = new KetaiSensor(this);
17 | sensor.start();
18 | textAlign(CENTER, CENTER);
19 | textSize(displayDensity * 24);
20 | }
21 |
22 | void draw() {
23 | if (millis() - stepTime > 500) {
24 | bColor = color(78, 93, 75);
25 | }
26 | background(bColor);
27 | text("Number of steps = " + stepCount, 0, 0, width, height);
28 | }
29 |
30 | void onStepDetectorEvent() {
31 | bColor = color(216, 100, 46);
32 | stepTime = millis();
33 | stepCount++;
34 | }
--------------------------------------------------------------------------------
/chapter 8/listing_8_3/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Java
2 | component=app
3 | mode.id=processing.mode.java.JavaMode
4 |
--------------------------------------------------------------------------------
/chapter 8/listing_8_3/data/4C.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_3/data/4C.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_3/data/4D.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_3/data/4D.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_3/data/4E.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_3/data/4E.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_3/data/4F.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_3/data/4F.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_3/data/4G.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_3/data/4G.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_3/data/5A.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_3/data/5A.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_4/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 8/listing_8_4/data/4C.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_4/data/4C.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_4/data/4D.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_4/data/4D.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_4/data/4E.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_4/data/4E.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_4/data/4F.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_4/data/4F.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_4/data/4G.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_4/data/4G.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_4/data/5A.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_4/data/5A.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_5/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 8/listing_8_5/data/4C.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_5/data/4C.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_5/data/4D.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_5/data/4D.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_5/data/4E.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_5/data/4E.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_5/data/4F.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_5/data/4F.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_5/data/4G.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_5/data/4G.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_5/data/5A.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_5/data/5A.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_6/AudioPlayer.pde:
--------------------------------------------------------------------------------
1 | import android.media.MediaPlayer;
2 | import android.content.res.AssetFileDescriptor;
3 | import android.media.AudioManager;
4 |
5 | class AudioPlayer extends MediaPlayer {
6 | boolean loadFile(PApplet app, String fileName) {
7 | AssetFileDescriptor desc;
8 | try {
9 | desc = app.getActivity().getAssets().openFd(fileName);
10 | } catch (IOException e) {
11 | println("Error loading " + fileName);
12 | println(e.getMessage());
13 | return false;
14 | }
15 |
16 | if (desc == null) {
17 | println("Cannot find " + fileName);
18 | return false;
19 | }
20 |
21 | try {
22 | setDataSource(desc.getFileDescriptor(), desc.getStartOffset(), desc.getLength());
23 | setAudioStreamType(AudioManager.STREAM_MUSIC);
24 | prepare();
25 | return true;
26 | } catch (IOException e) {
27 | println(e.getMessage());
28 | return false;
29 | }
30 | }
31 |
32 | void play() {
33 | if (isPlaying()) seekTo(0);
34 | start();
35 | }
36 | }
--------------------------------------------------------------------------------
/chapter 8/listing_8_6/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 8/listing_8_6/data/4C.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_6/data/4C.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_6/data/4D.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_6/data/4D.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_6/data/4E.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_6/data/4E.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_6/data/4F.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_6/data/4F.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_6/data/4G.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_6/data/4G.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_6/data/5A.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 8/listing_8_6/data/5A.wav
--------------------------------------------------------------------------------
/chapter 8/listing_8_7/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 8/listing_8_7/listing_8_7.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | import ketai.sensors.*;
7 | import android.hardware.GeomagneticField;
8 |
9 | KetaiSensor sensor;
10 | float expMag, obsMag;
11 |
12 | void setup() {
13 | fullScreen();
14 | sensor = new KetaiSensor(this);
15 | sensor.start();
16 | GeomagneticField geoField = new GeomagneticField(14.0093, 120.996147, 300, System.currentTimeMillis());
17 | expMag = geoField.getFieldStrength()/1000;
18 | }
19 |
20 | void draw() {
21 | println(obsMag, expMag);
22 | if (obsMag < 0.7 * expMag || 1.3 * expMag < obsMag) {
23 | background(255);
24 | } else {
25 | background(0);
26 | }
27 | }
28 |
29 | void onMagneticFieldEvent(float x, float y, float z) {
30 | obsMag = sqrt(sq(x) + sq(y) + sq(z));
31 | }
--------------------------------------------------------------------------------
/chapter 8/listing_8_8/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=wallpaper
2 |
--------------------------------------------------------------------------------
/chapter 8/listing_8_9/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 8/listing_8_9/listing_8_9.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | import ketai.sensors.*;
7 |
8 | float orientation[] = new float[3];
9 | float easing = 0.05;
10 | float azimuth;
11 |
12 | KetaiSensor sensor;
13 |
14 | void setup() {
15 | fullScreen(P2D);
16 | orientation(PORTRAIT);
17 | sensor = new KetaiSensor(this);
18 | sensor.enableAccelerometer();
19 | sensor.enableMagenticField();
20 | sensor.start();
21 | }
22 |
23 | void draw() {
24 | background(255);
25 |
26 | float cx = width * 0.5;
27 | float cy = height * 0.4;
28 | float radius = 0.8 * cx;
29 |
30 | translate(cx, cy);
31 |
32 | noFill();
33 | stroke(0);
34 | strokeWeight(2);
35 | ellipse(0, 0, radius*2, radius*2);
36 | line(0, -cy, 0, -radius);
37 |
38 | sensor.getOrientation(orientation);
39 | azimuth += easing * (orientation[0] - azimuth);
40 |
41 | fill(192, 0, 0);
42 | noStroke();
43 | rotate(-azimuth);
44 | beginShape();
45 | vertex(-30, 40);
46 | vertex(0, 0);
47 | vertex(30, 40);
48 | vertex(0, -radius);
49 | endShape();
50 | }
--------------------------------------------------------------------------------
/chapter 9/listing_9_1/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 9/listing_9_10/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Java
2 | component=app
3 | mode.id=processing.mode.java.JavaMode
4 |
--------------------------------------------------------------------------------
/chapter 9/listing_9_10/data/streetview0.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/listing_9_10/data/streetview0.jpg
--------------------------------------------------------------------------------
/chapter 9/listing_9_10/data/streetview1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/listing_9_10/data/streetview1.jpg
--------------------------------------------------------------------------------
/chapter 9/listing_9_10/data/streetview2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/listing_9_10/data/streetview2.jpg
--------------------------------------------------------------------------------
/chapter 9/listing_9_10/data/streetview3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/listing_9_10/data/streetview3.jpg
--------------------------------------------------------------------------------
/chapter 9/listing_9_10/data/streetview4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/listing_9_10/data/streetview4.jpg
--------------------------------------------------------------------------------
/chapter 9/listing_9_10/data/streetview5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/listing_9_10/data/streetview5.jpg
--------------------------------------------------------------------------------
/chapter 9/listing_9_10/data/streetview6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/listing_9_10/data/streetview6.jpg
--------------------------------------------------------------------------------
/chapter 9/listing_9_10/data/streetview7.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/listing_9_10/data/streetview7.jpg
--------------------------------------------------------------------------------
/chapter 9/listing_9_10/data/streetview8.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/listing_9_10/data/streetview8.jpg
--------------------------------------------------------------------------------
/chapter 9/listing_9_10/data/streetview9.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/listing_9_10/data/streetview9.jpg
--------------------------------------------------------------------------------
/chapter 9/listing_9_11/LocationListener.pde:
--------------------------------------------------------------------------------
1 | void initLocation(boolean granted) {
2 | if (granted) {
3 | Context context = getContext();
4 | listener = new SimpleListener();
5 | manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
6 | provider = LocationManager.NETWORK_PROVIDER;
7 | if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
8 | provider = LocationManager.GPS_PROVIDER;
9 | }
10 | manager.requestLocationUpdates(provider, 30000, 20, listener);
11 | }
12 | }
13 |
14 | class SimpleListener implements LocationListener {
15 | public void onLocationChanged(Location loc) {
16 | queue.add(new LocationValue(loc.getLatitude(), loc.getLongitude()));
17 | }
18 | public void onProviderDisabled(String provider) { }
19 | public void onProviderEnabled(String provider) { }
20 | public void onStatusChanged(String provider, int status, Bundle extras) { }
21 | }
22 |
23 | public void resume() {
24 | if (manager != null) {
25 | manager.requestLocationUpdates(provider, 30000, 20, listener);
26 | }
27 | }
28 |
29 | public void pause() {
30 | if (manager != null) {
31 | manager.removeUpdates(listener);
32 | }
33 | }
--------------------------------------------------------------------------------
/chapter 9/listing_9_11/Voronoi.pde:
--------------------------------------------------------------------------------
1 | class VoronoiPoint {
2 | float x, y;
3 | PImage img;
4 |
5 | VoronoiPoint(float x, float y, PImage img){
6 | this.x = x;
7 | this.y = y;
8 | this.img = img;
9 | img.loadPixels();
10 | }
11 |
12 | color getColor(int idx) {
13 | return img.pixels[idx];
14 | }
15 | }
16 |
17 | int findClosestPoint(float x, float y) {
18 | int minIdx = -1;
19 | float minDist = 1000;
20 | for (int i = 0; i < points.length; i++) {
21 | VoronoiPoint p = points[i];
22 | if (p == null) break;
23 | float d = dist(x, y, p.x, p.y);
24 | if (d < minDist) {
25 | minIdx = i;
26 | minDist = d;
27 | }
28 | }
29 | return minIdx;
30 | }
--------------------------------------------------------------------------------
/chapter 9/listing_9_11/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=wallpaper
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 9/listing_9_2/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 9/listing_9_3/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=app
2 |
--------------------------------------------------------------------------------
/chapter 9/listing_9_4/code/sketch.properties:
--------------------------------------------------------------------------------
1 | component=wallpaper
2 |
--------------------------------------------------------------------------------
/chapter 9/listing_9_5/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 9/listing_9_6/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 9/listing_9_6/listing_9_6.pde:
--------------------------------------------------------------------------------
1 | // Processing for Android:
2 | // Create Mobile, Sensor-Aware, and VR Applications Using Processing
3 | // Andres Colubri
4 | // http://p5android-book.andrescolubri.net/
5 |
6 | PImage street;
7 | String apiKey = "";
8 |
9 | void setup () {
10 | size(512, 512);
11 | street = requestImage("http://maps.googleapis.com/maps/api/streetview?location=42.383401,-71.116110&size=512x512&fov=90&pitch=-10&key=" + apiKey);
12 | }
13 |
14 | void draw() {
15 | if (0 < street.width && 0 < street.height) {
16 | image(street, 0, 0, width, height);
17 | }
18 | }
--------------------------------------------------------------------------------
/chapter 9/listing_9_7/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=app
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 9/listing_9_8/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Java
2 | component=app
3 | mode.id=processing.mode.java.JavaMode
4 |
--------------------------------------------------------------------------------
/chapter 9/listing_9_9/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Java
2 | component=app
3 | mode.id=processing.mode.java.JavaMode
4 |
--------------------------------------------------------------------------------
/chapter 9/listing_9_9/data/streetview0.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/listing_9_9/data/streetview0.jpg
--------------------------------------------------------------------------------
/chapter 9/listing_9_9/data/streetview1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/listing_9_9/data/streetview1.jpg
--------------------------------------------------------------------------------
/chapter 9/listing_9_9/data/streetview2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/listing_9_9/data/streetview2.jpg
--------------------------------------------------------------------------------
/chapter 9/listing_9_9/data/streetview3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/listing_9_9/data/streetview3.jpg
--------------------------------------------------------------------------------
/chapter 9/listing_9_9/data/streetview4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/listing_9_9/data/streetview4.jpg
--------------------------------------------------------------------------------
/chapter 9/listing_9_9/data/streetview5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/listing_9_9/data/streetview5.jpg
--------------------------------------------------------------------------------
/chapter 9/listing_9_9/data/streetview6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/listing_9_9/data/streetview6.jpg
--------------------------------------------------------------------------------
/chapter 9/listing_9_9/data/streetview7.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/listing_9_9/data/streetview7.jpg
--------------------------------------------------------------------------------
/chapter 9/listing_9_9/data/streetview8.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/listing_9_9/data/streetview8.jpg
--------------------------------------------------------------------------------
/chapter 9/listing_9_9/data/streetview9.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/listing_9_9/data/streetview9.jpg
--------------------------------------------------------------------------------
/chapter 9/street_collage/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/chapter 9/street_collage/LocationListener.pde:
--------------------------------------------------------------------------------
1 | void initLocation(boolean granted) {
2 | if (granted) {
3 | Context context = getContext();
4 | listener = new SimpleListener();
5 | manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
6 | provider = LocationManager.NETWORK_PROVIDER;
7 | if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
8 | provider = LocationManager.GPS_PROVIDER;
9 | }
10 | manager.requestLocationUpdates(provider, 30000, 20, listener);
11 | }
12 | }
13 |
14 | class SimpleListener implements LocationListener {
15 | public void onLocationChanged(Location loc) {
16 | queue.add(new LocationValue(loc.getLatitude(), loc.getLongitude()));
17 | }
18 | public void onProviderDisabled(String provider) { }
19 | public void onProviderEnabled(String provider) { }
20 | public void onStatusChanged(String provider, int status, Bundle extras) { }
21 | }
22 |
23 | public void resume() {
24 | if (manager != null) {
25 | manager.requestLocationUpdates(provider, 30000, 20, listener);
26 | }
27 | }
28 |
29 | public void pause() {
30 | if (manager != null) {
31 | manager.removeUpdates(listener);
32 | }
33 | }
--------------------------------------------------------------------------------
/chapter 9/street_collage/Voronoi.pde:
--------------------------------------------------------------------------------
1 | class VoronoiPoint {
2 | float x, y;
3 | PImage img;
4 |
5 | VoronoiPoint(float x, float y, PImage img){
6 | this.x = x;
7 | this.y = y;
8 | this.img = img;
9 | img.loadPixels();
10 | }
11 |
12 | color getColor(int idx) {
13 | return img.pixels[idx];
14 | }
15 | }
16 |
17 | int findClosestPoint(float x, float y) {
18 | int minIdx = -1;
19 | float minDist = 1000;
20 | for (int i = 0; i < points.length; i++) {
21 | VoronoiPoint p = points[i];
22 | if (p == null) break;
23 | float d = dist(x, y, p.x, p.y);
24 | if (d < minDist) {
25 | minIdx = i;
26 | minDist = d;
27 | }
28 | }
29 | return minIdx;
30 | }
--------------------------------------------------------------------------------
/chapter 9/street_collage/code/sketch.properties:
--------------------------------------------------------------------------------
1 | mode=Android
2 | component=wallpaper
3 | mode.id=processing.mode.android.AndroidMode
4 |
--------------------------------------------------------------------------------
/chapter 9/street_collage/data/default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/street_collage/data/default.png
--------------------------------------------------------------------------------
/chapter 9/street_collage/icon-144.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/street_collage/icon-144.png
--------------------------------------------------------------------------------
/chapter 9/street_collage/icon-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/street_collage/icon-192.png
--------------------------------------------------------------------------------
/chapter 9/street_collage/icon-36.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/street_collage/icon-36.png
--------------------------------------------------------------------------------
/chapter 9/street_collage/icon-48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/street_collage/icon-48.png
--------------------------------------------------------------------------------
/chapter 9/street_collage/icon-72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/street_collage/icon-72.png
--------------------------------------------------------------------------------
/chapter 9/street_collage/icon-96.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/processing-for-android/82cff4a6386b26fb44b362ad38ac785023ef79d1/chapter 9/street_collage/icon-96.png
--------------------------------------------------------------------------------
/contributing.md:
--------------------------------------------------------------------------------
1 | # Contributing to Apress Source Code
2 |
3 | Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers.
4 |
5 | ## How to Contribute
6 |
7 | 1. Make sure you have a GitHub account.
8 | 2. Fork the repository for the relevant book.
9 | 3. Create a new branch on which to make your change, e.g.
10 | `git checkout -b my_code_contribution`
11 | 4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted.
12 | 5. Submit a pull request.
13 |
14 | Thank you for your contribution!
--------------------------------------------------------------------------------
/processing-for-android-examples.txt:
--------------------------------------------------------------------------------
1 | name=Processing for Android, 1st Edition
2 | category=Android
3 | authors=[Andres Colubri](http://andrescolubri.net/)
4 | url=http://p5android-book.andrescolubri.net/
5 | sentence=Code examples of the book "Processing for Android: Create Mobile, Sensor-Aware, and VR Applications Using Processing" (Apress, 2017).
6 | paragraph=
7 | version=1
8 | prettyVersion=1.0
9 | lastUpdated=0
10 | minRevision=0
11 | maxRevision=0
12 |
--------------------------------------------------------------------------------