Add 'practicing-processing/' from commit 'a863dc99fc5e1967264c286f2adf2b27b50585ef'

git-subtree-dir: practicing-processing
git-subtree-mainline: d40d570281
git-subtree-split: a863dc99fc
This commit is contained in:
Dan Buch 2013-01-09 23:49:00 -05:00
commit 1037e390b5
11 changed files with 445 additions and 0 deletions

3
practicing-processing/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.class
lib/*
lib/preferences.txt

View File

@ -0,0 +1,20 @@
#!/bin/bash
set -e
TOP="$(dirname $(dirname $(readlink -f -- "$0")))"
$TOP/bin/prochome-check >/dev/null
if [ ! -f "$TOP/lib/preferences.txt" ]; then
cp "$TOP/lib/preferences.txt.stub" "$TOP/lib/preferences.txt"
fi
CP="$CLASSPATH"
CP="$TOP/lib/mbh-processing-practice.jar:$CP"
for procjar in "lib/core" "lib/pde" "java/lib/tools" "java/lib/rt"
do
CP="$PROCESSING_HOME/$procjar.jar:$CP"
done
test -n "$DEBUG" && echo "DEBUG:CP=$CP"
java -cp "$CP" com.meatballhat.processing.ProcessingRunner "$@"

View File

@ -0,0 +1,13 @@
#!/bin/bash
if [ -z "$PROCESSING_HOME" ]; then
cat >&2 <<EOM
----------------------------------------------
ERROR: You must define "\$PROCESSING_HOME"
----------------------------------------------
EOM
exit 1
else
echo "Looks like PROCESSING_HOME is set to \"$PROCESSING_HOME\"."
exit 0
fi

View File

@ -0,0 +1,28 @@
<project name="practicing-processing" basedir="." default="jar">
<property environment="env" />
<target name="envcheck">
<exec executable="./bin/prochome-check" failonerror="true" />
</target>
<target name="jar" depends="build" description="Jar Up All The Things">
<jar destfile="lib/mbh-processing-practice.jar" basedir="build" />
</target>
<target name="build" depends="envcheck" description="Build All The Things">
<javac srcdir="src" destdir="build" includeantruntime="false" debug="on">
<classpath>
<pathelement location="${env.PROCESSING_HOME}/lib/pde.jar" />
<pathelement location="${env.PROCESSING_HOME}/lib/core.jar" />
<pathelement location="${env.PROCESSING_HOME}/java/lib/tools.jar" />
<pathelement location="${env.PROCESSING_HOME}/java/lib/rt.jar" />
</classpath>
</javac>
</target>
<target name="clean" description="Delete built stuff">
<delete>
<fileset dir="build" includes="**/*.class" />
</delete>
</target>
</project>

View File

View File

@ -0,0 +1,67 @@
console.auto_clear=true
console.font.macosx=Monaco,plain,10
console.font=Monospaced,plain,11
console.length=500
console.lines=4
contribution.backup.on_install=true
contribution.backup.on_remove=true
editor.antialias.linux=true
editor.antialias=true
editor.divider.size=0
editor.divider.size.windows=2
editor.external=false
editor.font.macosx=Monaco,plain,10
editor.font=Monospaced,plain,12
editor.indent=true
editor.keys.alternative_cut_copy_paste.macosx=false
editor.keys.alternative_cut_copy_paste=true
editor.keys.home_and_end_travel_far=false
editor.keys.home_and_end_travel_far.macosx=true
editor.keys.home_and_end_travel_smart=true
editor.keys.shift_backspace_is_delete=true
editor.tabs.expand=true
editor.tabs.size=2
editor.untitled.prefix=sketch_
editor.window.height.default=600
editor.window.height.min=500
editor.window.height.min.macosx=450
editor.window.height.min.windows=530
editor.window.width.default=500
editor.window.width.min=400
export.applet.separate_jar_files=false
export.application.fullscreen=false
export.application.platform.linux=true
export.application.platform.macosx=true
export.application.platform=true
export.application.platform.windows=true
export.application.stop=true
export.delete_target_folder=true
instance_server.key=0.3877576097235004
instance_server.port=38596
last.sketch.count=0
last.sketch.restore=true
launcher=xdg-open
platform.auto_file_type_associations=true
preproc.color_datatype=true
preproc.enhanced_casting=true
preproc.imports.list=java.applet.*,java.awt.Dimension,java.awt.Frame,java.awt.event.MouseEvent,java.awt.event.KeyEvent,java.awt.event.FocusEvent,java.awt.Image,java.io.*,java.net.*,java.text.*,java.util.*,java.util.zip.*,java.util.regex.*
preproc.output_parse_tree=false
preproc.save_build_files=false
preproc.substitute_floats=true
preproc.substitute_unicode=true
preproc.web_colors=true
run.display=1
run.options=
run.options.bits.macosx=32
run.options.memory=false
run.options.memory.initial=64
run.options.memory.maximum=256
run.present.bgcolor=#666666
run.present.exclusive=false
run.present.exclusive.macosx=true
run.present.stop.color=#cccccc
run.window.bgcolor=#DFDFDF
sketchbook.path=/home/me/repos/practicing-processing.git/sketchbook
update.check=true
update.id=-5920873896785929326
update.last=1325434363680

View File

@ -0,0 +1,42 @@
/**
* Wave Gradient
* by Ira Greenberg.
*
* Generate a gradient along a sin() wave.
*/
float angle = 0;
float px = 0, py = 0;
float amplitude = 30;
float frequency = 0;
float fillGap = 2.5;
color c;
int colorRange = 255;
int ncycles = 500;
void setup() {
size(640, 360);
background(200);
noLoop();
}
void draw() {
for (int i =- ncycles; i < height+ncycles; i++){
// Reset angle to 0, so waves stack properly
angle = 0;
// Increasing frequency causes more gaps
frequency+=.01;
for (float j = 0; j < width+ncycles; j++){
py = i + sin(radians(angle)) * amplitude;
angle += frequency;
c = color(abs(py-i)*colorRange/amplitude, colorRange-abs(py-i)*colorRange/amplitude, j*((colorRange * 1.0)/(width+(int)(ncycles * 0.66))));
// Hack to fill gaps. Raise value of fillGap if you increase frequency
for (int filler = 0; filler < fillGap; filler++){
set(int(j-filler), int(py)-filler, c);
set(int(j), int(py), c);
set(int(j+filler), int(py)+filler, c);
}
}
}
}

View File

@ -0,0 +1,272 @@
package com.meatballhat.processing;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import processing.app.Base;
import processing.app.Preferences;
import processing.app.SketchException;
import processing.app.RunnerListener;
import processing.app.Sketch;
import processing.core.PApplet;
import processing.mode.java.runner.*;
public class ProcessingRunner implements processing.app.RunnerListener {
static final String helpArg = "--help";
static final String preprocArg = "--preprocess";
static final String buildArg = "--build";
static final String runArg = "--run";
static final String presentArg = "--present";
static final String sketchArg = "--sketch=";
static final String outputArg = "--output=";
static final String exportAppletArg = "--export-applet";
static final String exportApplicationArg = "--export-application";
static final String platformArg = "--platform=";
static final String bitsArg = "--bits=";
static final String preferencesArg = "--preferences=";
static final int HELP = -1;
static final int PREPROCESS = 0;
static final int BUILD = 1;
static final int RUN = 2;
static final int PRESENT = 3;
static final int EXPORT_APPLET = 4;
static final int EXPORT_APPLICATION = 5;
Sketch sketch;
static public void main(String[] args) {
// Do this early so that error messages go to the console
Base.setCommandLine();
// init the platform so that prefs and other native code is ready to go
Base.initPlatform();
// make sure a full JDK is installed
Base.initRequirements();
// run static initialization that grabs all the prefs
//Preferences.init(null);
// launch command line handler
new ProcessingRunner(args);
}
public ProcessingRunner(String[] args) {
String sketchFolder = null;
String pdePath = null; // path to the .pde file
String outputPath = null;
String preferencesPath = null;
int platformIndex = PApplet.platform; // default to this platform
int platformBits = 0;
int mode = HELP;
for (String arg : args) {
if (arg.length() == 0) {
// ignore it, just the crappy shell script
} else if (arg.equals(helpArg)) {
// mode already set to HELP
} else if (arg.equals(buildArg)) {
mode = BUILD;
} else if (arg.equals(runArg)) {
mode = RUN;
} else if (arg.equals(presentArg)) {
mode = PRESENT;
} else if (arg.equals(preprocArg)) {
mode = PREPROCESS;
} else if (arg.equals(exportAppletArg)) {
mode = EXPORT_APPLET;
} else if (arg.equals(exportApplicationArg)) {
mode = EXPORT_APPLICATION;
} else if (arg.startsWith(platformArg)) {
String platformStr = arg.substring(platformArg.length());
platformIndex = Base.getPlatformIndex(platformStr);
if (platformIndex == -1) {
complainAndQuit(platformStr + " should instead be " +
"'windows', 'macosx', or 'linux'.");
}
} else if (arg.startsWith(sketchArg)) {
sketchFolder = arg.substring(sketchArg.length());
File sketchy = new File(sketchFolder);
File pdeFile = new File(sketchy, sketchy.getName() + ".pde");
pdePath = pdeFile.getAbsolutePath();
} else if (arg.startsWith(preferencesArg)) {
preferencesPath = arg.substring(preferencesArg.length());
} else if (arg.startsWith(outputArg)) {
outputPath = arg.substring(outputArg.length());
} else {
complainAndQuit("I don't know anything about " + arg + ".");
}
}
if ((outputPath == null) &&
(mode == PREPROCESS || mode == BUILD ||
mode == RUN || mode == PRESENT)) {
complainAndQuit("An output path must be specified when using " +
preprocArg + ", " + buildArg + ", " +
runArg + ", or " + presentArg + ".");
}
if (mode == HELP) {
printCommandLine(System.out);
System.exit(0);
}
// --present --platform=windows "--sketch=/Applications/Processing 0148/examples/Basics/Arrays/Array" --output=test-build
File outputFolder = new File(outputPath);
if (!outputFolder.exists()) {
if (!outputFolder.mkdirs()) {
complainAndQuit("Could not create the output folder.");
}
}
// run static initialization that grabs all the prefs
// (also pass in a prefs path if that was specified)
Preferences.init(preferencesPath);
if (sketchFolder == null) {
complainAndQuit("No sketch path specified.");
} else if (outputPath.equals(pdePath)) {
complainAndQuit("The sketch path and output path cannot be identical.");
} else if (!pdePath.toLowerCase().endsWith(".pde")) {
complainAndQuit("Sketch path must point to the main .pde file.");
} else {
//Sketch sketch = null;
boolean success = false;
try {
sketch = new Sketch(null, pdePath);
if (mode == PREPROCESS) {
success = true; // FIXME sketch.preprocess(new File(outputPath)) != null;
} else if (mode == BUILD) {
success = true; // FIXME sketch.build(outputPath) != null;
} else if (mode == RUN || mode == PRESENT) {
String className = "BUSTED"; // FIXME sketch.build(outputPath);
if (className != null) {
success = true;
Runner runner = new Runner(null, null); // FIXME new Runner(this, sketch);
runner.launch(true); // FIXME runner.launch(className, mode == PRESENT);
} else {
success = false;
}
} else if (mode == EXPORT_APPLET) {
if (outputPath != null) {
success = true; // FIXME sketch.exportApplet(outputPath);
} else {
String target = sketchFolder + File.separatorChar + "applet";
success = true; // FIXME sketch.exportApplet(target);
}
} else if (mode == EXPORT_APPLICATION) {
if (outputPath != null) {
success = true; // FIXME sketch.exportApplication(outputPath, platformIndex, platformBits);
} else {
//String sketchFolder =
// pdePath.substring(0, pdePath.lastIndexOf(File.separatorChar));
outputPath =
sketchFolder + File.separatorChar +
"application." + Base.getPlatformName(platformIndex);
success = true; // FIXME sketch.exportApplication(outputPath, platformIndex, platformBits);
}
}
System.exit(success ? 0 : 1);
} catch (SketchException re) {
statusError(re);
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}
}
public void statusNotice(String message) {
System.err.println(message);
}
public void statusError(String message) {
System.err.println(message);
}
public void statusError(Exception exception) {
if (exception instanceof SketchException) {
SketchException re = (SketchException) exception;
// format the runner exception like emacs
//blah.java:2:10:2:13: Syntax Error: This is a big error message
String filename = sketch.getCode(re.getCodeIndex()).getFileName();
int line = re.getCodeLine();
int column = re.getCodeColumn();
if (column == -1) column = 0;
// TODO if column not specified, should just select the whole line.
System.err.println(filename + ":" +
line + ":" + column + ":" +
line + ":" + column + ":" + " " + re.getMessage());
} else {
exception.printStackTrace();
}
}
static void complainAndQuit(String lastWords) {
printCommandLine(System.err);
System.err.println(lastWords);
System.exit(1);
}
static void printCommandLine(PrintStream out) {
out.println("Processing " + Base.VERSION_NAME + " rocks the console.");
out.println();
out.println("--help Show this help text.");
out.println();
out.println("--sketch=<name> Specify the sketch folder (required)");
out.println("--output=<name> Specify the output folder (required and");
out.println(" cannot be the same as the sketch folder.)");
out.println();
out.println("--preprocess Preprocess a sketch into .java files.");
out.println("--build Preprocess and compile a sketch into .class files.");
out.println("--run Preprocess, compile, and run a sketch.");
out.println("--present Preprocess, compile, and run a sketch full screen.");
out.println();
out.println("--export-applet Export an applet.");
out.println("--export-application Export an application.");
out.println("--platform Specify the platform (export to application only).");
out.println(" Should be one of 'windows', 'macosx', or 'linux'.");
out.println("--bits Must be specified if libraries are used that are");
out.println(" 32- or 64-bit specific such as the OpenGL library.");
out.println(" Otherwise specify 0 or leave it out.");
out.println();
out.println("--preferences=<file> Specify a preferences file to use. Required if the");
out.println(" sketch uses libraries found in your sketchbook folder.");
}
public void startIndeterminate() {
}
public void stopIndeterminate() {
}
public void statusHalt() {
}
public boolean isHalted() {
return false;
}
}