diff --git a/javascript/examples/Environment/FileReader/FileReader.pde b/javascript/examples/Environment/FileReader/FileReader.pde index d94bebf60..90ee22b51 100644 --- a/javascript/examples/Environment/FileReader/FileReader.pde +++ b/javascript/examples/Environment/FileReader/FileReader.pde @@ -1,4 +1,7 @@ /** + * Select an image to have it be transferred to your sketch + * without the need to be uploaded first.
+ * *
* * No Safari support. diff --git a/javascript/examples/Environment/Input/variableInputs/interface.js b/javascript/examples/Environment/Input/variableInputs/interface.js deleted file mode 100644 index 9b7e53e49..000000000 --- a/javascript/examples/Environment/Input/variableInputs/interface.js +++ /dev/null @@ -1,204 +0,0 @@ -window.onload = function () { - tryFindSketch(); -} - -function tryFindSketch () { - var sketch = Processing.instances[0]; - if ( sketch == undefined ) return setTimeout(tryFindSketch, 200); - - var controller = new Controller(sketch,"form-form"); - sketch.setController(controller); -} - -var Controller = (function(){ - - function Controller () { - var sketch = arguments[0]; - var form = document.getElementById(arguments[1]); - form.onsubmit = function () {return false}; - var inputs = {}; - - this.createInputElement = function ( id, type, labelStr ) { - var input = document.createElement('input'); - input.id = id; - input.name = id; - input.type = type; - if ( labelStr !== undefined && labelStr !== '' ) - { - var label = document.createElement('label'); - label['for'] = id; - label.id = id+'-label'; - label.innerHTML = labelStr; - form.appendChild(label); - } - form.appendChild(input); - return input; - } - - this.addInputField = function ( l, t ) { - var id = createIdFromLabel(l); - if ( inputs[id] == undefined ) { - inputs[id] = this.createInputElement(id, t, l); - inputs[id].onchange = function(){ - changeFunc()(sketch, id, this.value); - return false; - } - } - return inputs[id]; - } - - this.addRange = function ( l, c, mi, mx ) { - var input = this.addInputField( l, "range" ); - input.value = c; - input.min = mi; - input.max = mx; - return input; - } - - this.addPassword = function ( l ) { - var input = this.addInputField ( l, "password" ); - return input; - } - - this.addEmail = function ( l ) { - var input = this.addInputField ( l, "email" ); - return input; - } - - this.addSearch = function ( l, c ) { - var input = this.addInputField ( l, "search" ); - input.value = c; - return input; - } - - this.addNumber = function ( l, c ) { - var input = this.addInputField ( l, "number" ); - input.value = c; - return input; - } - - this.addTelephone = function ( l, c ) { - var input = this.addInputField ( l, "tel" ); - input.value = c; - return input; - } - - this.addUrl = function ( l, c ) { - var input = this.addInputField ( l, "url" ); - input.value = c; - return input; - } - - this.addDate = function ( l, c ) { - var input = this.addInputField ( l, "date" ); - input.value = c; - return input; - } - - this.addCheckbox = function ( l, c ) { - var id = createIdFromLabel(l); - if ( inputs[id] == undefined ) { - inputs[id] = this.createInputElement(id, "checkbox", l); - inputs[id].onchange = function(){ - changeFunc()(sketch, id, this.checked); - return false; - } - } - inputs[id].checked = c ? 'checked' : ''; - return inputs[id]; - } - - this.addTextfield = function ( l, c ) { - var id = createIdFromLabel(l); - if ( inputs[id] == undefined ) { - inputs[id] = this.createInputElement(id, "text", l); - inputs[id].onchange = function(){ - changeFunc()(sketch, id, this.value); - return false; - } - } - inputs[id].value = c; - return inputs[id]; - } - - this.addTextarea = function ( l, c ) { - var id = createIdFromLabel(l); - if ( inputs[id] == undefined ) { - var label = document.createElement('label'); - label['for'] = id; - label.id = id+'-label'; - label.innerHTML = l; - form.appendChild(label); - inputs[id] = document.createElement('textarea'); - inputs[id].id = id; - inputs[id].name = id; - inputs[id].innerHTML = c; - inputs[id].onchange = function(){ - changeFunc()(sketch, id, this.value); - return false; - } - form.appendChild(inputs[id]); - } - inputs[id].value = c; - return inputs[id]; - } - - this.addSelection = function ( l, o ) { - var id = createIdFromLabel(l); - if ( inputs[id] == undefined ) { - var label = document.createElement('label'); - label['for'] = id; - label.id = id+'-label'; - label.innerHTML = l; - form.appendChild(label); - var select = document.createElement('select'); - select.id = id; - select.name = id; - if ( o !== undefined && o.length && o.length > 0 ) { - for ( var i = 0; i < o.length; i++ ) { - var value = o[i].length > 1 ? o[i][1] : i; - var option = document.createElement('option'); - option.innerHTML = o[i][0]; - option.value = value; - select.appendChild(option); - } - } - select.onchange = function( event ){ - changeFunc()(sketch, id, this.value); - return false; - } - inputs[id] = select; - form.appendChild(inputs[id]); - } - return inputs[id]; - } - this.addMenu = this.addSelection; - - this.setElementLabel = function ( element, labelStr ) { - var label = document.getElementById(element.id+'-label'); - if ( label && label.childNodes && label.childNodes.length > 0 ) { - label.childNodes[0].textContent = labelStr; - } else { - //console.log([element, label]); - } - } - } - - var changeFunc = function () { - return function ( sketch, id, value ) { - try { - sketch[id](value); - } catch (e) { - //console.log(e); - sketch.println( "Function \"void "+id+"(value)\" is not defined in your sketch."); - } - } - } - - var createIdFromLabel = function ( l ) { - return l.replace(/^[^-_a-z]/i,'_').replace(/[^-_a-z0-9]/gi,''); - } - - return Controller; - -})(); diff --git a/javascript/examples/Environment/Input/variableInputs/variableInputs.pde b/javascript/examples/Environment/Input/variableInputs/variableInputs.pde deleted file mode 100644 index 43d4830c0..000000000 --- a/javascript/examples/Environment/Input/variableInputs/variableInputs.pde +++ /dev/null @@ -1,190 +0,0 @@ -/** - * This examples shows you how to interact with diverse HTML inputs. It follows - * roughly the way that ControlP5 - * works for standard Processing.
- * - *
- * - * - */ - - String[] menuItems; - - int currentShape = 2; - float currentX = 0; - boolean hasStroke = true; - float hueValue = 0; - String fieldString = "Fancy Corp. Co."; - String areaString = "We are the fresh new company with "+ - "activities ranging from A to Z and from "+ - "alpha to omega."; - PFont fontLarge, fontSmall; - - void setup () - { - size(300,200); - - colorMode(HSB); - - currentX = 50; - - menuItems = new String[] { - new String[] {"Rectangle"}, new String[] {"Ellipse"}, - new String[] {"Star"}, new String[] {"Spirograph"} - }; - - textFont(createFont("Arial", 16)); - } - - int bg = 200; void setBG ( int b ) { bg = b; } - void draw () - { - background( bg ); - - strokeWeight(4); - - if ( hasStroke ) stroke( hueValue, 150, 95 ); - else noStroke(); - - fill( hueValue, 200, 150 ); - - pushMatrix(); - switch ( currentShape ) { - case 0: - rectMode(CENTER); - rect(currentX, height/4, 50, 50); - break; - case 1: - ellipse(currentX, height/4, 55, 55); - break; - case 2: - star(currentX, height/4, 17, 30); - break; - case 3: - spiro(currentX, height/4, 20); - break; - } - popMatrix(); - - fill( 0 ); - textSize(16); - textAlign( CENTER ); - float tWidth = textWidth(fieldString); - float tX = currentX; - if ( currentX-tWidth/2 < 25 ) - { - textAlign( LEFT ); - tX = currentX-25; - } - else if ( currentX+tWidth/2 > width-25 ) - { - textAlign( RIGHT ); - tX = currentX+25; - } - text( fieldString, tX, height/4+50 ); - - textSize(11.5); - textAlign( currentX > width/2 ? RIGHT : LEFT ); - int l, w; - if ( currentX <= width/2 ) - { - l = currentX-50+25; - w = width-l-25; - } - else - { - l = 25; - w = currentX+50-25-25; - } - text( areaString, l, height/4+70, w, height/2 ); - } - - void star ( float x, float y, float inner, float outer ) - { - beginShape(); - for ( int i = 0; i < 360; i+=36 ) - { - float r = radians(i + sin(frameCount/90.0)*25); - vertex( x + cos(r)*outer, y + sin(r)*outer ); - r = radians(i+(36/2)); - vertex( x + cos(r)*inner, y + sin(r)*inner ); - } - endShape(CLOSE); - } - - void spiro ( float x, float y, float rad ) - { - beginShape(); - for ( int i = 0; i < 360; i+=2 ) - { - float r = radians(i); - float r2 = radians(i*(sin(frameCount/240.0)+2)*2); - vertex( x + (cos(r)+cos(r2)/2)*rad, y + (sin(r)+sin(r2)/2)*rad ); - } - endShape(); - } - - /* these are callbacks */ - - void setController ( Controller ctlr ) - { - // labels are supposed to be existing function names - - InterfaceElement element = ctlr.addRange( "rangeCallback", currentX, 0, 100 ); - ctlr.setElementLabel( element, "Example range input field" ); - - element = ctlr.addCheckbox( "textBoxCallback", hasStroke ); - ctlr.setElementLabel( element, "A checkbox here" ); - - element = ctlr.addTextfield( "textFieldChanged", fieldString ); - ctlr.setElementLabel( element, "... and this is a textfield" ); - - element = ctlr.addTextarea( "calledByTextarea", areaString ); - ctlr.setElementLabel( element, "Ta-dah: a textarea" ); - - element = ctlr.addMenu( "theMenu", menuItems ); - ctlr.setElementLabel( element, "LBNL a select menu" ); - } - - void rangeCallback ( float value ) - { - currentX = map( value, 0, 100, 50, width-50 ); - } - - void textBoxCallback ( boolean value ) - { - hasStroke = value; - } - - void textFieldChanged ( String value ) - { - fieldString = value; - } - - void calledByTextarea ( String value ) - { - areaString = value; - } - - void theMenu ( String value ) - { - currentShape = int(value); - } - - /* and the interfaces */ - - /* explain inputs to Processing */ - interface InputElement - { - String type; - String id; - Object value; - } - - /* explain Controller to Processing */ - interface Controller - { - InputElement addRange ( String label, float initialValue, float minValue, float maxValue ); - void setLabel ( InputElement element, String label ); - }