improved error handling with preproc (empty status & server only runs when build successful); added 1 example: selectionFlower; added <IE9 alert to template

This commit is contained in:
fjenett
2011-06-04 10:38:43 +00:00
parent dbddec591a
commit c3dbecf291
5 changed files with 146 additions and 18 deletions

View File

@@ -23,10 +23,7 @@ void mouseDragged ()
colorMode(HSB);
mColor = color( map(mouseX, 0,width, 0,255), 200, map(mouseY, 0, height, 255, 0) );
colorMode(RGB);
}
void mouseReleased ()
{
if ( js )
{
js.setColor(red(mColor), green(mColor), blue(mColor));
@@ -34,11 +31,11 @@ void mouseReleased ()
}
/**
* Define an interface that will act as glue between your sketch
* and "real" JavaScript running in your page. The name does not matter.
* Define an interface that will act as glue between this sketch
* and "real" JavaScript running in the HTML page. The name does not matter.
*
* The interface must define any functions that you intend to call
* from inside your sketch.
* The interface must define any functions that one intends to call
* from inside the sketch.
*/
interface JavaScriptInterface
{

View File

@@ -1,6 +1,6 @@
/**
* This code will be embedded into your HTML page as "normal"
* JavaScript code with a <script> tag. This allows you to
* This code will be embedded into the HTML page as "normal"
* JavaScript code with a <script> tag. This allows one to
* interact with the page as any normal JavaScript code can.
*/
@@ -9,7 +9,7 @@
makeTheLink();
}
// make the connection with your sketch
// make the connection with the sketch
function makeTheLink() {
// Get the instance. The id is automatically generated
@@ -25,7 +25,7 @@
mySketchInstance.setInterfaceLink(this); // make the connection
}
// called from your sketch!
// called from the sketch!
function setColor ( rr, gg, bb ) {
var colorString = 'rgb('+rr+','+gg+','+bb+')';

View File

@@ -0,0 +1,75 @@
/**
* <p>This example shows you how to get the currently selected text
* from the HTML page that this sketch is running in.</p>
*
* <p>Just select some text somewhere on this page and see it be transformed
* into a ... graph.</p>
*
* <p>Heavily inspired by <a href="http://bit.ly/jHvvWX">Boris Müller</a>.</p>
*/
/* @pjs transparent=true; */
String selectedText = "";
void setup ()
{
size( 300, 300 );
}
void draw ()
{
background( 100,0 );
fill( 255 );
if ( !selectedText.equals("") )
{
translate( width/2, height/2 );
float tw = selectedText.length() * 10;
float[] x = new float[selectedText.length()];
float[] y = new float[selectedText.length()];
for ( int i = 0, n = 0; i < tw; n++ )
{
char cr = new Character(selectedText.charAt(n));
float c = cr;
float r = -HALF_PI + map( i, 0, tw, 0, TWO_PI );
x[n] = cos(r)*c;
y[n] = sin(r)*c;
i += 10;
}
fill( 100 );
if ( x.length > 0 )
{
beginShape();
for ( int i = 0; i < x.length; i++ )
{
vertex( x[i], y[i] );
}
endShape( CLOSE );
}
smooth();
fill( 255 );
stroke( 150 );
for ( int i = 0; i < x.length; i++ )
text( selectedText.charAt(i), x[i]*1.15, y[i]*1.15+6 );
}
else
{
fill( map( sin(frameCount/12.0),-1,1,100,200 ) );
text("Select some (other) text on this page to start.", 2, height/2);
}
}
void setSelectionText ( String txt )
{
selectedText = txt;
}

View File

@@ -0,0 +1,50 @@
/**
* This code will be embedded into the HTML page as "normal"
* JavaScript code through a <script> tag. This allows one to
* interact with the page as any normal JavaScript code can.
*/
var mySketchInstance;
// called once the page has fully loaded
window.onload = function () {
getSketchInstance();
}
// this is called (repeatedly) to find the sketch
function getSketchInstance() {
var s = Processing.getInstanceById("selectionFlower");
if ( s == undefined )
return setTimeout(getSketchInstance, 200); // try again a bit later
mySketchInstance = s;
monitorSelection();
}
// this code gets called all the time (every 1/5 sec) to check
// if the selection changed
function monitorSelection ( ) {
var txt = undefined;
if (window.getSelection) {
txt = window.getSelection().toString();
} else if (document.getSelection) {
txt = document.getSelection().toString();
} else if (document.selection) {
txt = document.selection.createRange().text;
}
if ( txt !== undefined && txt != "" )
{
mySketchInstance.setSelectionText(txt); // set the text in the sketch
console.log( txt );
}
setTimeout(monitorSelection, 1000/5);
}