Initial commit

parents
Showing with 825 additions and 0 deletions
## Example files for the title:
# Processing and Arduino in Tandem, by Joseph Gray
[![Processing and Arduino in Tandem, by Joseph Gray](http://akamaicovers.oreilly.com/images/9781449399832/cat.gif)](https://www.safaribooksonline.com/library/view/title/9781449399832//)
The following applies to example files from material published by O’Reilly Media, Inc. Content from other publishers may include different rules of usage. Please refer to any additional usage rights explained in the actual example files or refer to the publisher’s website.
O'Reilly books are here to help you get your job done. In general, you may use the code in O'Reilly books in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from our books does not require permission. Answering a question by citing our books and quoting example code does not require permission. On the other hand, selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Incorporating a significant amount of example code from our books into your product's documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN.
If you think your use of code examples falls outside fair use or the permission given here, feel free to contact us at <permissions@oreilly.com>.
Please note that the examples are not production code and have not been carefully testing. They are provided "as-is" and come with no warranty of any kind.
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
#!/bin/sh
APPDIR=$(dirname "$0")
java -Djava.library.path="$APPDIR" -cp "$APPDIR/lib/module2_drawingTool.jar:$APPDIR/lib/core.jar:$APPDIR/lib/controlP5.jar" module2_drawingTool
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>CFBundleName</key>
<string>module2_drawingTool</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFBundleAllowMixedLocalizations</key>
<string>true</string>
<key>CFBundleExecutable</key>
<string>JavaApplicationStub</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleIconFile</key>
<string>sketch.icns</string>
<key>CFBundleIdentifier</key>
<string>module2_drawingTool</string>
<!-- http://developer.apple.com/documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/PListKeys.html#//apple_ref/doc/uid/20001431-113616 -->
<key>LSUIPresentationMode</key>
<integer>0</integer>
<!-- make sure that applications open in 32-bit mode on Snow Leopard,
otherwise video and most other native libraries will choke
http://developer.apple.com/mac/library/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/TP40009250-SW1 -->
<key>LSArchitecturePriority</key>
<array>
<string>i386</string>
<string>ppc</string>
</array>
<key>Java</key>
<dict>
<key>VMOptions</key>
<string> -Xms64m -Xmx2000m</string>
<key>MainClass</key>
<string>module2_drawingTool</string>
<key>JVMVersion</key>
<string>1.5*</string>
<key>JVMArchs</key>
<array>
<string>i386</string>
<string>ppc</string>
</array>
<key>ClassPath</key>
<string>$JAVAROOT/module2_drawingTool.jar:$JAVAROOT/core.jar:$JAVAROOT/controlP5.jar</string>
<!-- http://developer.apple.com/releasenotes/Java/java141/system_properties/chapter_4_section_1.html#//apple_ref/doc/uid/TP30000285 -->
<key>Properties</key>
<dict>
<key>apple.laf.useScreenMenuBar</key>
<string>true</string>
<key>apple.awt.showGrowBox</key>
<string>false</string>
<key>com.apple.smallTabs</key>
<string>true</string>
<key>apple.awt.Antialiasing</key>
<string>false</string>
<key>apple.awt.TextAntialiasing</key>
<string>true</string>
<key>com.apple.hwaccel</key>
<string>true</string>
<key>apple.awt.use-file-dialog-packages</key>
<string>false</string>
</dict>
</dict>
</dict>
</plist>
-Xms64m -Xmx2000m
module2_drawingTool
module2_drawingTool.jar,core.jar,controlP5.jar
No preview for this file type
void setupGUI() {
controlP5 = new ControlP5(this);
PFont GUIfont = createFont("arial",12);
controlP5.setControlFont(GUIfont);
controlP5.addTextlabel("linePreviewTitle", "Line Preview", 22, 12);
controlP5.addSlider("lineWeight", 1.0, 100.0, 20, 120, 250, 15).setLabel("weight");
controlP5.addSlider("lineHue", 1.0, 255.0, 20, 140, 250, 15).setLabel("hue");
controlP5.addSlider("lineSaturation", 1.0, 255.0, 20, 160, 250, 15).setLabel("saturation");
controlP5.addSlider("lineBrightness", 1.0, 255.0, 20, 180, 250, 15).setLabel("brightness");
controlP5.addSlider("lineAlpha", 1.0, 255.0, 20, 200, 250, 15).setLabel("opacity");
controlP5.addButton("saveImage",0,20,340,80,21).setLabel("Save Image");
controlP5.addButton("clearImage",0,103,340,90,21).setLabel("Clear Image");
}
void drawGUI() {
drawCursor();
drawGUIBackground();
drawLinePreview();
}
void drawCursor() {
if(mouseX>GUI_WIDTH) cursor(CROSS);
if(mouseX<=GUI_WIDTH) cursor(HAND);
}
void drawGUIBackground() {
noStroke();
fill(0);
rect(0,0, GUI_WIDTH, height);
}
void drawLinePreview() {
//draw white box
noStroke();
fill(255);
rect(20,60,GUI_WIDTH-40,50);
// draw outline
stroke(140);
strokeWeight(1);
fill(0,0);
rect(20,10,GUI_WIDTH-40,100);
// draw preview line
strokeWeight(lineWeight);
stroke(lineHue,lineSaturation,lineBrightness,lineAlpha);
line(70,60,GUI_WIDTH-70,60);
}
import controlP5.*;
ControlP5 controlP5;
int GUI_WIDTH = 400;
float lineWeight = 50;
float lineHue = 128;
float lineSaturation = 128;
float lineBrightness = 128;
float lineAlpha = 128;
void setup() {
size(1000,600);
background(255);
smooth();
frameRate(60);
colorMode(HSB);
//
setupGUI();
}
void draw() {
if(mousePressed) drawLine();
drawGUI();
}
void drawLine() {
strokeWeight(lineWeight);
stroke(lineHue,lineSaturation,lineBrightness, lineAlpha);
line(pmouseX, pmouseY, mouseX, mouseY);
}
void saveImage() {
String fileName = timeStamp()+".png";
PImage imageSave = get(GUI_WIDTH,0,width-GUI_WIDTH,height);
imageSave.save(fileName);
}
String timeStamp() {
String timestamp = year()+"_"+month()+"_"+day()+"_"+minute()+"_"+second()+"_"+millis();
return timestamp;
}
void clearImage() {
noStroke();
fill(255);
rect(GUI_WIDTH,0,width-GUI_WIDTH,height);
}
void keyPressed() {
if(key == 's') saveImage();
}
void setupGUI() {
controlP5 = new ControlP5(this);
PFont GUIfont = createFont("arial",12);
controlP5.setControlFont(GUIfont);
controlP5.addTextlabel("linePreviewTitle", "Line Preview", 22, 12);
controlP5.addSlider("lineWeight", 1.0, 100.0, 20, 120, 250, 15).setLabel("weight");
controlP5.addSlider("lineHue", 1.0, 255.0, 20, 140, 250, 15).setLabel("hue");
controlP5.addSlider("lineSaturation", 1.0, 255.0, 20, 160, 250, 15).setLabel("saturation");
controlP5.addSlider("lineBrightness", 1.0, 255.0, 20, 180, 250, 15).setLabel("brightness");
controlP5.addSlider("lineAlpha", 1.0, 255.0, 20, 200, 250, 15).setLabel("opacity");
controlP5.addSlider("randomX", 0.0, 600, 20, 240, 250, 15).setLabel("X random");
controlP5.addSlider("randomY", 0.0, 600, 20, 260, 250, 15).setLabel("Y random");
controlP5.addButton("blur", 0, 20, 300, 80, 21).setLabel("Blur");
controlP5.addButton("erode", 0, 103, 300, 80, 21).setLabel("Erode");
controlP5.addButton("dilate", 0, 186, 300, 80, 21).setLabel("dilate");
controlP5.addButton("negative", 0, 269, 300, 80, 21).setLabel("Negative");
controlP5.addButton("saveImage",0,20,340,80,21).setLabel("Save Image");
controlP5.addButton("clearImage",0,103,340,90,21).setLabel("Clear Image");
}
void drawGUI() {
drawCursor();
drawGUIBackground();
drawLinePreview();
}
void drawCursor() {
if(mouseX>GUI_WIDTH) cursor(CROSS);
if(mouseX<=GUI_WIDTH) cursor(HAND);
}
void drawGUIBackground() {
noStroke();
fill(0);
rect(0,0, GUI_WIDTH, height);
}
void drawLinePreview() {
//draw white box
noStroke();
fill(255);
rect(20,60,GUI_WIDTH-40,50);
// draw outline
stroke(140);
strokeWeight(1);
fill(0,0);
rect(20,10,GUI_WIDTH-40,100);
// draw preview line
strokeWeight(lineWeight);
stroke(lineHue,lineSaturation,lineBrightness,lineAlpha);
line(70,60,GUI_WIDTH-70,60);
}
import controlP5.*;
ControlP5 controlP5;
int GUI_WIDTH = 400;
float lineWeight = 50;
float lineHue = 128;
float lineSaturation = 128;
float lineBrightness = 128;
float lineAlpha = 128;
float randomX = 0;
float randomY = 0;
void setup() {
size(1000,600);
background(255);
smooth();
frameRate(60);
colorMode(HSB);
//
setupGUI();
}
void draw() {
if(mousePressed) drawLine();
drawGUI();
}
void drawLine() {
strokeWeight(lineWeight);
stroke(lineHue,lineSaturation,lineBrightness, lineAlpha);
float x1 = pmouseX+random(-randomX, randomX);
float y1 = pmouseY+random(-randomY, randomY);
float x2 = mouseX+random(-randomX, randomX);
float y2 = mouseY+random(-randomY, randomY);
line(x1, y1, x2, y2);
}
void saveImage() {
String fileName = timeStamp()+".png";
PImage imageSave = get(GUI_WIDTH,0,width-GUI_WIDTH,height);
imageSave.save(fileName);
}
String timeStamp() {
String timestamp = year()+"_"+month()+"_"+day()+"_"+minute()+"_"+second()+"_"+millis();
return timestamp;
}
void clearImage() {
noStroke();
fill(255);
rect(GUI_WIDTH,0,width-GUI_WIDTH,height);
}
void keyPressed() {
if(key == 's') saveImage();
}
void blur() {
filter(BLUR, 5);
}
void erode() {
filter(ERODE);
}
void dilate() {
filter(DILATE);
}
void negative() {
filter(INVERT);
}
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
#!/bin/sh
APPDIR=$(dirname "$0")
java -Djava.library.path="$APPDIR" -cp "$APPDIR/lib/module2_drawingTool.jar:$APPDIR/lib/core.jar:$APPDIR/lib/controlP5.jar" module2_drawingTool
No preview for this file type
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>CFBundleName</key>
<string>module2_drawingTool</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFBundleAllowMixedLocalizations</key>
<string>true</string>
<key>CFBundleExecutable</key>
<string>JavaApplicationStub</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleIconFile</key>
<string>sketch.icns</string>
<key>CFBundleIdentifier</key>
<string>module2_drawingTool</string>
<!-- http://developer.apple.com/documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/PListKeys.html#//apple_ref/doc/uid/20001431-113616 -->
<key>LSUIPresentationMode</key>
<integer>0</integer>
<!-- make sure that applications open in 32-bit mode on Snow Leopard,
otherwise video and most other native libraries will choke
http://developer.apple.com/mac/library/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/TP40009250-SW1 -->
<key>LSArchitecturePriority</key>
<array>
<string>i386</string>
<string>ppc</string>
</array>
<key>Java</key>
<dict>
<key>VMOptions</key>
<string> -Xms64m -Xmx2000m</string>
<key>MainClass</key>
<string>module2_drawingTool</string>
<key>JVMVersion</key>
<string>1.5*</string>
<key>JVMArchs</key>
<array>
<string>i386</string>
<string>ppc</string>
</array>
<key>ClassPath</key>
<string>$JAVAROOT/module2_drawingTool.jar:$JAVAROOT/core.jar:$JAVAROOT/controlP5.jar</string>
<!-- http://developer.apple.com/releasenotes/Java/java141/system_properties/chapter_4_section_1.html#//apple_ref/doc/uid/TP30000285 -->
<key>Properties</key>
<dict>
<key>apple.laf.useScreenMenuBar</key>
<string>true</string>
<key>apple.awt.showGrowBox</key>
<string>false</string>
<key>com.apple.smallTabs</key>
<string>true</string>
<key>apple.awt.Antialiasing</key>
<string>false</string>
<key>apple.awt.TextAntialiasing</key>
<string>true</string>
<key>com.apple.hwaccel</key>
<string>true</string>
<key>apple.awt.use-file-dialog-packages</key>
<string>false</string>
</dict>
</dict>
</dict>
</plist>
-Xms64m -Xmx2000m
module2_drawingTool
module2_drawingTool.jar,core.jar,controlP5.jar
No preview for this file type
No preview for this file type
void setupGUI() {
controlP5 = new ControlP5(this);
PFont GUIfont = createFont("arial",12);
controlP5.setControlFont(GUIfont);
controlP5.addTextlabel("linePreviewTitle", "Line Preview", 22, 12);
controlP5.addSlider("lineWeight", 1.0, 100.0, 20, 120, 250, 15).setLabel("weight");
controlP5.addSlider("lineHue", 1.0, 255.0, 20, 140, 250, 15).setLabel("hue");
controlP5.addSlider("lineSaturation", 1.0, 255.0, 20, 160, 250, 15).setLabel("saturation");
controlP5.addSlider("lineBrightness", 1.0, 255.0, 20, 180, 250, 15).setLabel("brightness");
controlP5.addSlider("lineAlpha", 1.0, 255.0, 20, 200, 250, 15).setLabel("opacity");
controlP5.addButton("saveImage",0,20,340,80,21).setLabel("Save Image");
controlP5.addButton("clearImage",0,103,340,90,21).setLabel("Clear Image");
}
void drawGUI() {
drawCursor();
drawGUIBackground();
drawLinePreview();
}
void drawCursor() {
if(mouseX>GUI_WIDTH) cursor(CROSS);
if(mouseX<=GUI_WIDTH) cursor(HAND);
}
void drawGUIBackground() {
noStroke();
fill(0);
rect(0,0, GUI_WIDTH, height);
}
void drawLinePreview() {
//draw white box
noStroke();
fill(255);
rect(20,60,GUI_WIDTH-40,50);
// draw outline
stroke(140);
strokeWeight(1);
fill(0,0);
rect(20,10,GUI_WIDTH-40,100);
// draw preview line
strokeWeight(lineWeight);
stroke(lineHue,lineSaturation,lineBrightness,lineAlpha);
line(70,60,GUI_WIDTH-70,60);
}
import controlP5.*;
ControlP5 controlP5;
int GUI_WIDTH = 400;
float lineWeight = 50;
float lineHue = 128;
float lineSaturation = 128;
float lineBrightness = 128;
float lineAlpha = 128;
void setup() {
size(1000,600);
background(255);
smooth();
frameRate(60);
colorMode(HSB);
//
setupGUI();
}
void draw() {
if(mousePressed) drawLine();
drawGUI();
}
void drawLine() {
strokeWeight(lineWeight);
stroke(lineHue,lineSaturation,lineBrightness, lineAlpha);
line(pmouseX, pmouseY, mouseX, mouseY);
}
void saveImage() {
String fileName = timeStamp()+".png";
PImage imageSave = get(GUI_WIDTH,0,width-GUI_WIDTH,height);
imageSave.save(fileName);
}
String timeStamp() {
String timestamp = year()+"_"+month()+"_"+day()+"_"+minute()+"_"+second()+"_"+millis();
return timestamp;
}
void clearImage() {
noStroke();
fill(255);
rect(GUI_WIDTH,0,width-GUI_WIDTH,height);
}
void keyPressed() {
if(key == 's') saveImage();
}
void setupGUI() {
controlP5 = new ControlP5(this);
PFont GUIfont = createFont("arial",12);
controlP5.setControlFont(GUIfont);
controlP5.addTextlabel("linePreviewTitle", "Line Preview", 22, 12);
controlP5.addSlider("lineWeight", 1.0, 100.0, 20, 120, 250, 15).setLabel("weight");
controlP5.addSlider("lineHue", 1.0, 255.0, 20, 140, 250, 15).setLabel("hue");
controlP5.addSlider("lineSaturation", 1.0, 255.0, 20, 160, 250, 15).setLabel("saturation");
controlP5.addSlider("lineBrightness", 1.0, 255.0, 20, 180, 250, 15).setLabel("brightness");
controlP5.addSlider("lineAlpha", 1.0, 255.0, 20, 200, 250, 15).setLabel("opacity");
controlP5.addSlider("randomX", 0.0, 600, 20, 240, 250, 15).setLabel("X random");
controlP5.addSlider("randomY", 0.0, 600, 20, 260, 250, 15).setLabel("Y random");
controlP5.addButton("blur", 0, 20, 300, 80, 21).setLabel("Blur");
controlP5.addButton("erode", 0, 103, 300, 80, 21).setLabel("Erode");
controlP5.addButton("dilate", 0, 186, 300, 80, 21).setLabel("dilate");
controlP5.addButton("negative", 0, 269, 300, 80, 21).setLabel("Negative");
controlP5.addButton("saveImage",0,20,340,80,21).setLabel("Save Image");
controlP5.addButton("clearImage",0,103,340,90,21).setLabel("Clear Image");
}
void drawGUI() {
drawCursor();
drawGUIBackground();
drawLinePreview();
}
void drawCursor() {
if(mouseX>GUI_WIDTH) cursor(CROSS);
if(mouseX<=GUI_WIDTH) cursor(HAND);
}
void drawGUIBackground() {
noStroke();
fill(0);
rect(0,0, GUI_WIDTH, height);
}
void drawLinePreview() {
//draw white box
noStroke();
fill(255);
rect(20,60,GUI_WIDTH-40,50);
// draw outline
stroke(140);
strokeWeight(1);
fill(0,0);
rect(20,10,GUI_WIDTH-40,100);
// draw preview line
strokeWeight(lineWeight);
stroke(lineHue,lineSaturation,lineBrightness,lineAlpha);
line(70,60,GUI_WIDTH-70,60);
}
import controlP5.*;
ControlP5 controlP5;
int GUI_WIDTH = 400;
float lineWeight = 50;
float lineHue = 128;
float lineSaturation = 128;
float lineBrightness = 128;
float lineAlpha = 128;
float randomX = 0;
float randomY = 0;
void setup() {
size(1000,600);