Created
November 3, 2015 22:08
-
-
Save dougnukem/fc6c7e416da4dd68b1a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "application/javascript": [ | |
| "\n", | |
| " var component = document.getElementById(\"sketch_2\");\n", | |
| " if (component != undefined)\n", | |
| " component.remove();\n", | |
| " component = document.getElementById(\"state_2\");\n", | |
| " if (component != undefined)\n", | |
| " component.remove();\n", | |
| " component = document.getElementById(\"controls_div_2\");\n", | |
| " if (component != undefined)\n", | |
| " component.remove();\n", | |
| " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", | |
| " // FIXME: Stop all previously running versions (?)\n", | |
| " var processingInstance = Processing.getInstanceById(\"canvas_2\");\n", | |
| " if (processingInstance != undefined && processingInstance.isRunning())\n", | |
| " processingInstance.noLoop();\n", | |
| " });\n", | |
| " " | |
| ], | |
| "text/plain": [ | |
| "<IPython.core.display.Javascript object>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| }, | |
| { | |
| "data": { | |
| "text/html": [ | |
| "\n", | |
| "<div id=\"canvas_div_2\">\n", | |
| " <b>Sketch #2:</b><br/>\n", | |
| " <canvas id=\"canvas_2\"></canvas><br/>\n", | |
| "</div>\n", | |
| "<div id=\"controls_div_2\">\n", | |
| " <button id=\"run_button_2\" onclick=\"startSketch('2');\">\n", | |
| " <i class=\"fa fa-play-circle-o\" style=\"size: 2em;\"></i>\n", | |
| " Run\n", | |
| " </button>\n", | |
| " <button id=\"pause_button_2\" onclick=\"pauseSketch('2');\">\n", | |
| " <i class=\"fa fa-pause\" style=\"size: 2em;\"></i>\n", | |
| " Pause\n", | |
| " </button>\n", | |
| " <button id=\"setup_button_2\" onclick=\"setupSketch('2');\">\n", | |
| " setup()\n", | |
| " </button>\n", | |
| " <button id=\"draw_button_2\" onclick=\"drawSketch('2');\">\n", | |
| " draw()\n", | |
| " </button>\n", | |
| "</div>\n", | |
| "<b>Sketch #2 state:</b> <span id=\"state_2\">Loading...</span><br/>\n", | |
| "<script>\n", | |
| "\n", | |
| "function change_button(button, disable) {\n", | |
| " button.disabled = disable;\n", | |
| " if (disable) {\n", | |
| " button.style.color = \"grey\";\n", | |
| " } else {\n", | |
| " button.style.color = \"black\";\n", | |
| " }\n", | |
| "}\n", | |
| "\n", | |
| "function startSketch(id) {\n", | |
| " switchSketchState(id, true);\n", | |
| "}\n", | |
| "\n", | |
| "function pauseSketch(id) {\n", | |
| " switchSketchState(id, false);\n", | |
| "}\n", | |
| "\n", | |
| "function drawSketch(id) {\n", | |
| " var processingInstance = Processing.getInstanceById(\"canvas_\" + id);\n", | |
| " if (processingInstance != undefined) {\n", | |
| " if (processingInstance.draw != undefined) {\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = \"Drawing...\";\n", | |
| " try {\n", | |
| " processingInstance.redraw();\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = \"Drawing... done! Paused.\";\n", | |
| " document.getElementById(\"state_\" + id).style.color = \"blue\";\n", | |
| " } catch (e) {\n", | |
| " processingInstance.println(e.toString());\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = e.toString();\n", | |
| " document.getElementById(\"state_\" + id).style.color = \"red\";\n", | |
| " }\n", | |
| " } else {\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = \"No drawing() function. Paused.\";\n", | |
| " document.getElementById(\"state_\" + id).style.color = \"blue\";\n", | |
| " }\n", | |
| " } else {\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = \"Error.\";\n", | |
| " document.getElementById(\"state_\" + id).style.color = \"red\";\n", | |
| " }\n", | |
| " change_button(document.getElementById(\"run_button_\" + id), processingInstance.draw == undefined);\n", | |
| " change_button(document.getElementById(\"pause_button_\" + id), true);\n", | |
| " change_button(document.getElementById(\"setup_button_\" + id), processingInstance.setup == undefined);\n", | |
| " change_button(document.getElementById(\"draw_button_\" + id), processingInstance.draw == undefined);\n", | |
| "}\n", | |
| "\n", | |
| "function setupSketch(id) {\n", | |
| " var processingInstance = Processing.getInstanceById(\"canvas_\" + id);\n", | |
| " if (processingInstance != undefined) {\n", | |
| " if (processingInstance.setup != undefined) {\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = \"Setting up...\";\n", | |
| " try {\n", | |
| " processingInstance.setup();\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = \"Setting up... done! Paused.\";\n", | |
| " document.getElementById(\"state_\" + id).style.color = \"blue\";\n", | |
| " } catch (e) {\n", | |
| " processingInstance.println(e.toString());\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = e.toString();\n", | |
| " document.getElementById(\"state_\" + id).style.color = \"red\";\n", | |
| " }\n", | |
| " } else {\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = \"No setup() function. Paused.\";\n", | |
| " document.getElementById(\"state_\" + id).style.color = \"blue\";\n", | |
| " }\n", | |
| " } else {\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = \"Error.\";\n", | |
| " document.getElementById(\"state_\" + id).style.color = \"red\";\n", | |
| " }\n", | |
| " change_button(document.getElementById(\"run_button_\" + id), processingInstance.draw == undefined);\n", | |
| " change_button(document.getElementById(\"pause_button_\" + id), true);\n", | |
| " change_button(document.getElementById(\"setup_button_\" + id), processingInstance.setup == undefined);\n", | |
| " change_button(document.getElementById(\"draw_button_\" + id), processingInstance.draw == undefined);\n", | |
| "}\n", | |
| "\n", | |
| "function switchSketchState(id, on) {\n", | |
| " var processingInstance = Processing.getInstanceById(\"canvas_\" + id);\n", | |
| " if (on) {\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = \"Running...\";\n", | |
| " document.getElementById(\"state_\" + id).style.color = \"green\";\n", | |
| " change_button(document.getElementById(\"run_button_\" + id), true);\n", | |
| " change_button(document.getElementById(\"pause_button_\" + id), processingInstance.draw == undefined);\n", | |
| " change_button(document.getElementById(\"setup_button_\" + id), true);\n", | |
| " change_button(document.getElementById(\"draw_button_\" + id), true);\n", | |
| " processingInstance.loop(); // call Processing loop() function\n", | |
| " } else {\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = \"Paused.\";\n", | |
| " document.getElementById(\"state_\" + id).style.color = \"blue\";\n", | |
| " change_button(document.getElementById(\"run_button_\" + id), processingInstance.draw == undefined);\n", | |
| " change_button(document.getElementById(\"pause_button_\" + id), true);\n", | |
| " change_button(document.getElementById(\"setup_button_\" + id), processingInstance.setup == undefined);\n", | |
| " change_button(document.getElementById(\"draw_button_\" + id), processingInstance.draw == undefined);\n", | |
| " processingInstance.noLoop(); // stop animation, call noLoop()\n", | |
| " }\n", | |
| "}\n", | |
| "\n", | |
| "require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function () {\n", | |
| " var processingCode = \"// Global variables\\nfloat radius = 50.0;\\nint X, Y;\\nint nX, nY;\\nint delay = 16;\\n\\n// Setup the Processing Canvas\\nvoid setup(){\\n size( 200, 200 );\\n strokeWeight( 10 );\\n frameRate( 15 );\\n X = width / 2;\\n Y = height / 2;\\n nX = X;\\n nY = Y; \\n}\\n\\n// Main draw loop\\nvoid draw(){\\n \\n radius = radius + sin( frameCount / 4 );\\n \\n // Track circle to new destination\\n X+=(nX-X)/delay;\\n Y+=(nY-Y)/delay;\\n \\n // Fill canvas grey\\n background( 100 );\\n \\n // Set fill-color to blue\\n fill( 0, 121, 184 );\\n \\n // Set stroke-color white\\n stroke(255); \\n \\n // Draw circle\\n ellipse( X, Y, radius, radius ); \\n}\\n\\n\\n// Set circle's next destination\\nvoid mouseMoved(){\\n nX = mouseX;\\n nY = mouseY; \\n}\";\n", | |
| " var cc;\n", | |
| " var processingInstance;\n", | |
| " var has_error = false;\n", | |
| " try {\n", | |
| " cc = Processing.compile(processingCode);\n", | |
| " } catch (e) {\n", | |
| " console.log(e);\n", | |
| " cc = Processing.compile(\"println('\" + e.toString() + \"');\");\n", | |
| " document.getElementById(\"state_2\").innerHTML = e.toString();\n", | |
| " document.getElementById(\"state_2\").style.color = \"red\";\n", | |
| " has_error = true;\n", | |
| " }\n", | |
| " if (cc != undefined) {\n", | |
| " try {\n", | |
| " processingInstance = new Processing(\"canvas_2\", cc);\n", | |
| " } catch (e) {\n", | |
| " console.log(e);\n", | |
| " cc = Processing.compile(\"println('\" + e.toString() + \"');\");\n", | |
| " document.getElementById(\"state_2\").innerHTML = e.toString();\n", | |
| " document.getElementById(\"state_2\").style.color = \"red\";\n", | |
| " processingInstance = new Processing(\"canvas_2\", cc);\n", | |
| " has_error = true;\n", | |
| " }\n", | |
| " }\n", | |
| " if (processingInstance != undefined) {\n", | |
| " setTimeout(function () {\n", | |
| " // Canvas:\n", | |
| " if (processingInstance.externals.context === undefined) {\n", | |
| " document.getElementById(\"canvas_div_2\").style.display = \"none\";\n", | |
| " }\n", | |
| " }, 100);\n", | |
| " // Controls:\n", | |
| " if (!(processingInstance.isRunning() && processingInstance.draw != undefined)) {\n", | |
| " document.getElementById(\"controls_div_2\").style.display = \"none\";\n", | |
| " }\n", | |
| " if (processingInstance.draw != undefined) {\n", | |
| " if (!has_error) {\n", | |
| " document.getElementById(\"state_2\").innerHTML = \"Running...\";\n", | |
| " document.getElementById(\"state_2\").style.color = \"green\";\n", | |
| " }\n", | |
| " change_button(document.getElementById(\"run_button_2\"), true);\n", | |
| " change_button(document.getElementById(\"pause_button_2\"), false);\n", | |
| " change_button(document.getElementById(\"setup_button_2\"), true);\n", | |
| " change_button(document.getElementById(\"draw_button_2\"), true);\n", | |
| " } else {\n", | |
| " if (!has_error) {\n", | |
| " document.getElementById(\"state_2\").innerHTML = \"Done.\";\n", | |
| " document.getElementById(\"state_2\").style.color = \"blue\";\n", | |
| " }\n", | |
| " change_button(document.getElementById(\"run_button_2\"), true);\n", | |
| " change_button(document.getElementById(\"pause_button_2\"), true);\n", | |
| " change_button(document.getElementById(\"setup_button_2\"), processingInstance.setup == undefined);\n", | |
| " change_button(document.getElementById(\"draw_button_2\"), true);\n", | |
| " }\n", | |
| " } else {\n", | |
| " document.getElementById(\"canvas_div_2\").style.display = \"none\";\n", | |
| " document.getElementById(\"controls_div_2\").style.display = \"none\";\n", | |
| " if (!has_error) {\n", | |
| " document.getElementById(\"state_2\").innerHTML = \"Error.\";\n", | |
| " document.getElementById(\"state_2\").style.color = \"red\";\n", | |
| " }\n", | |
| " change_button(document.getElementById(\"run_button_2\"), true);\n", | |
| " change_button(document.getElementById(\"pause_button_2\"), true);\n", | |
| " change_button(document.getElementById(\"setup_button_2\"), true);\n", | |
| " change_button(document.getElementById(\"draw_button_2\"), true);\n", | |
| " }\n", | |
| "});\n", | |
| "\n", | |
| "</script>\n" | |
| ], | |
| "text/plain": [ | |
| "<IPython.core.display.HTML object>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| } | |
| ], | |
| "source": [ | |
| "// Global variables\n", | |
| "float radius = 50.0;\n", | |
| "int X, Y;\n", | |
| "int nX, nY;\n", | |
| "int delay = 16;\n", | |
| "\n", | |
| "// Setup the Processing Canvas\n", | |
| "void setup(){\n", | |
| " size( 200, 200 );\n", | |
| " strokeWeight( 10 );\n", | |
| " frameRate( 15 );\n", | |
| " X = width / 2;\n", | |
| " Y = height / 2;\n", | |
| " nX = X;\n", | |
| " nY = Y; \n", | |
| "}\n", | |
| "\n", | |
| "// Main draw loop\n", | |
| "void draw(){\n", | |
| " \n", | |
| " radius = radius + sin( frameCount / 4 );\n", | |
| " \n", | |
| " // Track circle to new destination\n", | |
| " X+=(nX-X)/delay;\n", | |
| " Y+=(nY-Y)/delay;\n", | |
| " \n", | |
| " // Fill canvas grey\n", | |
| " background( 100 );\n", | |
| " \n", | |
| " // Set fill-color to blue\n", | |
| " fill( 0, 121, 184 );\n", | |
| " \n", | |
| " // Set stroke-color white\n", | |
| " stroke(255); \n", | |
| " \n", | |
| " // Draw circle\n", | |
| " ellipse( X, Y, radius, radius ); \n", | |
| "}\n", | |
| "\n", | |
| "\n", | |
| "// Set circle's next destination\n", | |
| "void mouseMoved(){\n", | |
| " nX = mouseX;\n", | |
| " nY = mouseY; \n", | |
| "}" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 11, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Downloaded 'greenscreen1.jpg'.\n" | |
| ] | |
| } | |
| ], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 12, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Downloaded 'greenscreen2.jpg'.\n" | |
| ] | |
| }, | |
| { | |
| "data": { | |
| "application/javascript": [ | |
| "\n", | |
| " var component = document.getElementById(\"sketch_8\");\n", | |
| " if (component != undefined)\n", | |
| " component.remove();\n", | |
| " component = document.getElementById(\"state_8\");\n", | |
| " if (component != undefined)\n", | |
| " component.remove();\n", | |
| " component = document.getElementById(\"controls_div_8\");\n", | |
| " if (component != undefined)\n", | |
| " component.remove();\n", | |
| " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", | |
| " // FIXME: Stop all previously running versions (?)\n", | |
| " var processingInstance = Processing.getInstanceById(\"canvas_8\");\n", | |
| " if (processingInstance != undefined && processingInstance.isRunning())\n", | |
| " processingInstance.noLoop();\n", | |
| " });\n", | |
| " " | |
| ], | |
| "text/plain": [ | |
| "<IPython.core.display.Javascript object>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| }, | |
| { | |
| "data": { | |
| "text/html": [ | |
| "\n", | |
| "<div id=\"canvas_div_8\">\n", | |
| " <b>Sketch #8:</b><br/>\n", | |
| " <canvas id=\"canvas_8\"></canvas><br/>\n", | |
| "</div>\n", | |
| "<div id=\"controls_div_8\">\n", | |
| " <button id=\"run_button_8\" onclick=\"startSketch('8');\">\n", | |
| " <i class=\"fa fa-play-circle-o\" style=\"size: 2em;\"></i>\n", | |
| " Run\n", | |
| " </button>\n", | |
| " <button id=\"pause_button_8\" onclick=\"pauseSketch('8');\">\n", | |
| " <i class=\"fa fa-pause\" style=\"size: 2em;\"></i>\n", | |
| " Pause\n", | |
| " </button>\n", | |
| " <button id=\"setup_button_8\" onclick=\"setupSketch('8');\">\n", | |
| " setup()\n", | |
| " </button>\n", | |
| " <button id=\"draw_button_8\" onclick=\"drawSketch('8');\">\n", | |
| " draw()\n", | |
| " </button>\n", | |
| "</div>\n", | |
| "<b>Sketch #8 state:</b> <span id=\"state_8\">Loading...</span><br/>\n", | |
| "<script>\n", | |
| "\n", | |
| "function change_button(button, disable) {\n", | |
| " button.disabled = disable;\n", | |
| " if (disable) {\n", | |
| " button.style.color = \"grey\";\n", | |
| " } else {\n", | |
| " button.style.color = \"black\";\n", | |
| " }\n", | |
| "}\n", | |
| "\n", | |
| "function startSketch(id) {\n", | |
| " switchSketchState(id, true);\n", | |
| "}\n", | |
| "\n", | |
| "function pauseSketch(id) {\n", | |
| " switchSketchState(id, false);\n", | |
| "}\n", | |
| "\n", | |
| "function drawSketch(id) {\n", | |
| " var processingInstance = Processing.getInstanceById(\"canvas_\" + id);\n", | |
| " if (processingInstance != undefined) {\n", | |
| " if (processingInstance.draw != undefined) {\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = \"Drawing...\";\n", | |
| " try {\n", | |
| " processingInstance.redraw();\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = \"Drawing... done! Paused.\";\n", | |
| " document.getElementById(\"state_\" + id).style.color = \"blue\";\n", | |
| " } catch (e) {\n", | |
| " processingInstance.println(e.toString());\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = e.toString();\n", | |
| " document.getElementById(\"state_\" + id).style.color = \"red\";\n", | |
| " }\n", | |
| " } else {\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = \"No drawing() function. Paused.\";\n", | |
| " document.getElementById(\"state_\" + id).style.color = \"blue\";\n", | |
| " }\n", | |
| " } else {\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = \"Error.\";\n", | |
| " document.getElementById(\"state_\" + id).style.color = \"red\";\n", | |
| " }\n", | |
| " change_button(document.getElementById(\"run_button_\" + id), processingInstance.draw == undefined);\n", | |
| " change_button(document.getElementById(\"pause_button_\" + id), true);\n", | |
| " change_button(document.getElementById(\"setup_button_\" + id), processingInstance.setup == undefined);\n", | |
| " change_button(document.getElementById(\"draw_button_\" + id), processingInstance.draw == undefined);\n", | |
| "}\n", | |
| "\n", | |
| "function setupSketch(id) {\n", | |
| " var processingInstance = Processing.getInstanceById(\"canvas_\" + id);\n", | |
| " if (processingInstance != undefined) {\n", | |
| " if (processingInstance.setup != undefined) {\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = \"Setting up...\";\n", | |
| " try {\n", | |
| " processingInstance.setup();\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = \"Setting up... done! Paused.\";\n", | |
| " document.getElementById(\"state_\" + id).style.color = \"blue\";\n", | |
| " } catch (e) {\n", | |
| " processingInstance.println(e.toString());\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = e.toString();\n", | |
| " document.getElementById(\"state_\" + id).style.color = \"red\";\n", | |
| " }\n", | |
| " } else {\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = \"No setup() function. Paused.\";\n", | |
| " document.getElementById(\"state_\" + id).style.color = \"blue\";\n", | |
| " }\n", | |
| " } else {\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = \"Error.\";\n", | |
| " document.getElementById(\"state_\" + id).style.color = \"red\";\n", | |
| " }\n", | |
| " change_button(document.getElementById(\"run_button_\" + id), processingInstance.draw == undefined);\n", | |
| " change_button(document.getElementById(\"pause_button_\" + id), true);\n", | |
| " change_button(document.getElementById(\"setup_button_\" + id), processingInstance.setup == undefined);\n", | |
| " change_button(document.getElementById(\"draw_button_\" + id), processingInstance.draw == undefined);\n", | |
| "}\n", | |
| "\n", | |
| "function switchSketchState(id, on) {\n", | |
| " var processingInstance = Processing.getInstanceById(\"canvas_\" + id);\n", | |
| " if (on) {\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = \"Running...\";\n", | |
| " document.getElementById(\"state_\" + id).style.color = \"green\";\n", | |
| " change_button(document.getElementById(\"run_button_\" + id), true);\n", | |
| " change_button(document.getElementById(\"pause_button_\" + id), processingInstance.draw == undefined);\n", | |
| " change_button(document.getElementById(\"setup_button_\" + id), true);\n", | |
| " change_button(document.getElementById(\"draw_button_\" + id), true);\n", | |
| " processingInstance.loop(); // call Processing loop() function\n", | |
| " } else {\n", | |
| " document.getElementById(\"state_\" + id).innerHTML = \"Paused.\";\n", | |
| " document.getElementById(\"state_\" + id).style.color = \"blue\";\n", | |
| " change_button(document.getElementById(\"run_button_\" + id), processingInstance.draw == undefined);\n", | |
| " change_button(document.getElementById(\"pause_button_\" + id), true);\n", | |
| " change_button(document.getElementById(\"setup_button_\" + id), processingInstance.setup == undefined);\n", | |
| " change_button(document.getElementById(\"draw_button_\" + id), processingInstance.draw == undefined);\n", | |
| " processingInstance.noLoop(); // stop animation, call noLoop()\n", | |
| " }\n", | |
| "}\n", | |
| "\n", | |
| "require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function () {\n", | |
| " var processingCode = '/* @pjs preload=\"greenscreen2.jpg\"; */\\n\\nPImage img;\\n\\nvoid setup() {\\n img = loadImage(\"greenscreen2.jpg\");\\n // println(\"\" + img.width + \" x \" + img.height)\\n // 1920 x 1080\\n // Resize to a more reasonable size:\\n img.resize(img.width/10, img.height/10);\\n // Make sketch size match:\\n size(img.width, img.height);\\n}\\n\\nvoid draw() {\\n image(img, 0, 0);\\n noLoop();\\n}';\n", | |
| " var cc;\n", | |
| " var processingInstance;\n", | |
| " var has_error = false;\n", | |
| " try {\n", | |
| " cc = Processing.compile(processingCode);\n", | |
| " } catch (e) {\n", | |
| " console.log(e);\n", | |
| " cc = Processing.compile(\"println('\" + e.toString() + \"');\");\n", | |
| " document.getElementById(\"state_8\").innerHTML = e.toString();\n", | |
| " document.getElementById(\"state_8\").style.color = \"red\";\n", | |
| " has_error = true;\n", | |
| " }\n", | |
| " if (cc != undefined) {\n", | |
| " try {\n", | |
| " processingInstance = new Processing(\"canvas_8\", cc);\n", | |
| " } catch (e) {\n", | |
| " console.log(e);\n", | |
| " cc = Processing.compile(\"println('\" + e.toString() + \"');\");\n", | |
| " document.getElementById(\"state_8\").innerHTML = e.toString();\n", | |
| " document.getElementById(\"state_8\").style.color = \"red\";\n", | |
| " processingInstance = new Processing(\"canvas_8\", cc);\n", | |
| " has_error = true;\n", | |
| " }\n", | |
| " }\n", | |
| " if (processingInstance != undefined) {\n", | |
| " setTimeout(function () {\n", | |
| " // Canvas:\n", | |
| " if (processingInstance.externals.context === undefined) {\n", | |
| " document.getElementById(\"canvas_div_8\").style.display = \"none\";\n", | |
| " }\n", | |
| " }, 100);\n", | |
| " // Controls:\n", | |
| " if (!(processingInstance.isRunning() && processingInstance.draw != undefined)) {\n", | |
| " document.getElementById(\"controls_div_8\").style.display = \"none\";\n", | |
| " }\n", | |
| " if (processingInstance.draw != undefined) {\n", | |
| " if (!has_error) {\n", | |
| " document.getElementById(\"state_8\").innerHTML = \"Running...\";\n", | |
| " document.getElementById(\"state_8\").style.color = \"green\";\n", | |
| " }\n", | |
| " change_button(document.getElementById(\"run_button_8\"), true);\n", | |
| " change_button(document.getElementById(\"pause_button_8\"), false);\n", | |
| " change_button(document.getElementById(\"setup_button_8\"), true);\n", | |
| " change_button(document.getElementById(\"draw_button_8\"), true);\n", | |
| " } else {\n", | |
| " if (!has_error) {\n", | |
| " document.getElementById(\"state_8\").innerHTML = \"Done.\";\n", | |
| " document.getElementById(\"state_8\").style.color = \"blue\";\n", | |
| " }\n", | |
| " change_button(document.getElementById(\"run_button_8\"), true);\n", | |
| " change_button(document.getElementById(\"pause_button_8\"), true);\n", | |
| " change_button(document.getElementById(\"setup_button_8\"), processingInstance.setup == undefined);\n", | |
| " change_button(document.getElementById(\"draw_button_8\"), true);\n", | |
| " }\n", | |
| " } else {\n", | |
| " document.getElementById(\"canvas_div_8\").style.display = \"none\";\n", | |
| " document.getElementById(\"controls_div_8\").style.display = \"none\";\n", | |
| " if (!has_error) {\n", | |
| " document.getElementById(\"state_8\").innerHTML = \"Error.\";\n", | |
| " document.getElementById(\"state_8\").style.color = \"red\";\n", | |
| " }\n", | |
| " change_button(document.getElementById(\"run_button_8\"), true);\n", | |
| " change_button(document.getElementById(\"pause_button_8\"), true);\n", | |
| " change_button(document.getElementById(\"setup_button_8\"), true);\n", | |
| " change_button(document.getElementById(\"draw_button_8\"), true);\n", | |
| " }\n", | |
| "});\n", | |
| "\n", | |
| "</script>\n" | |
| ], | |
| "text/plain": [ | |
| "<IPython.core.display.HTML object>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| } | |
| ], | |
| "source": [ | |
| "%download http://blog.unem.de/wp-content/uploads/2012/05/11-Greenscreen-Clarissa-Knorr.jpg -f greenscreen2.jpg\n", | |
| "/* @pjs preload=\"greenscreen2.jpg\"; */\n", | |
| "\n", | |
| "PImage img;\n", | |
| "\n", | |
| "void setup() {\n", | |
| " img = loadImage(\"greenscreen2.jpg\");\n", | |
| " // println(\"\" + img.width + \" x \" + img.height)\n", | |
| " // 1920 x 1080\n", | |
| " // Resize to a more reasonable size:\n", | |
| " img.resize(img.width/10, img.height/10);\n", | |
| " // Make sketch size match:\n", | |
| " size(img.width, img.height);\n", | |
| "}\n", | |
| "\n", | |
| "void draw() {\n", | |
| " image(img, 0, 0);\n", | |
| " noLoop();\n", | |
| "}\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Calysto Processing", | |
| "language": "java", | |
| "name": "calysto_processing" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "text/x-java", | |
| "version": 2 | |
| }, | |
| "file_extension": ".java", | |
| "mimetype": "text/x-java", | |
| "name": "java" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 0 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment