├── .editorconfig ├── .gitignore ├── LICENSE ├── README.md ├── app ├── debug │ ├── client.js │ ├── cycle.js │ ├── index.js │ ├── style.scss │ └── template.html ├── editor │ ├── index.js │ ├── style.scss │ └── template.html ├── files.js ├── keybindings.js ├── main.js ├── menu.js ├── modes │ └── p5 │ │ └── p5-mode.js ├── settings.js ├── settings │ ├── index.js │ ├── style.scss │ └── template.html ├── sidebar │ ├── file.html │ ├── folder.html │ ├── index.js │ ├── sidebar.html │ └── style.scss ├── tabs │ ├── index.js │ ├── style.scss │ ├── tab.html │ └── template.html ├── updater.js ├── window │ └── window.scss └── windowstate.js ├── contributing.md ├── gulpfile.js ├── icons ├── p5js.icns └── p5js.ico ├── lib ├── ffmpegsumo.dll └── ffmpegsumo.so ├── package.json ├── public ├── boot.html ├── fonts │ ├── Inconsolata.otf │ ├── Montserrat-Bold.ttf │ ├── Montserrat-Regular.ttf │ └── icons.otf ├── images │ ├── browser.svg │ ├── close-button.svg │ ├── code.svg │ ├── collapsed.svg │ ├── consoleH.svg │ ├── consoleV.svg │ ├── database.svg │ ├── expanded.svg │ ├── file.svg │ ├── file1.svg │ ├── folder.svg │ ├── gear.svg │ ├── gears.svg │ ├── image.svg │ ├── library.svg │ ├── minus-button.svg │ ├── options.svg │ ├── p5-logo.png │ ├── package.svg │ ├── play-button-flip.svg │ ├── play-button.svg │ ├── plus-button.svg │ ├── plus.svg │ ├── settings-button-flip.svg │ ├── settings-button.svg │ ├── sidebar.svg │ ├── sliders.svg │ ├── stop-button-flip.svg │ ├── stop-button.svg │ ├── stop-gray.svg │ ├── stop-red.svg │ ├── textAdjust.svg │ ├── upload.svg │ └── wordWrap.svg ├── index.html ├── js │ └── debug-console.js ├── mode_assets │ └── p5 │ │ ├── empty_project │ │ ├── index.html │ │ ├── libraries │ │ │ ├── p5.dom.js │ │ │ ├── p5.js │ │ │ └── p5.sound.js │ │ └── sketch.js │ │ ├── example_assets │ │ ├── 360video_256crop_v2.mp4 │ │ ├── Damscray_-_Dancing_Tiger_01.mp3 │ │ ├── Damscray_-_Dancing_Tiger_01.ogg │ │ ├── Damscray_-_Dancing_Tiger_02.mp3 │ │ ├── Damscray_-_Dancing_Tiger_02.ogg │ │ ├── Damscray_DancingTiger.mp3 │ │ ├── Damscray_DancingTiger.ogg │ │ ├── LeagueGothic-Regular.otf │ │ ├── beat.mp3 │ │ ├── beat.ogg │ │ ├── beatbox.mp3 │ │ ├── beatbox.ogg │ │ ├── bx-spring.mp3 │ │ ├── bx-spring.ogg │ │ ├── cat.jpg │ │ ├── concrete-tunnel.mp3 │ │ ├── concrete-tunnel.ogg │ │ ├── doorbell.mp3 │ │ ├── doorbell.ogg │ │ ├── drum.mp3 │ │ ├── drum.ogg │ │ ├── fingers.mov │ │ ├── fingers.webm │ │ ├── large-dark-plate.mp3 │ │ ├── large-dark-plate.ogg │ │ ├── lucky_dragons_-_power_melody.mp3 │ │ ├── lucky_dragons_-_power_melody.ogg │ │ ├── mask.png │ │ ├── moonwalk.jpg │ │ ├── particle_texture.png │ │ ├── small-plate.mp3 │ │ └── small-plate.ogg │ │ ├── examples │ │ ├── 3D │ │ │ ├── 00_geometries.js │ │ │ ├── 01_sine_cosine_in_3D.js │ │ │ ├── 02_multiple_lights.js │ │ │ ├── 03_materials.js │ │ │ ├── 04_textures.js │ │ │ └── 07_orbit_control.js │ │ ├── Arrays │ │ │ ├── 00_Array.js │ │ │ ├── 01_Array_2d.js │ │ │ └── 02_Array_Objects.js │ │ ├── Color │ │ │ ├── 00_Hue.js │ │ │ ├── 01_Saturation.js │ │ │ ├── 02_Brightness.js │ │ │ ├── 03_Color_Variables.js │ │ │ ├── 04_Relativity.js │ │ │ ├── 05_Linear_Gradient.js │ │ │ ├── 06_Radial_Gradient.js │ │ │ └── 07_Lerp_Color.js │ │ ├── Control │ │ │ ├── 00_Iteration.js │ │ │ ├── 01_Embedded_Iteration.js │ │ │ ├── 02_Conditionals_1.js │ │ │ ├── 03_Conditionals_2.js │ │ │ └── 04_Logical_Operators.js │ │ ├── Data │ │ │ ├── 00_Variables.js │ │ │ ├── 01_True_and_False.js │ │ │ └── 03_Variable_Scope.js │ │ ├── Dom │ │ │ ├── 03_Input_Button.js │ │ │ ├── 04_Slider.js │ │ │ ├── 07_Modify_DOM.js │ │ │ ├── 08_Video.js │ │ │ ├── 09_Video_Canvas.js │ │ │ ├── 10_Video_Pixels.js │ │ │ ├── 11_Capture.js │ │ │ └── 12_Drop.js │ │ ├── Form │ │ │ ├── 00_Points_and_Lines.js │ │ │ ├── 01_Shape_Primitives.js │ │ │ ├── 02_Pie_Chart.js │ │ │ ├── 03_Regular_Polygon.js │ │ │ ├── 04_Star.js │ │ │ ├── 05_Triangle_Strip.js │ │ │ ├── 06_Bezier.js │ │ │ └── 07_3D_Primitives.js │ │ ├── Hello │ │ │ ├── 01_shapes.js │ │ │ ├── 02_interactivity.js │ │ │ ├── 03_interactivity.js │ │ │ ├── 04_animate.js │ │ │ ├── 04_flocking.js │ │ │ ├── 05_weather.js │ │ │ ├── 06_drawing.js │ │ │ └── 07_song.js │ │ ├── Image │ │ │ ├── 00_Load_and_Display_Image.js │ │ │ ├── 01_Background_Image.js │ │ │ ├── 02_Transparency.js │ │ │ ├── 03_Alpha_Mask.js │ │ │ ├── 04_Create_Image.js │ │ │ └── 05_Pointillism.js │ │ ├── Instance │ │ │ ├── 01_Instantiating.js │ │ │ └── 02_Instance_Container.js │ │ ├── Interaction │ │ │ ├── 10_Tickle.js │ │ │ ├── 20_Follow1.js │ │ │ ├── 21_Follow2.js │ │ │ ├── 22_Follow3.js │ │ │ ├── reach1.js │ │ │ ├── reach2.js │ │ │ └── reach3.js │ │ ├── Lights │ │ │ ├── 02_Directional.js │ │ │ └── 05_Mixture.js │ │ ├── Math │ │ │ ├── 00_incrementdecrement.js │ │ │ ├── 01_operatorprecedence.js │ │ │ ├── 02_distance1d.js │ │ │ ├── 03_distance2d.js │ │ │ ├── 04_sine.js │ │ │ ├── 05_sincosine.js │ │ │ ├── 06_sinewave.js │ │ │ ├── 07_additivewave.js │ │ │ ├── 08_polartocartesian.js │ │ │ ├── 11_doubleRandom.js │ │ │ ├── 12_random.js │ │ │ ├── 13_noise1D.js │ │ │ ├── 14_noisewave.js │ │ │ └── 15_arctangent.js │ │ ├── Mobile │ │ │ ├── 00_Acceleration_Ball_Bounce.js │ │ │ ├── 00_acceleration_ballBounce.js │ │ │ ├── 01_Simple_Draw.js │ │ │ ├── 01_simpleDraw.js │ │ │ ├── 02_Acceleration_Color.js │ │ │ ├── 02_accelerationColor.js │ │ │ ├── 03_Shake_Ball_Bounce.js │ │ │ ├── 03_shake_ballBounce.js │ │ │ └── 04_tilted_3D_box.js │ │ ├── Objects │ │ │ ├── 01_Objects.js │ │ │ ├── 02_Multiple_Objects.js │ │ │ ├── 03_Objects_Array.js │ │ │ └── 03_Objects_Optional_Arguments.js │ │ ├── Simulate │ │ │ ├── 01_Forces.js │ │ │ ├── 02_ParticleSystem.js │ │ │ ├── 03_Flocking.js │ │ │ ├── 04_WolframCA.js │ │ │ ├── 05_GameOfLife.js │ │ │ ├── 06_MultipleParticleSystems.js │ │ │ ├── 07_Spirograph.js │ │ │ ├── 08_LSystems.js │ │ │ ├── 09_Spring.js │ │ │ ├── 10_SoftBody.js │ │ │ ├── 11_SmokeParticleSystem.js │ │ │ └── 12_BrownianMotion.js │ │ ├── Sound │ │ │ ├── 00_Load_and_Play_Sound.js │ │ │ ├── 01_Preload_Sound.js │ │ │ ├── 02_soundFormats.js │ │ │ ├── 03_Play_Mode.js │ │ │ ├── 04_Pan_SoundFile.js │ │ │ ├── 05_Sound_Effect.js │ │ │ ├── 06_Manipulate_Sound.js │ │ │ ├── 07_Amplitude_Analysis.js │ │ │ ├── 08_Noise_Envelope.js │ │ │ ├── 09_Note_Envelope.js │ │ │ ├── 10_Oscillator_Waveform.js │ │ │ ├── 11_Live_Input.js │ │ │ ├── 12_FFT_Spectrum.js │ │ │ ├── 13_Mic_Threshold.js │ │ │ ├── 14_Filter_LowPass.js │ │ │ ├── 15_Filter_BandPass.js │ │ │ ├── 16_Delay.js │ │ │ ├── 17_Reverb.js │ │ │ ├── 18_Convolution_Reverb.js │ │ │ ├── 19_Record_Save.js │ │ │ ├── 21_FreqModulation.js │ │ │ └── 22_AmplitudeModulation.js │ │ └── Structure │ │ │ ├── 00_Coordinates.js │ │ │ ├── 01_Width_and_Height.js │ │ │ ├── 02_Setup_and_Draw.js │ │ │ ├── 03_No_Loop.js │ │ │ ├── 04_Loop.js │ │ │ ├── 05_Redraw.js │ │ │ ├── 06_Functions.js │ │ │ ├── 07_Recursion.js │ │ │ └── 08_Create_Graphics.js │ │ ├── libraries │ │ └── p5.serialport.js │ │ └── server.js ├── package.json └── serial.html └── release-howto.md /.editorconfig: -------------------------------------------------------------------------------- 1 | ; http://editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | indent_style = space 7 | indent_size = 2 8 | end_of_line = lf 9 | charset = utf-8 10 | trim_trailing_whitespace = true 11 | insert_final_newline = true 12 | 13 | [*.md] 14 | indent_size = 4 15 | 16 | [node_modules/**.js] 17 | codepaint = false 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .org.chromium.* 2 | *.sublime-* 3 | node_modules/ 4 | dist/ 5 | cache/ 6 | public/js/main.js 7 | public/css 8 | public/mode_assets/p5/p5-reference 9 | .DS_Store 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Brandon Pierce 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /app/debug/client.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 3 | var original = window.console; 4 | window.console = {}; 5 | window._isNodeWebkit = true; 6 | 7 | ["log", "warn", "error"].forEach(function(func) { 8 | window.console[func] = function(msg) { 9 | var style = null; 10 | if (arguments[2] && arguments[0].indexOf('%c') > -1) { 11 | style = arguments[1]; 12 | } 13 | var data = { 14 | msg: JSON.stringify(JSON.decycle(msg, true), null, ' '), 15 | style: style, 16 | type: func 17 | }; 18 | 19 | window.opener.postMessage(JSON.stringify({ console: data}), 'file://'); 20 | 21 | original[func].apply(original, arguments); 22 | }; 23 | }); 24 | 25 | 26 | window.onerror = function(msg, url, num, column, errorObj) { 27 | var data = { 28 | num: num, 29 | // msg: JSON.stringify(JSON.decycle(msg, true), null, ' '), 30 | msg: msg, 31 | type: 'error' 32 | }; 33 | 34 | window.opener.postMessage(JSON.stringify({ console: data}), 'file://'); 35 | 36 | return false; 37 | }; 38 | 39 | function downloadFile() { 40 | window.opener.postMessage(JSON.stringify({ downloadFile: arguments }), 'file://'); 41 | } 42 | 43 | var booted = false; 44 | var interval = setInterval(function() { 45 | if (typeof p5 !== 'undefined' && !booted) { 46 | p5.prototype.downloadFile = downloadFile; 47 | booted = true; 48 | clearInterval(interval); 49 | } 50 | }, 10); 51 | 52 | })(); 53 | 54 | -------------------------------------------------------------------------------- /app/debug/style.scss: -------------------------------------------------------------------------------- 1 | #debug { 2 | background-color: #eeeeee; 3 | flex: 1; 4 | color: #333; 5 | overflow: auto; 6 | 7 | div { 8 | margin: 5px; 9 | white-space: pre; 10 | a { 11 | color: #fff; 12 | background-color: #333; 13 | } 14 | } 15 | } 16 | 17 | .error { 18 | color: red; 19 | } 20 | 21 | #debug-container { 22 | width: 100px; 23 | height: auto; 24 | display: flex; 25 | flex-direction: column; 26 | justify-content: flex-start; 27 | position: relative; 28 | min-width: 10px; 29 | min-height: 10px; 30 | } 31 | 32 | #debug-drag { 33 | background-color: rgba(153, 153, 153, 0.5); 34 | padding-top: 2px; 35 | height: 18px !important; 36 | cursor: col-resize; 37 | color: #b1b1b1; 38 | font-size: 12px; 39 | } 40 | 41 | .prompt-label { 42 | margin-left: 25px; 43 | } 44 | 45 | .console-label { 46 | margin-left: 23px; 47 | } 48 | 49 | 50 | body.horizontal { 51 | #debug-container { 52 | height: 100px; 53 | width: auto; 54 | flex-direction: column; 55 | margin-right: 0; 56 | } 57 | 58 | #debug-drag { 59 | height: 10px; 60 | width: auto; 61 | cursor: row-resize; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/debug/template.html: -------------------------------------------------------------------------------- 1 |
>_console
2 |
3 | -------------------------------------------------------------------------------- /app/editor/template.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | -------------------------------------------------------------------------------- /app/keybindings.js: -------------------------------------------------------------------------------- 1 | var $ = require('jquery'); 2 | var Mousetrap = require('br-mousetrap'); 3 | 4 | module.exports.setup = function(app) { 5 | /*Mousetrap.bind(['command+r', 'ctrl+r'], function(e) { 6 | app.run(); 7 | }); 8 | 9 | Mousetrap.bind(['command+o', 'ctrl+o'], function(e) { 10 | $('#openFile').trigger('click'); 11 | }); 12 | 13 | Mousetrap.bind(['command+s', 'ctrl+s'], function(e) { 14 | app.saveFile(); 15 | }); 16 | 17 | Mousetrap.bind(['command+shift+s', 'ctrl+shift+s'], function(e) { 18 | $('#saveFile').trigger('click'); 19 | }); 20 | 21 | Mousetrap.bind(['command+n', 'ctrl+n'], function(e) { 22 | app.newFile(); 23 | }); 24 | 25 | Mousetrap.bind(['command+shift+n', 'ctrl+shift+n'], function(e) { 26 | app.newWindow(app.windowURL); 27 | }); 28 | 29 | Mousetrap.bind(['command+w', 'ctrl+w'], function(e) { 30 | app.closeProject(); 31 | }); */ 32 | 33 | //Mousetrap.bind(['command+e', 'ctrl+e'], function(e) { 34 | //app.export(); 35 | //}); 36 | 37 | Mousetrap.bind(['command+alt+j', 'ctrl+alt+j'], function(e) { 38 | gui.Window.get().showDevTools(); 39 | }); 40 | 41 | /*Mousetrap.bind(['command+=', 'ctrl+='], function(e) { 42 | app.changeFontSize(1); 43 | }); 44 | 45 | Mousetrap.bind(['command+-', 'ctrl+-'], function(e) { 46 | app.changeFontSize(-1); 47 | });*/ 48 | 49 | /*Mousetrap.bind(['command+t', 'ctrl+t'], function(e) { 50 | app.$.editor.reformat(); 51 | });*/ 52 | 53 | /*Mousetrap.bind(['command+,', 'ctrl+,'], function(e) { 54 | app.toggleSettingsPane(); 55 | });*/ 56 | 57 | Mousetrap.stopCallback = function(e, element, combo) { 58 | return false; 59 | } 60 | } 61 | 62 | -------------------------------------------------------------------------------- /app/settings.js: -------------------------------------------------------------------------------- 1 | var defaults = { 2 | fontSize: 14, 3 | tabSize: 2, 4 | tabType: 'spaces', 5 | theme: 'tomorrow', 6 | consoleOrientation: 'horizontal', 7 | showSidebar: false, 8 | wordWrap: false, 9 | runInBrowser: false 10 | }; 11 | 12 | module.exports.load = function() { 13 | if (typeof nodeGlobal.userSettings === 'object') { 14 | return nodeGlobal.userSettings; 15 | } 16 | 17 | var settings = localStorage.userSettings; 18 | if (!settings) { 19 | settings = defaults; 20 | } else { 21 | try { 22 | settings = JSON.parse(settings); 23 | } catch(err) { 24 | settings = defaults; 25 | } 26 | } 27 | 28 | nodeGlobal.userSettings = settings; 29 | 30 | return settings; 31 | }; 32 | 33 | module.exports.save = function(settings) { 34 | nodeGlobal.userSettings = settings; 35 | localStorage.userSettings = JSON.stringify(nodeGlobal.userSettings); 36 | }; 37 | 38 | module.exports.write = function() { 39 | localStorage.userSettings = JSON.stringify(nodeGlobal.userSettings); 40 | }; 41 | 42 | module.exports.defaults = defaults; 43 | -------------------------------------------------------------------------------- /app/settings/index.js: -------------------------------------------------------------------------------- 1 | var $ = require('jquery'); 2 | module.exports = { 3 | template: require('./template.html'), 4 | 5 | data: { 6 | tabSizeDisplay: 1 7 | }, 8 | 9 | ready: function() { 10 | if (parseInt(this.tabSize) < 1) { 11 | this.tabSize = 1; 12 | } 13 | this.tabSizeDisplay = this.tabSize; 14 | }, 15 | 16 | methods: { 17 | updateTabSize: function(e) { 18 | var parsed = typeof e === 'number' ? e : parseInt(e.target.value); 19 | this.tabSize = parsed >= 1 ? parsed : 1; 20 | this.tabSizeDisplay = this.tabSize; 21 | }, 22 | decreaseTabSize: function(e) { 23 | this.updateTabSize(this.tabSize-1); 24 | }, 25 | increaseTabSize: function(e) { 26 | this.updateTabSize(this.tabSize+1); 27 | }, 28 | decreaseFontSize: function(e) { 29 | this.fontSize--; 30 | }, 31 | increaseFontSize: function(e) { 32 | this.fontSize++; 33 | }, 34 | showSidebarOn: function() { 35 | $('#showSidebarOn + label').addClass('labelSelected'); 36 | $('#showSidebarOff + label').removeClass('labelSelected'); 37 | $('#showSidebarOn').prop('checked', true); 38 | $('#showSidebarOff + label').click(function(){ 39 | $('#showSidebarOn + label').removeClass('labelSelected'); 40 | }); 41 | }, 42 | showSidebarOff: function() { 43 | $('#showSidebarOff + label').addClass('labelSelected'); 44 | $('#showSidebarOn + label').removeClass('labelSelected'); 45 | $('#showSidebarOff').prop('checked', true); 46 | $('#showSidebarOn + label').click(function(){ 47 | $('#showSidebarOff + label').removeClass('labelSelected'); 48 | }); 49 | } 50 | } 51 | 52 | }; 53 | -------------------------------------------------------------------------------- /app/sidebar/file.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | {{name}} 4 |
5 | -------------------------------------------------------------------------------- /app/sidebar/folder.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | {{name}} 4 |
5 | 8 | -------------------------------------------------------------------------------- /app/sidebar/sidebar.html: -------------------------------------------------------------------------------- 1 | 11 | -------------------------------------------------------------------------------- /app/tabs/index.js: -------------------------------------------------------------------------------- 1 | var Path = nodeRequire('path'); 2 | var fs = nodeRequire('fs'); 3 | var trash = nodeRequire('trash'); 4 | 5 | var File = require('./../files'); 6 | var _ = require('underscore'); 7 | var $ = require('jquery'); 8 | 9 | module.exports = { 10 | template: require('./template.html'), 11 | 12 | components: { 13 | tab: { 14 | template: require('./tab.html'), 15 | computed: { 16 | hidden: function() { 17 | return this.name[0] === '.' 18 | }, 19 | className: function() { 20 | var c = ''; 21 | if (this.$root.currentFile == this.file) c += 'selected'; 22 | return c; 23 | } 24 | }, 25 | 26 | methods: { 27 | 28 | } 29 | } 30 | }, 31 | 32 | methods: { 33 | closeFile: function(fileObject) { 34 | var tabs = this.$root.tabs; 35 | var target_tabs = tabs.filter(function(tab) { 36 | return tab.name === fileObject.name; 37 | }); 38 | if (target_tabs[0]) { 39 | var newTarget; 40 | var index = _.indexOf(tabs, target_tabs[0]); 41 | 42 | switch (index) { 43 | case 0: 44 | newTarget = 0; 45 | break; 46 | case tabs.length - 1: 47 | newTarget = tabs.length - 2; 48 | break; 49 | default: 50 | newTarget = index - 1; 51 | break; 52 | } 53 | tabs.splice(index, 1); 54 | this.$root.openFile(tabs[newTarget].path); 55 | } 56 | }, 57 | 58 | addTab: function(fileObject, tabs) { 59 | if (fileObject.open) { 60 | var tabObject = { 61 | name: fileObject.name, 62 | path: fileObject.path, 63 | id: fileObject.path, 64 | type: 'file', 65 | open: true, 66 | file: fileObject 67 | }; 68 | 69 | tabs.push(tabObject); 70 | } 71 | }, 72 | }, 73 | 74 | ready: function() { 75 | this.$on('add-tab', this.addTab); 76 | this.$on('close-file', this.closeFile); 77 | 78 | 79 | }, 80 | }; -------------------------------------------------------------------------------- /app/tabs/style.scss: -------------------------------------------------------------------------------- 1 | 2 | #tab-container { 3 | font-size: 12px; 4 | display: flex; 5 | flex: 1; 6 | flex-direction: column; 7 | max-height: 30px; 8 | -webkit-touch-callout: none; 9 | -webkit-user-select: none; 10 | } 11 | 12 | #toolbar { 13 | height: 60px; 14 | width: 100%; 15 | } 16 | 17 | #actions { 18 | 19 | #add, #export { 20 | float: left; 21 | } 22 | 23 | #settings { 24 | float: right; 25 | margin-right: 15px; 26 | } 27 | } 28 | 29 | #tabs { 30 | margin-left: 53px; 31 | 32 | 33 | ul { 34 | list-style: none; 35 | padding:0; 36 | margin:0; 37 | white-space: nowrap; 38 | } 39 | 40 | li { 41 | margin: 0 0 0 0; 42 | display: inline-block; 43 | } 44 | 45 | div { 46 | display: inline-block; 47 | height: 30px; 48 | background-color: rgba(153, 153, 153, 0.1); 49 | width: 128px; 50 | text-align: center; 51 | } 52 | 53 | div.selected{ 54 | background-color: rgba(153, 153, 153, 0.4); 55 | } 56 | 57 | li div { 58 | border-right: 1px solid rgba(153, 153, 153, 0.3); 59 | } 60 | 61 | li:first-child div { 62 | border-top-left-radius: 8px; 63 | } 64 | 65 | li:nth-last-child(2) div { 66 | border-top-right-radius: 8px; 67 | border-right: none; 68 | } 69 | 70 | li:nth-last-child(1) div { 71 | border-right: none; 72 | } 73 | 74 | a{ 75 | display: inline-block; 76 | text-decoration: none; 77 | line-height: 2.4; 78 | text-align: center; 79 | color: #b5b5b5; 80 | outline: none; 81 | } 82 | a.delete{ 83 | color: #aaa; 84 | float: right; 85 | padding-right: 18px; 86 | background: url('../images/close-button.svg'); 87 | background-repeat: no-repeat; 88 | margin-top: 10px; 89 | height: 10px; 90 | } 91 | .selected a{ 92 | color: #333333; 93 | } 94 | a.delete:hover { 95 | opacity: 0.5; 96 | } 97 | } 98 | 99 | #add { 100 | 101 | div { 102 | width: 30px !important; 103 | background-color: #fbfbfb;; 104 | } 105 | a { 106 | width: 100%; 107 | display:block; 108 | color: #333333; 109 | } 110 | a:hover { 111 | opacity: 0.5; 112 | } 113 | } 114 | 115 | -------------------------------------------------------------------------------- /app/tabs/tab.html: -------------------------------------------------------------------------------- 1 |
{{name}}{{file.contents !== file.lastSavedContents ? '*' : ''}}  2 | 3 |
4 | 5 | 6 | -------------------------------------------------------------------------------- /app/tabs/template.html: -------------------------------------------------------------------------------- 1 |
2 | 10 | 11 |
-------------------------------------------------------------------------------- /app/updater.js: -------------------------------------------------------------------------------- 1 | var $ = require('jquery'); 2 | var manifest = nodeRequire('./package.json'); 3 | var semver = nodeRequire('semver'); 4 | var packageURL = 'https://raw.githubusercontent.com/processing/p5.js-editor/master/package.json?v=' + new Date().getTime(); 5 | var downloadURL = 'https://github.com/processing/p5.js-editor/releases/download/'; 6 | 7 | module.exports.check = function() { 8 | if (nodeGlobal.checkedUpdate === true) return false; 9 | nodeGlobal.checkedUpdate = true; 10 | $.ajax({url: packageURL, success: update, cache: false, dataType: 'json'}); 11 | function update(data) { 12 | if (semver.gt(data.version, manifest.version)) { 13 | var shouldDownload = confirm('A newer version of P5 is available. Do you want to download it?'); 14 | if (shouldDownload) { 15 | gui.Shell.openExternal(downloadURL + 'v' + data.version + '/p5-' + (isWin ? 'win' : 'mac') + '.zip'); 16 | } 17 | } 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /app/windowstate.js: -------------------------------------------------------------------------------- 1 | var fs = nodeRequire('fs'); 2 | 3 | module.exports.load = function(callback) { 4 | var windows = localStorage.windows ? JSON.parse(localStorage.windows) : []; 5 | localStorage.windows = JSON.stringify([]); 6 | 7 | var windowsToOpen = windows.filter(function(w){ 8 | return w.path && fs.existsSync(w.path); 9 | }); 10 | 11 | if (windowsToOpen.length > 0) { 12 | var openedWindows = 0; 13 | windowsToOpen.forEach(function(w){ 14 | var win = gui.Window.open('index.html',{ 15 | x: w.x, 16 | y: w.y, 17 | width: w.width, 18 | height: w.height-55, 19 | toolbar: false, 20 | focus: true, 21 | show: false 22 | }); 23 | win.on('document-start', function(){ 24 | win.window.PATH = w.path; 25 | win.window.FILEPATH = w.filePath; 26 | win.window.UNSAVED = w.temp; 27 | openedWindows ++; 28 | if (openedWindows === windows.length) { 29 | callback(false); 30 | } 31 | }); 32 | }); 33 | 34 | } else { 35 | callback(true); 36 | } 37 | }; 38 | 39 | module.exports.save = function(app, win) { 40 | var state = { 41 | x: win.x, 42 | y: win.y, 43 | width: win.width, 44 | height: win.height, 45 | temp: app.temp, 46 | path: app.projectPath, 47 | filePath: app.currentFile && app.currentFile.path ? app.currentFile.path : null 48 | }; 49 | var windows = JSON.parse(localStorage.windows); 50 | windows.push(state); 51 | localStorage.windows = JSON.stringify(windows); 52 | }; 53 | 54 | 55 | 56 | module.exports.totalWindows = function() { 57 | if (!localStorage.openWindows) localStorage.openWindows = 0; 58 | return +localStorage.openWindows; 59 | }; 60 | 61 | 62 | module.exports.incrementWindows = function() { 63 | if (!localStorage.openWindows || +localStorage.openWindows < 0) localStorage.openWindows = 0; 64 | localStorage.openWindows ++; 65 | }; 66 | 67 | module.exports.decrementWindows = function() { 68 | if (!localStorage.openWindows || +localStorage.openWindows < 1) localStorage.openWindows = 1; 69 | localStorage.openWindows --; 70 | }; 71 | -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 | # This editor has been deprecated, we will not be making further releases. We are turning our energy toward a web editor which will be released sometime next year. For now, we recommend using editors like [Brackets](http://brackets.io), [Atom](https://atom.io/), [Sublime Text](https://www.sublimetext.com/3), or [OpenProcessing](https://www.openprocessing.org/). 2 | 3 | -------------------------------------------------------------------------------- /icons/p5js.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/icons/p5js.icns -------------------------------------------------------------------------------- /icons/p5js.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/icons/p5js.ico -------------------------------------------------------------------------------- /lib/ffmpegsumo.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/lib/ffmpegsumo.dll -------------------------------------------------------------------------------- /lib/ffmpegsumo.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/lib/ffmpegsumo.so -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "Sam Lavigne", 3 | "name": "p5", 4 | "description": "Javascript IDE for beginners", 5 | "version": "0.6.2", 6 | "devDependencies": { 7 | "autolinker": "^0.17.1", 8 | "br-mousetrap": "~1.1.3", 9 | "brace": "git+https://gigit@github.com/antiboredom/brace.git", 10 | "browserify": "^3.33.1", 11 | "express": "^4.12.3", 12 | "github-release": "~0.1.0", 13 | "gulp": "^3.8.11", 14 | "gulp-browserify": "~0.5.0", 15 | "gulp-concat": "^2.2.0", 16 | "gulp-download": "0.0.1", 17 | "gulp-notify": "~1.4.0", 18 | "gulp-plumber": "~0.6.3", 19 | "gulp-rename": "^1.2.0", 20 | "gulp-sass": "^2.2.0", 21 | "gulp-zip": "~0.4.0", 22 | "jquery": "~2.1.1", 23 | "js-beautify": "~1.5.1", 24 | "nw": "0.12.3", 25 | "nw-builder": "^2.0.2", 26 | "partialify": "^3.1.1", 27 | "request": "^2.56.0", 28 | "underscore": "~1.6.0", 29 | "vue": "^0.10.3", 30 | "unzip": "^0.1.11" 31 | }, 32 | "scripts": { 33 | "app": "nw public" 34 | }, 35 | "repository": { 36 | "type": "git", 37 | "url": "git://github.com/antiboredom/jside.git" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /public/boot.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 75 | 76 | -------------------------------------------------------------------------------- /public/fonts/Inconsolata.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/fonts/Inconsolata.otf -------------------------------------------------------------------------------- /public/fonts/Montserrat-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/fonts/Montserrat-Bold.ttf -------------------------------------------------------------------------------- /public/fonts/Montserrat-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/fonts/Montserrat-Regular.ttf -------------------------------------------------------------------------------- /public/fonts/icons.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/fonts/icons.otf -------------------------------------------------------------------------------- /public/images/browser.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/images/close-button.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /public/images/collapsed.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /public/images/consoleH.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /public/images/consoleV.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /public/images/expanded.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /public/images/folder.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /public/images/image.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /public/images/library.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /public/images/minus-button.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /public/images/p5-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/images/p5-logo.png -------------------------------------------------------------------------------- /public/images/package.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /public/images/play-button-flip.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /public/images/play-button.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /public/images/plus-button.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /public/images/plus.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /public/images/settings-button-flip.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /public/images/settings-button.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /public/images/sidebar.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /public/images/stop-button-flip.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /public/images/stop-button.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /public/images/stop-gray.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 12 | 17 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /public/images/stop-red.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 14 | 19 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /public/images/textAdjust.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 14 | 15 | 16 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /public/images/upload.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /public/images/wordWrap.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {{title}} {{currentFile.contents !== currentFile.lastSavedContents ? '*' : ''}} 6 | 7 | 8 | 9 |
10 | 11 | 12 |

13 |
14 |
15 | 16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | 30 |
31 | 32 | 33 | 34 | 35 | 36 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /public/mode_assets/p5/empty_project/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Untitled 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /public/mode_assets/p5/empty_project/sketch.js: -------------------------------------------------------------------------------- 1 | function setup() { 2 | 3 | } 4 | 5 | function draw() { 6 | 7 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/360video_256crop_v2.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/360video_256crop_v2.mp4 -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/Damscray_-_Dancing_Tiger_01.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/Damscray_-_Dancing_Tiger_01.mp3 -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/Damscray_-_Dancing_Tiger_01.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/Damscray_-_Dancing_Tiger_01.ogg -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/Damscray_-_Dancing_Tiger_02.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/Damscray_-_Dancing_Tiger_02.mp3 -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/Damscray_-_Dancing_Tiger_02.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/Damscray_-_Dancing_Tiger_02.ogg -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/Damscray_DancingTiger.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/Damscray_DancingTiger.mp3 -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/Damscray_DancingTiger.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/Damscray_DancingTiger.ogg -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/LeagueGothic-Regular.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/LeagueGothic-Regular.otf -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/beat.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/beat.mp3 -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/beat.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/beat.ogg -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/beatbox.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/beatbox.mp3 -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/beatbox.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/beatbox.ogg -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/bx-spring.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/bx-spring.mp3 -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/bx-spring.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/bx-spring.ogg -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/cat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/cat.jpg -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/concrete-tunnel.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/concrete-tunnel.mp3 -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/concrete-tunnel.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/concrete-tunnel.ogg -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/doorbell.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/doorbell.mp3 -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/doorbell.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/doorbell.ogg -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/drum.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/drum.mp3 -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/drum.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/drum.ogg -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/fingers.mov: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/fingers.mov -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/fingers.webm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/fingers.webm -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/large-dark-plate.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/large-dark-plate.mp3 -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/large-dark-plate.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/large-dark-plate.ogg -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/lucky_dragons_-_power_melody.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/lucky_dragons_-_power_melody.mp3 -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/lucky_dragons_-_power_melody.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/lucky_dragons_-_power_melody.ogg -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/mask.png -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/moonwalk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/moonwalk.jpg -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/particle_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/particle_texture.png -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/small-plate.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/small-plate.mp3 -------------------------------------------------------------------------------- /public/mode_assets/p5/example_assets/small-plate.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/processing/p5.js-editor/9b98c9f603a7d12aac1331b024b86d6ec6216027/public/mode_assets/p5/example_assets/small-plate.ogg -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/3D/00_geometries.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Geometries 3 | * @description There are six 3D primitives in p5 now. 4 | */ 5 | function setup(){ 6 | createCanvas(710, 400, WEBGL); 7 | } 8 | 9 | function draw(){ 10 | background(250); 11 | translate(-250 * 2.5, 0, 0); 12 | normalMaterial(); 13 | push(); 14 | rotateZ(frameCount * 0.01); 15 | rotateX(frameCount * 0.01); 16 | rotateY(frameCount * 0.01); 17 | plane(80); 18 | pop(); 19 | translate(250, 0, 0); 20 | push(); 21 | rotateZ(frameCount * 0.01); 22 | rotateX(frameCount * 0.01); 23 | rotateY(frameCount * 0.01); 24 | box(80, 80, 80); 25 | pop(); 26 | translate(250, 0, 0); 27 | push(); 28 | rotateZ(frameCount * 0.01); 29 | rotateX(frameCount * 0.01); 30 | rotateY(frameCount * 0.01); 31 | cylinder(80, 80); 32 | pop(); 33 | translate(250, 0, 0); 34 | push(); 35 | rotateZ(frameCount * 0.01); 36 | rotateX(frameCount * 0.01); 37 | rotateY(frameCount * 0.01); 38 | cone(80, 80); 39 | pop(); 40 | translate(250, 0, 0); 41 | push(); 42 | rotateZ(frameCount * 0.01); 43 | rotateX(frameCount * 0.01); 44 | rotateY(frameCount * 0.01); 45 | torus(80, 20); 46 | pop(); 47 | translate(250, 0, 0); 48 | push(); 49 | rotateZ(frameCount * 0.01); 50 | rotateX(frameCount * 0.01); 51 | rotateY(frameCount * 0.01); 52 | sphere(80); 53 | pop(); 54 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/3D/01_sine_cosine_in_3D.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Sine Cosine in 3D 3 | * @description Sine, cosine and push / pop could be applied in 3D as well. 4 | */ 5 | function setup(){ 6 | createCanvas(710, 400, WEBGL); 7 | } 8 | 9 | function draw(){ 10 | background(250); 11 | rotateY(frameCount * 0.01); 12 | 13 | for(var j = 0; j < 5; j++){ 14 | push(); 15 | for(var i = 0; i < 80; i++){ 16 | translate(sin(frameCount * 0.001 + j) * 100, sin(frameCount * 0.001 + j) * 100, i * 0.1); 17 | rotateZ(frameCount * 0.002); 18 | push(); 19 | sphere(8, 6, 4); 20 | pop(); 21 | } 22 | pop(); 23 | } 24 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/3D/02_multiple_lights.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Multiple Lights 3 | * @description All types of lights could be used in one sketch. 4 | */ 5 | function setup(){ 6 | createCanvas(710, 400, WEBGL); 7 | } 8 | 9 | function draw(){ 10 | background(0); 11 | 12 | var locY = (mouseY / height - 0.5) * (-2); 13 | var locX = (mouseX / width - 0.5) * 2; 14 | 15 | ambientLight(50); 16 | directionalLight(200, 0, 0, 0.25, 0.25, 0.25); 17 | pointLight(0, 0, 200, locX, locY, 0); 18 | pointLight(200, 200, 0, -locX, -locY, 0); 19 | 20 | push(); 21 | translate(-250, 0, 0); 22 | rotateZ(frameCount * 0.02); 23 | rotateX(frameCount * 0.02); 24 | specularMaterial(250); 25 | box(100, 100, 100); 26 | pop(); 27 | 28 | translate(250, 0, 0); 29 | ambientMaterial(250); 30 | sphere(120, 64); 31 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/3D/03_materials.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Materials 3 | * @description There are five types of materials supported. 4 | * They respond to light differently. 5 | * Move your mouse to change the light position. 6 | */ 7 | var img; 8 | function setup(){ 9 | createCanvas(710, 400, WEBGL); 10 | img = loadImage("assets/cat.jpg"); 11 | } 12 | 13 | function draw(){ 14 | background(0); 15 | 16 | var locY = (mouseY / height - 0.5) * (-2); 17 | var locX = (mouseX / width - 0.5) * 2; 18 | 19 | ambientLight(100, 80, 80); 20 | pointLight(200, 200, 200, locX, locY, 0); 21 | 22 | push(); 23 | rotateZ(frameCount * 0.02); 24 | rotateX(frameCount * 0.02); 25 | rotateY(frameCount * 0.02); 26 | texture(img); 27 | box(80); 28 | pop(); 29 | 30 | translate(-200, -250, 0); 31 | push(); 32 | rotateZ(frameCount * 0.02); 33 | rotateX(frameCount * 0.02); 34 | rotateY(frameCount * 0.02); 35 | basicMaterial(250, 0, 0); 36 | torus(80, 20, 64, 64); 37 | pop(); 38 | 39 | translate(400, 0, 0); 40 | push(); 41 | rotateZ(frameCount * 0.02); 42 | rotateX(frameCount * 0.02); 43 | rotateY(frameCount * 0.02); 44 | normalMaterial(); 45 | torus(80, 20, 64, 64); 46 | pop(); 47 | 48 | translate(-400, 500, 0); 49 | push(); 50 | rotateZ(frameCount * 0.02); 51 | rotateX(frameCount * 0.02); 52 | rotateY(frameCount * 0.02); 53 | ambientMaterial(250); 54 | torus(80, 20, 64, 64); 55 | pop(); 56 | 57 | translate(400, 0, 0); 58 | push(); 59 | specularMaterial(250); 60 | rotateZ(frameCount * 0.02); 61 | rotateX(frameCount * 0.02); 62 | rotateY(frameCount * 0.02); 63 | torus(80, 20, 64, 64); 64 | pop(); 65 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/3D/04_textures.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Textures 3 | * @description Images and videos are supported for texture. 4 | */ 5 | // video source: https://vimeo.com/90312869 6 | var img; 7 | var vid; 8 | var theta = 0; 9 | 10 | function setup(){ 11 | createCanvas(710, 400, WEBGL); 12 | 13 | img = loadImage("assets/cat.jpg"); 14 | vid = createVideo(["assets/360video_256crop_v2.mp4"]); 15 | vid.loop(); 16 | vid.hide(); 17 | } 18 | 19 | function draw(){ 20 | background(250); 21 | translate(-220,0,0); 22 | push(); 23 | rotateZ(theta * mouseX * 0.001); 24 | rotateX(theta * mouseX * 0.001); 25 | rotateY(theta * mouseX * 0.001); 26 | //pass image as texture 27 | texture(vid); 28 | sphere(150); 29 | pop(); 30 | translate(440,0,0); 31 | push(); 32 | rotateZ(theta * 0.1); 33 | rotateX(theta * 0.1); 34 | rotateY(theta * 0.1); 35 | texture(img); 36 | box(100, 100, 100); 37 | pop(); 38 | theta += 0.05; 39 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/3D/07_orbit_control.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Orbit Control 3 | * @description Orbit control allows you to drag and move around the world. 4 | */ 5 | function setup(){ 6 | createCanvas(710, 400, WEBGL); 7 | } 8 | 9 | function draw(){ 10 | background(250); 11 | var radius = width * 1.5; 12 | 13 | //drag to move the world. 14 | orbitControl(); 15 | 16 | normalMaterial(); 17 | translate(0, 0, -600); 18 | for(var i = 0; i <= 12; i++){ 19 | for(var j = 0; j <= 12; j++){ 20 | push(); 21 | var a = j/12 * PI; 22 | var b = i/12 * PI; 23 | translate(sin(2 * a) * radius * sin(b), cos(b) * radius / 2 , cos(2 * a) * radius * sin(b)); 24 | if(j%2 === 0){ 25 | cone(30, 30); 26 | }else{ 27 | box(30, 30, 30); 28 | } 29 | pop(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Arrays/00_Array.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Array 3 | * @description An array is a list of data. Each piece of data in an array 4 | * is identified by an index number representing its position in 5 | * the array. Arrays are zero based, which means that the first 6 | * element in the array is [0], the second element is [1], and so on. 7 | * In this example, an array named "coswav" is created and 8 | * filled with the cosine values. This data is displayed three 9 | * separate ways on the screen. 10 | */ 11 | var coswave = []; 12 | 13 | function setup() { 14 | 15 | createCanvas(720, 360); 16 | for (var i = 0; i < width; i++) { 17 | var amount = map(i, 0, width, 0, PI); 18 | coswave[i] = abs(cos(amount)); 19 | } 20 | background(255); 21 | noLoop(); 22 | } 23 | 24 | function draw() { 25 | var y1 = 0; 26 | var y2 = height/3; 27 | for (var i = 0; i < width; i+=3) { 28 | stroke(coswave[i]*255); 29 | line(i, y1, i, y2); 30 | } 31 | 32 | y1 = y2; 33 | y2 = y1 + y1; 34 | for (var i = 0; i < width; i+=3) { 35 | stroke(coswave[i]*255 / 4); 36 | line(i, y1, i, y2); 37 | } 38 | 39 | y1 = y2; 40 | y2 = height; 41 | for (var i = 0; i < width; i+=3) { 42 | stroke(255 - coswave[i]*255); 43 | line(i, y1, i, y2); 44 | } 45 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Arrays/01_Array_2d.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Array 2D 3 | * @description Demonstrates the syntax for creating a two-dimensional (2D) 4 | * array. Values in a 2D array are accessed through two index values. 5 | * 2D arrays are useful for storing images. In this example, each dot 6 | * is colored in relation to its distance from the center of the image. 7 | */ 8 | var distances = []; 9 | var maxDistance; 10 | var spacer; 11 | 12 | function setup() { 13 | createCanvas(720, 360); 14 | maxDistance = dist(width/2, height/2, width, height); 15 | for (var x = 0; x < width; x++) { 16 | distances[x] = []; // create nested array 17 | for (var y = 0; y < height; y++) { 18 | var distance = dist(width/2, height/2, x, y); 19 | distances[x][y] = distance/maxDistance * 255; 20 | } 21 | } 22 | spacer = 10; 23 | noLoop(); // Run once and stop 24 | } 25 | 26 | function draw() { 27 | background(0); 28 | // This embedded loop skips over values in the arrays based on 29 | // the spacer variable, so there are more values in the array 30 | // than are drawn here. Change the value of the spacer variable 31 | // to change the density of the points 32 | for (var x = 0; x < width; x += spacer) { 33 | for (var y = 0; y < height; y += spacer) { 34 | stroke(distances[x][y]); 35 | point(x + spacer/2, y + spacer/2); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Arrays/02_Array_Objects.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Array Objects 3 | * @description Demonstrates the syntax for creating an array of custom objects. 4 | */ 5 | var unit = 40; 6 | var count; 7 | var mods = []; 8 | 9 | function setup() { 10 | createCanvas(720, 360); 11 | noStroke(); 12 | var wideCount = width / unit; 13 | var highCount = height / unit; 14 | count = wideCount * highCount; 15 | 16 | var index = 0; 17 | for (var y = 0; y < highCount; y++) { 18 | for (var x = 0; x < wideCount; x++) { 19 | mods[index++] = new Module(x*unit, y*unit, unit/2, unit/2, 20 | random(0.05, 0.8), unit); 21 | } 22 | } 23 | } 24 | 25 | function draw() { 26 | background(0); 27 | for (var i = 0; i < count; i++) { 28 | mods[i].update(); 29 | mods[i].draw(); 30 | } 31 | } 32 | 33 | 34 | function Module(_xOff, _yOff, _x, _y, _speed, _unit) { 35 | this.xOff = _xOff; 36 | this.yOff = _yOff; 37 | this.x = _x; 38 | this.y = _y; 39 | this.speed = _speed; 40 | this.unit = _unit; 41 | this.xDir = 1; 42 | this.yDir = 1; 43 | } 44 | 45 | // Custom method for updating the variables 46 | Module.prototype.update = function() { 47 | this.x = this.x + (this.speed * this.xDir); 48 | if (this.x >= this.unit || this.x <= 0) { 49 | this.xDir *= -1; 50 | this.x = this.x + (1 * this.xDir); 51 | this.y = this.y + (1 * this.yDir); 52 | } 53 | if (this.y >= this.unit || this.y <= 0) { 54 | this.yDir *= -1; 55 | this.y = this.y + (1 * this.yDir); 56 | } 57 | } 58 | 59 | // Custom method for drawing the object 60 | Module.prototype.draw = function() { 61 | fill(255); 62 | ellipse(this.xOff + this.x, this.yOff + this.y, 6, 6); 63 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Color/00_Hue.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Hue 3 | * @description Hue is the color reflected from or transmitted through an 4 | * object and is typically referred to as the name of the color (red, blue, 5 | * yellow, etc.) Move the cursor vertically over each bar to alter its hue. 6 | */ 7 | var barWidth = 20; 8 | var lastBar = -1; 9 | 10 | function setup() { 11 | createCanvas(720, 400); 12 | colorMode(HSB, height, height, height); 13 | noStroke(); 14 | background(0); 15 | } 16 | 17 | function draw() { 18 | var whichBar = mouseX / barWidth; 19 | if (whichBar !== lastBar) { 20 | var barX = whichBar * barWidth; 21 | fill(mouseY, height, height); 22 | rect(barX, 0, barWidth, height); 23 | lastBar = whichBar; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Color/01_Saturation.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Saturation 3 | * @description Saturation is the strength or purity of the color and 4 | * represents the amount of gray in proportion to the hue. A "saturated" 5 | * color is pure and an "unsaturated" color has a large percentage of gray. 6 | * Move the cursor vertically over each bar to alter its saturation. 7 | */ 8 | var barWidth = 20; 9 | var lastBar = -1; 10 | 11 | function setup() { 12 | createCanvas(720, 400); 13 | colorMode(HSB, width, height, 100); 14 | noStroke(); 15 | } 16 | 17 | function draw() { 18 | var whichBar = mouseX / barWidth; 19 | if (whichBar != lastBar) { 20 | var barX = whichBar * barWidth; 21 | fill(barX, mouseY, 66); 22 | rect(barX, 0, barWidth, height); 23 | lastBar = whichBar; 24 | } 25 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Color/02_Brightness.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Brightness 3 | * @description By Dan Shiffman. This program adjusts the brightness of a part 4 | * of the image by calculating the distance of each pixel to the mouse. 5 | *

To run this example locally, you will need 6 | * at least an image file and a running local server.

7 | */ 8 | var img; 9 | 10 | function preload() { 11 | img = loadImage("assets/moonwalk.jpg"); 12 | } 13 | 14 | function setup() { 15 | createCanvas(720, 200); 16 | pixelDensity(1); 17 | img.loadPixels(); 18 | loadPixels(); 19 | } 20 | 21 | function draw() { 22 | for (var x = 0; x < img.width; x++) { 23 | for (var y = 0; y < img.height; y++ ) { 24 | // Calculate the 1D location from a 2D grid 25 | var loc = (x + y*img.width)*4; 26 | // Get the R,G,B values from image 27 | var r,g,b; 28 | r = img.pixels[loc]; 29 | // Calculate an amount to change brightness based on proximity to the mouse 30 | var maxdist = 50; 31 | var d = dist(x, y, mouseX, mouseY); 32 | var adjustbrightness = 255*(maxdist-d)/maxdist; 33 | r += adjustbrightness; 34 | // Constrain RGB to make sure they are within 0-255 color range 35 | r = constrain(r, 0, 255); 36 | // Make a new color and set pixel in the window 37 | //color c = color(r, g, b); 38 | var pixloc = (y*width + x)*4; 39 | pixels[pixloc] = r; 40 | pixels[pixloc+1] = r; 41 | pixels[pixloc+2] = r; 42 | pixels[pixloc+3] = 255; 43 | } 44 | } 45 | updatePixels(); 46 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Color/03_Color_Variables.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Color Variables 3 | * @description (Homage to Albers.) This example creates variables for colors 4 | * that may be referred to in the program by a name, rather than a number. 5 | */ 6 | function setup() { 7 | createCanvas(710, 400); 8 | noStroke(); 9 | background(51, 0, 0); 10 | 11 | var inside = color(204, 102, 0); 12 | var middle = color(204, 153, 0); 13 | var outside = color(153, 51, 0); 14 | 15 | // These statements are equivalent to the statements above. 16 | // Programmers may use the format they prefer. 17 | //color inside = #CC6600; 18 | //color middle = #CC9900; 19 | //color outside = #993300; 20 | 21 | push(); 22 | translate(80, 80); 23 | fill(outside); 24 | rect(0, 0, 200, 200); 25 | fill(middle); 26 | rect(40, 60, 120, 120); 27 | fill(inside); 28 | rect(60, 90, 80, 80); 29 | pop(); 30 | 31 | push(); 32 | translate(360, 80); 33 | fill(inside); 34 | rect(0, 0, 200, 200); 35 | fill(outside); 36 | rect(40, 60, 120, 120); 37 | fill(middle); 38 | rect(60, 90, 80, 80); 39 | pop(); 40 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Color/04_Relativity.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Relativity 3 | * @description Each color is perceived in relation to other colors. The top 4 | * and bottom bars each contain the same component colors, but a different 5 | * display order causes individual colors to appear differently. 6 | */ 7 | var a, b, c, d, e; 8 | 9 | function setup() { 10 | createCanvas(710, 400); 11 | noStroke(); 12 | a = color(165, 167, 20); 13 | b = color(77, 86, 59); 14 | c = color(42, 106, 105); 15 | d = color(165, 89, 20); 16 | e = color(146, 150, 127); 17 | noLoop(); // Draw only one time 18 | } 19 | 20 | function draw() { 21 | drawBand(a, b, c, d, e, 0, width/128); 22 | drawBand(c, a, d, b, e, height/2, width/128); 23 | } 24 | 25 | function drawBand(v, w, x, y, z, ypos, barWidth) { 26 | var num = 5; 27 | var colorOrder = [ v, w, x, y, z ]; 28 | for(var i = 0; i < width; i += barWidth*num) { 29 | for(var j = 0; j < num; j++) { 30 | fill(colorOrder[j]); 31 | rect(i+j*barWidth, ypos, barWidth, height/2); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Color/05_Linear_Gradient.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Linear Gradient 3 | * @description The lerpColor() function is useful for interpolating between 4 | * two colors. 5 | */ 6 | // Constants 7 | var Y_AXIS = 1; 8 | var X_AXIS = 2; 9 | var b1, b2, c1, c2; 10 | 11 | function setup() { 12 | createCanvas(710, 400); 13 | 14 | // Define colors 15 | b1 = color(255); 16 | b2 = color(0); 17 | c1 = color(204, 102, 0); 18 | c2 = color(0, 102, 153); 19 | 20 | noLoop(); 21 | } 22 | 23 | function draw() { 24 | // Background 25 | setGradient(0, 0, width/2, height, b1, b2, X_AXIS); 26 | setGradient(width/2, 0, width/2, height, b2, b1, X_AXIS); 27 | // Foreground 28 | setGradient(50, 90, 540, 80, c1, c2, Y_AXIS); 29 | setGradient(50, 190, 540, 80, c2, c1, X_AXIS); 30 | } 31 | 32 | function setGradient(x, y, w, h, c1, c2, axis) { 33 | 34 | noFill(); 35 | 36 | if (axis == Y_AXIS) { // Top to bottom gradient 37 | for (var i = y; i <= y+h; i++) { 38 | var inter = map(i, y, y+h, 0, 1); 39 | var c = lerpColor(c1, c2, inter); 40 | stroke(c); 41 | line(x, i, x+w, i); 42 | } 43 | } 44 | else if (axis == X_AXIS) { // Left to right gradient 45 | for (var i = x; i <= x+w; i++) { 46 | var inter = map(i, x, x+w, 0, 1); 47 | var c = lerpColor(c1, c2, inter); 48 | stroke(c); 49 | line(i, y, i, y+h); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Color/06_Radial_Gradient.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Radial Gradient 3 | * @description Draws a series of concentric circles to create a gradient 4 | * from one color to another. 5 | */ 6 | var dim; 7 | 8 | function setup() { 9 | createCanvas(710, 400); 10 | dim = width/2; 11 | background(0); 12 | colorMode(HSB, 360, 100, 100); 13 | noStroke(); 14 | ellipseMode(RADIUS); 15 | frameRate(1); 16 | } 17 | 18 | function draw() { 19 | background(0); 20 | for (var x = 0; x <= width; x+=dim) { 21 | drawGradient(x, height/2); 22 | } 23 | } 24 | 25 | function drawGradient(x, y) { 26 | var radius = dim/2; 27 | var h = random(0, 360); 28 | for (var r = radius; r > 0; --r) { 29 | fill(h, 90, 90); 30 | ellipse(x, y, r, r); 31 | h = (h + 1) % 360; 32 | } 33 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Color/07_Lerp_Color.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Lerp Color 3 | * @description Loop random shapes, 4 | * lerp color from red to blue. 5 | */ 6 | function setup() { 7 | createCanvas(720, 400); 8 | background(255); 9 | noStroke(); 10 | } 11 | 12 | function draw() { 13 | background(255); 14 | from = color(255, 0, 0, 0.2 * 255); 15 | to = color(0, 0, 255, 0.2 * 255); 16 | c1 = lerpColor(from, to, .33); 17 | c2 = lerpColor(from, to, .66); 18 | for (var i = 0; i < 15; i++) { 19 | fill(from); 20 | quad(random(-40, 220), random(height), 21 | random(-40, 220), random(height), 22 | random(-40, 220), random(height), 23 | random(-40, 220), random(height)); 24 | fill(c1); 25 | quad(random(140, 380), random(height), 26 | random(140, 380), random(height), 27 | random(140, 380), random(height), 28 | random(140, 380), random(height)); 29 | fill(c2); 30 | quad(random(320, 580), random(height), 31 | random(320, 580), random(height), 32 | random(320, 580), random(height), 33 | random(320, 580), random(height)); 34 | fill(to); 35 | quad(random(500, 760), random(height), 36 | random(500, 760), random(height), 37 | random(500, 760), random(height), 38 | random(500, 760), random(height)); 39 | } 40 | frameRate(5); 41 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Control/00_Iteration.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Iteration 3 | * @description Iteration with a "for" structure to construct repetitive forms. 4 | */ 5 | var y; 6 | var num = 14; 7 | 8 | function setup() { 9 | 10 | createCanvas(720, 360); 11 | background(102); 12 | noStroke(); 13 | 14 | // Draw white bars 15 | fill(255); 16 | y = 60; 17 | for(var i = 0; i < num/3; i++) { 18 | rect(50, y, 475, 10); 19 | y+=20; 20 | } 21 | 22 | // Gray bars 23 | fill(51); 24 | y = 40; 25 | for(var i = 0; i < num; i++) { 26 | rect(405, y, 30, 10); 27 | y += 20; 28 | } 29 | y = 50; 30 | for(var i = 0; i < num; i++) { 31 | rect(425, y, 30, 10); 32 | y += 20; 33 | } 34 | 35 | // Thin lines 36 | y = 45; 37 | fill(0); 38 | for(var i = 0; i < num-1; i++) { 39 | rect(120, y, 40, 1); 40 | y+= 20; 41 | } 42 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Control/01_Embedded_Iteration.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Embedded Iteration 3 | * @description Embedding "for" structures allows repetition in two dimensions. 4 | */ 5 | function setup() { 6 | 7 | createCanvas(720, 360); 8 | background(0); 9 | noStroke(); 10 | 11 | var gridSize = 35; 12 | 13 | for (var x = gridSize; x <= width - gridSize; x += gridSize) { 14 | for (var y = gridSize; y <= height - gridSize; y += gridSize) { 15 | noStroke(); 16 | fill(255); 17 | rect(x-1, y-1, 3, 3); 18 | stroke(255, 50); 19 | line(x, y, width/2, height/2); 20 | } 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Control/02_Conditionals_1.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Conditionals 1 3 | * @description Conditions are like questions. 4 | * They allow a program to decide to take one action if 5 | * the answer to a question is true or to do another action 6 | * if the answer to the question is false. 7 | * The questions asked within a program are always logical 8 | * or relational statements. For example, if the variable 'i' is 9 | * equal to zero then draw a line. 10 | */ 11 | function setup() { 12 | 13 | createCanvas(720, 360); 14 | background(0); 15 | 16 | for(var i = 10; i < width; i += 10) { 17 | // If 'i' divides by 20 with no remainder draw the first line 18 | // else draw the second line 19 | if(i%20 == 0) { 20 | stroke(255); 21 | line(i, 80, i, height/2); 22 | } else { 23 | stroke(153); 24 | line(i, 20, i, 180); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Control/03_Conditionals_2.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Conditionals 2 3 | * @description We extend the language of conditionals from the previous 4 | * example by adding the keyword "else". This allows conditionals 5 | * to ask two or more sequential questions, each with a different 6 | * action. 7 | */ 8 | function setup() { 9 | 10 | createCanvas(720, 360); 11 | background(0); 12 | 13 | for(var i = 2; i < width-2; i += 4) { 14 | // If 'i' divides by 20 with no remainder 15 | if((i % 20) == 0) { 16 | stroke(255); 17 | line(i, 80, i, height/2); 18 | // If 'i' divides by 10 with no remainder 19 | } else if ((i % 10) == 0) { 20 | stroke(153); 21 | line(i, 20, i, 180); 22 | // If neither of the above two conditions are met 23 | // then draw this line 24 | } else { 25 | stroke(102); 26 | line(i, height/2, i, height-20); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Control/04_Logical_Operators.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Logical Operators 3 | * @description The logical operators for AND (&&) and OR (||) are used to 4 | * combine simple relational statements into more complex expressions. 5 | * The NOT (!) operator is used to negate a boolean statement. 6 | */ 7 | var test = false; 8 | 9 | function setup() { 10 | 11 | createCanvas(720, 360); 12 | background(126); 13 | 14 | for (var i = 5; i <= height; i += 5) { 15 | // Logical AND 16 | stroke(0); 17 | if((i > 35) && (i < 100)) { 18 | line(width/4, i, width/2, i); 19 | test = false; 20 | } 21 | 22 | // Logical OR 23 | stroke(76); 24 | if ((i <= 35) || (i >= 100)) { 25 | line(width/2, i, width, i); 26 | test = true; 27 | } 28 | 29 | // Testing if a boolean value is "true" 30 | // The expression "if(test)" is equivalent to "if(test == true)" 31 | if (test) { 32 | stroke(0); 33 | point(width/3, i); 34 | } 35 | 36 | // Testing if a boolean value is "false" 37 | // The expression "if(!test)" is equivalent to "if(test == false)" 38 | if (!test) { 39 | stroke(255); 40 | point(width/4, i); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Data/00_Variables.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Variables 3 | * @description Variables are used for storing values. In this example, change 4 | * the values of variables to affect the composition. 5 | */ 6 | function setup() { 7 | 8 | createCanvas(720, 400); 9 | background(0); 10 | stroke(153); 11 | strokeWeight(4); 12 | strokeCap(SQUARE); 13 | 14 | var a = 50; 15 | var b = 120; 16 | var c = 180; 17 | 18 | line(a, b, a+c, b); 19 | line(a, b+10, a+c, b+10); 20 | line(a, b+20, a+c, b+20); 21 | line(a, b+30, a+c, b+30); 22 | 23 | a = a + c; 24 | b = height-b; 25 | 26 | line(a, b, a+c, b); 27 | line(a, b+10, a+c, b+10); 28 | line(a, b+20, a+c, b+20); 29 | line(a, b+30, a+c, b+30); 30 | 31 | a = a + c; 32 | b = height-b; 33 | 34 | line(a, b, a+c, b); 35 | line(a, b+10, a+c, b+10); 36 | line(a, b+20, a+c, b+20); 37 | line(a, b+30, a+c, b+30); 38 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Data/01_True_and_False.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name True and False 3 | * @description A Boolean variable has only two possible values: true or false. 4 | * It is common to use Booleans with control statements to determine the flow 5 | * of a program. In this example, when the boolean value "x" is true, vertical 6 | * black lines are drawn and when the boolean value "x" is false, horizontal 7 | * gray lines are drawn. 8 | */ 9 | function setup() { 10 | 11 | createCanvas(720, 400); 12 | background(0); 13 | stroke(255); 14 | 15 | var b = false; 16 | var d = 20; 17 | var middle = width/2;; 18 | 19 | for (var i = d; i <= width; i += d) { 20 | 21 | if (i < middle) { 22 | b = true; 23 | } else { 24 | b = false; 25 | } 26 | 27 | if (b == true) { 28 | // Vertical line 29 | line(i, d, i, height-d); 30 | } 31 | 32 | if (b == false) { 33 | // Horizontal line 34 | line(middle, i - middle + d, width-d, i - middle + d); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Data/03_Variable_Scope.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Variable Scope 3 | * @description Variables have a global or local "scope". For example, 4 | * variables declared within either the setup() or draw() functions may be 5 | * only used in these functions. Global variables, variables declared outside 6 | * of setup() and draw(), may be used anywhere within the program. If a local 7 | * variable is declared with the same name as a global variable, the program 8 | * will use the local variable to make its calculations within the current 9 | * scope. Variables are localized within each block, the space between a { 10 | * and }. 11 | */ 12 | var a = 80; // Create a global variable "a" 13 | 14 | function setup() { 15 | createCanvas(720, 400); 16 | background(0); 17 | stroke(255); 18 | noLoop(); 19 | } 20 | 21 | function draw() { 22 | // Draw a line using the global variable "a" 23 | line(a, 0, a, height); 24 | 25 | // Create a new variable "a" local to the for() statement 26 | for (var a = 120; a < 200; a += 3) { 27 | line(a, 0, a, height); 28 | } 29 | 30 | // Create a new variable "a" local to the draw() function 31 | var a = 300; 32 | // Draw a line using the new local variable "a" 33 | line(a, 0, a, height); 34 | 35 | // Make a call to the custom function drawAnotherLine() 36 | drawAnotherLine(); 37 | 38 | // Make a call to the custom function drawYetAnotherLine() 39 | drawYetAnotherLine(); 40 | } 41 | 42 | function drawAnotherLine() { 43 | // Create a new variable "a" local to this method 44 | var a = 320; 45 | // Draw a line using the local variable "a" 46 | line(a, 0, a, height); 47 | } 48 | 49 | function drawYetAnotherLine() { 50 | // Because no new local variable "a" is set, 51 | // this line draws using the original global 52 | // variable "a" which is set to the value 20. 53 | line(a+3, 0, a+3, height); 54 | } 55 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Dom/03_Input_Button.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Input and Button 3 | * @description You will need to include the 4 | * p5.dom library 5 | * for this example to work in your own project.

6 | * Input text and click the button to see it affect the the canvas. 7 | */ 8 | var input, button, greeting; 9 | 10 | function setup() { 11 | 12 | // create canvas 13 | createCanvas(710, 400); 14 | 15 | input = createInput(); 16 | input.position(20, 65); 17 | 18 | button = createButton('submit'); 19 | button.position(150, 65); 20 | button.mousePressed(greet); 21 | 22 | greeting = createElement('h2', 'what is your name?'); 23 | greeting.position(20, 5); 24 | 25 | textAlign(CENTER) 26 | textSize(50); 27 | } 28 | 29 | function greet() { 30 | var name = input.value(); 31 | greeting.html('hello '+name+'!'); 32 | input.value(''); 33 | 34 | for (var i=0; i<200; i++) { 35 | push(); 36 | fill(random(255), 255, 255); 37 | translate(random(width), random(height)); 38 | rotate(random(2*PI)); 39 | text(name, 0, 0); 40 | pop(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Dom/04_Slider.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Slider 3 | * @description You will need to include the 4 | * p5.dom library 5 | * for this example to work in your own project.

6 | * Move the sliders to control the R, G, B values of the background. 7 | */ 8 | var rSlider, gSlider, bSlider; 9 | 10 | function setup() { 11 | // create canvas 12 | createCanvas(710, 400); 13 | textSize(15) 14 | noStroke(); 15 | 16 | // create sliders 17 | rSlider = createSlider(0, 255, 100); 18 | rSlider.position(20, 20); 19 | gSlider = createSlider(0, 255, 0); 20 | gSlider.position(20, 50); 21 | bSlider = createSlider(0, 255, 255); 22 | bSlider.position(20, 80); 23 | } 24 | 25 | function draw() { 26 | var r = rSlider.value(); 27 | var g = gSlider.value(); 28 | var b = bSlider.value(); 29 | background(r, g, b); 30 | text("red", 165, 35); 31 | text("green", 165, 65); 32 | text("blue", 165, 95); 33 | } 34 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Dom/07_Modify_DOM.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Modifying the DOM 3 | * @frame 710,300 4 | * @description

Create DOM elements and modify their properties every time 5 | * draw() is called. You will need to include the 6 | * p5.dom library 7 | * for this example to work in your own project.

8 | */ 9 | var dancingWords = []; 10 | 11 | function DanceSpan(element, x, y) { 12 | element.position(x, y); 13 | 14 | this.brownian = function() { 15 | x += random(-6, 6); 16 | y += random(-6, 6); 17 | element.position(x, y); 18 | }; 19 | }; 20 | 21 | function setup() { 22 | // This paragraph is created aside of the main block of code. 23 | // It's to differentiate the creation of an element from its 24 | // selection. Selected elements doesn't need to be created by 25 | // p5js, they can be just plain HTML. 26 | createP('I learne in this Letter, that Don Peter of Arragon, ' 27 | + ' comes this night to Messina').addClass('text'); 28 | 29 | // This line grabs the paragraph just created, but it would 30 | // also grab any other elements with class 'text' in the HTML 31 | // page. 32 | var texts = selectAll('.text'); 33 | 34 | for (var i=0; iLoad a video with multiple formats and toggle between playing 5 | * and paused with a button press. 6 | *

To run this example locally, you will need at least 7 | * one video file, and the 8 | * p5.dom library.

9 | */ 10 | var playing = false; 11 | var fingers; 12 | var button; 13 | 14 | 15 | function setup() { 16 | // specify multiple formats for different browsers 17 | fingers = createVideo(['assets/fingers.mov', 18 | 'assets/fingers.webm']); 19 | button = createButton('play'); 20 | button.mousePressed(toggleVid); // attach button listener 21 | } 22 | 23 | // plays or pauses the video depending on current state 24 | function toggleVid() { 25 | if (playing) { 26 | fingers.pause(); 27 | button.html('play'); 28 | } else { 29 | fingers.loop(); 30 | button.html('pause'); 31 | } 32 | playing = !playing; 33 | } 34 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Dom/09_Video_Canvas.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Video Canvas 3 | * @description

Load a video with multiple formats and draw it to the canvas.

4 | *

To run this example locally, you will need the 5 | * p5.dom library 6 | * at least one video file, and a running local server.

7 | */ 8 | var fingers; 9 | 10 | function setup() { 11 | createCanvas(710, 400); 12 | // specify multiple formats for different browsers 13 | fingers = createVideo(['assets/fingers.mov', 14 | 'assets/fingers.webm']); 15 | fingers.loop(); // set the video to loop and start playing 16 | fingers.hide(); // by default video shows up in separate dom 17 | // element. hide it and draw it to the canvas 18 | // instead 19 | } 20 | 21 | function draw() { 22 | background(150); 23 | image(fingers,10,10); // draw the video frame to canvas 24 | filter('GRAY'); 25 | image(fingers,150,150); // draw a second copy to canvas 26 | } 27 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Dom/10_Video_Pixels.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Video Pixels 3 | * @frame 320,240 4 | * @description

Load a video, manipulate its pixels and draw to canvas. 5 | *

To run this example locally, you will need the 6 | * p5.dom library 7 | * at least one video file, and a running local server.

8 | */ 9 | var fingers; 10 | 11 | function setup() { 12 | createCanvas(320, 240); 13 | // specify multiple formats for different browsers 14 | fingers = createVideo(['assets/fingers.mov', 15 | 'assets/fingers.webm']); 16 | fingers.loop(); 17 | fingers.hide(); 18 | noStroke(); 19 | fill(0); 20 | } 21 | 22 | function draw() { 23 | background(255); 24 | fingers.loadPixels(); 25 | var stepSize = round(constrain(mouseX / 8, 6, 32)); 26 | for (var y=0; y To run this example locally, you will need the 5 | * p5.dom library 6 | * at least one video file, and a running local server.



7 | * Capture video from the webcam and display 8 | * on the canvas as well with invert filter. Note that by 9 | * default the capture feed shows up, too. You can hide the 10 | * feed by uncommenting the capture.hide() line. 11 | */ 12 | var capture; 13 | 14 | function setup() { 15 | createCanvas(390, 240); 16 | capture = createCapture(VIDEO); 17 | capture.size(320, 240); 18 | //capture.hide(); 19 | } 20 | 21 | function draw() { 22 | background(255); 23 | image(capture, 0, 0, 320, 240); 24 | filter('INVERT'); 25 | } 26 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Dom/12_Drop.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Drop 3 | * @description You will need to include the 4 | * p5.dom library 5 | * for this example to work in your own project.

6 | * Drag an image file onto the canvas to see it displayed. 7 | */ 8 | 9 | function setup() { 10 | // create canvas 11 | var c = createCanvas(710, 400); 12 | background(100); 13 | // Add an event for when a file is dropped onto the canvas 14 | c.drop(gotFile); 15 | } 16 | 17 | function draw() { 18 | fill(255); 19 | noStroke(); 20 | textSize(24); 21 | textAlign(CENTER); 22 | text('Drag an image file onto the canvas.', width/2, height/2); 23 | noLoop(); 24 | } 25 | 26 | function gotFile(file) { 27 | // If it's an image file 28 | if (file.type === 'image') { 29 | // Create an image DOM element but don't show it 30 | var img = createImg(file.data).hide(); 31 | // Draw the image onto the canvas 32 | image(img, 0, 0, width, height); 33 | } else { 34 | println('Not an image file!'); 35 | } 36 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Form/00_Points_and_Lines.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Points and Lines 3 | * @description Points and lines can be used to draw basic geometry. 4 | * Change the value of the variable 'd' to scale the form. The four 5 | * variables set the positions based on the value of 'd'. 6 | */ 7 | function setup() { 8 | 9 | var d = 70; 10 | var p1 = d; 11 | var p2 = p1+d; 12 | var p3 = p2+d; 13 | var p4 = p3+d; 14 | 15 | // Sets the screen to be 720 pixels wide and 400 pixels high 16 | createCanvas(720, 400); 17 | background(0); 18 | noSmooth(); 19 | 20 | translate(140, 0); 21 | 22 | // Draw gray box 23 | stroke(153); 24 | line(p3, p3, p2, p3); 25 | line(p2, p3, p2, p2); 26 | line(p2, p2, p3, p2); 27 | line(p3, p2, p3, p3); 28 | 29 | // Draw white points 30 | stroke(255); 31 | point(p1, p1); 32 | point(p1, p3); 33 | point(p2, p4); 34 | point(p3, p1); 35 | point(p4, p2); 36 | point(p4, p4); 37 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Form/01_Shape_Primitives.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Shape Primitives 3 | * @description The basic shape primitive functions are triangle(), 4 | * rect(), quad(), ellipse(), and arc(). Squares are made with rect() 5 | * and circles are made with ellipse(). Each of these functions requires 6 | * a number of parameters to determine the shape's position and size. 7 | */ 8 | function setup() { 9 | 10 | // Sets the screen to be 720 pixels wide and 400 pixels high 11 | createCanvas(720, 400); 12 | background(0); 13 | noStroke(); 14 | 15 | fill(204); 16 | triangle(18, 18, 18, 360, 81, 360); 17 | 18 | fill(102); 19 | rect(81, 81, 63, 63); 20 | 21 | fill(204); 22 | quad(189, 18, 216, 18, 216, 360, 144, 360); 23 | 24 | fill(255); 25 | ellipse(252, 144, 72, 72); 26 | 27 | fill(204); 28 | triangle(288, 18, 351, 360, 288, 360); 29 | 30 | fill(255); 31 | arc(479, 300, 280, 280, PI, TWO_PI); 32 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Form/02_Pie_Chart.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Pie Chart 3 | * @description Uses the arc() function to generate a pie chart from the data 4 | * stored in an array. 5 | */ 6 | var angles = [ 30, 10, 45, 35, 60, 38, 75, 67 ]; 7 | 8 | function setup() { 9 | createCanvas(720, 400); 10 | noStroke(); 11 | noLoop(); // Run once and stop 12 | } 13 | 14 | function draw() { 15 | background(100); 16 | pieChart(300, angles); 17 | } 18 | 19 | function pieChart(diameter, data) { 20 | var lastAngle = 0; 21 | for (var i = 0; i < data.length; i++) { 22 | var gray = map(i, 0, data.length, 0, 255); 23 | fill(gray); 24 | arc(width/2, height/2, diameter, diameter, lastAngle, lastAngle+radians(angles[i])); 25 | lastAngle += radians(angles[i]); 26 | } 27 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Form/03_Regular_Polygon.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Regular Polygon 3 | * @description What is your favorite? Pentagon? Hexagon? Heptagon? No? 4 | * What about the icosagon? The polygon() function created for this example is 5 | * capable of drawing any regular polygon. Try placing different numbers into 6 | * the polygon() function calls within draw() to explore. 7 | */ 8 | function setup() { 9 | createCanvas(720, 400); 10 | } 11 | 12 | function draw() { 13 | background(102); 14 | 15 | push(); 16 | translate(width*0.2, height*0.5); 17 | rotate(frameCount / 200.0); 18 | polygon(0, 0, 82, 3); 19 | pop(); 20 | 21 | push(); 22 | translate(width*0.5, height*0.5); 23 | rotate(frameCount / 50.0); 24 | polygon(0, 0, 80, 20); 25 | pop(); 26 | 27 | push(); 28 | translate(width*0.8, height*0.5); 29 | rotate(frameCount / -100.0); 30 | polygon(0, 0, 70, 7); 31 | pop(); 32 | } 33 | 34 | function polygon(x, y, radius, npoints) { 35 | var angle = TWO_PI / npoints; 36 | beginShape(); 37 | for (var a = 0; a < TWO_PI; a += angle) { 38 | var sx = x + cos(a) * radius; 39 | var sy = y + sin(a) * radius; 40 | vertex(sx, sy); 41 | } 42 | endShape(CLOSE); 43 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Form/04_Star.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Star 3 | * @description The star() function created for this example is capable of 4 | * drawing a wide range of different forms. Try placing different numbers 5 | * into the star() function calls within draw() to explore. 6 | */ 7 | function setup() { 8 | createCanvas(720, 400); 9 | } 10 | 11 | function draw() { 12 | background(102); 13 | 14 | push(); 15 | translate(width*0.2, height*0.5); 16 | rotate(frameCount / 200.0); 17 | star(0, 0, 5, 70, 3); 18 | pop(); 19 | 20 | push(); 21 | translate(width*0.5, height*0.5); 22 | rotate(frameCount / 50.0); 23 | star(0, 0, 80, 100, 40); 24 | pop(); 25 | 26 | push(); 27 | translate(width*0.8, height*0.5); 28 | rotate(frameCount / -100.0); 29 | star(0, 0, 30, 70, 5); 30 | pop(); 31 | } 32 | 33 | function star(x, y, radius1, radius2, npoints) { 34 | var angle = TWO_PI / npoints; 35 | var halfAngle = angle/2.0; 36 | beginShape(); 37 | for (var a = 0; a < TWO_PI; a += angle) { 38 | var sx = x + cos(a) * radius2; 39 | var sy = y + sin(a) * radius2; 40 | vertex(sx, sy); 41 | sx = x + cos(a+halfAngle) * radius1; 42 | sy = y + sin(a+halfAngle) * radius1; 43 | vertex(sx, sy); 44 | } 45 | endShape(CLOSE); 46 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Form/05_Triangle_Strip.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Triangle Strip 3 | * @description Example by Ira Greenberg. Generate a closed ring using the 4 | * vertex() function and beginShape(TRIANGLE_STRIP) mode. The outsideRadius 5 | * and insideRadius variables control ring's radii respectively. 6 | */ 7 | var x; 8 | var y; 9 | var outsideRadius = 150; 10 | var insideRadius = 100; 11 | 12 | function setup() { 13 | createCanvas(720, 400); 14 | background(204); 15 | x = width/2; 16 | y = height/2; 17 | } 18 | 19 | function draw() { 20 | background(204); 21 | 22 | var numPoints = int(map(mouseX, 0, width, 6, 60)); 23 | var angle = 0; 24 | var angleStep = 180.0/numPoints; 25 | 26 | beginShape(TRIANGLE_STRIP); 27 | for (var i = 0; i <= numPoints; i++) { 28 | var px = x + cos(radians(angle)) * outsideRadius; 29 | var py = y + sin(radians(angle)) * outsideRadius; 30 | angle += angleStep; 31 | vertex(px, py); 32 | px = x + cos(radians(angle)) * insideRadius; 33 | py = y + sin(radians(angle)) * insideRadius; 34 | vertex(px, py); 35 | angle += angleStep; 36 | } 37 | endShape(); 38 | } 39 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Form/06_Bezier.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Bezier 3 | * @description The first two parameters for the bezier() function specify the 4 | * first point in the curve and the last two parameters specify the last point. 5 | * The middle parameters set the control points that define the shape of the 6 | * curve. 7 | */ 8 | function setup() { 9 | createCanvas(720, 400); 10 | stroke(255); 11 | noFill(); 12 | } 13 | 14 | function draw() { 15 | background(0); 16 | for (var i = 0; i < 200; i += 20) { 17 | bezier(mouseX-(i/2.0), 40+i, 410, 20, 440, 300, 240-(i/16.0), 300+(i/8.0)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Form/07_3D_Primitives.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name 3D Primitives 3 | * @frame 720,400 (optional) 4 | * @description Placing mathematically 3D objects in synthetic space. 5 | * The box() and sphere() functions take at least one parameter to specify their 6 | * size. These shapes are positioned using the translate() function. 7 | */ 8 | function setup() { 9 | createCanvas(710, 400, WEBGL); 10 | } 11 | 12 | function draw() { 13 | background(100); 14 | noStroke(); 15 | 16 | push(); 17 | translate(-300, 200); 18 | rotateY(1.25); 19 | rotateX(-0.9); 20 | box(100); 21 | pop(); 22 | 23 | noFill(); 24 | stroke(255); 25 | push(); 26 | translate(500, height*0.35, -200); 27 | sphere(300); 28 | pop(); 29 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Hello/01_shapes.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Simple Shapes 3 | * @description This examples includes a circle, square, triangle, and a flower. 4 | */ 5 | function setup() { 6 | // Create the canvas 7 | createCanvas(720, 400); 8 | background(200); 9 | 10 | // Set colors 11 | fill(204, 101, 192, 127); 12 | stroke(127, 63, 120); 13 | 14 | // A rectangle 15 | rect(40, 120, 120, 40); 16 | // An ellipse 17 | ellipse(240, 240, 80, 80); 18 | // A triangle 19 | triangle(300, 100, 320, 100, 310, 80); 20 | 21 | // A design for a simple flower 22 | translate(580, 200); 23 | noStroke(); 24 | for (var i = 0; i < 10; i ++) { 25 | ellipse(0, 30, 20, 80); 26 | rotate(PI/5); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Hello/02_interactivity.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Interactivity 1 3 | * @frame 720,425 4 | * @description The circle changes color when you click on it. 5 | *

To run this example locally, you will need the 6 | * p5.dom library. 7 | *

8 | */ 9 | 10 | // for red, green, and blue color values 11 | var r, g, b; 12 | 13 | function setup() { 14 | createCanvas(720, 400); 15 | // Pick colors randomly 16 | r = random(255); 17 | g = random(255); 18 | b = random(255); 19 | } 20 | 21 | function draw() { 22 | background(127); 23 | // Draw a circle 24 | strokeWeight(2); 25 | stroke(r, g, b); 26 | fill(r, g, b, 127); 27 | ellipse(360, 200, 200, 200); 28 | } 29 | 30 | // When the user clicks the mouse 31 | function mousePressed() { 32 | // Check if mouse is inside the circle 33 | var d = dist(mouseX, mouseY, 360, 200); 34 | if (d < 100) { 35 | // Pick new random color values 36 | r = random(255); 37 | g = random(255); 38 | b = random(255); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Hello/03_interactivity.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Interactivity 2 3 | * @frame 720,425 4 | * @description The circle changes color when you move the slider. 5 | * You will need to include the 6 | * p5.dom library 7 | * for this example to work in your own project. 8 | */ 9 | 10 | // A HTML range slider 11 | var slider; 12 | 13 | function setup() { 14 | createCanvas(720, 400); 15 | // hue, saturation, and brightness 16 | colorMode(HSB, 255); 17 | // slider has a range between 0 and 255 with a starting value of 127 18 | slider = createSlider(0, 255, 127); 19 | } 20 | 21 | function draw() { 22 | background(127); 23 | strokeWeight(2); 24 | 25 | // Set the hue according to the slider 26 | stroke(slider.value(), 255, 255); 27 | fill(slider.value(), 255, 255, 127); 28 | ellipse(360, 200, 200, 200); 29 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Hello/04_animate.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Animation 3 | * @description The circle moves. 4 | */ 5 | // Where is the circle 6 | var x, y; 7 | 8 | function setup() { 9 | createCanvas(720, 400); 10 | // Starts in the middle 11 | x = width / 2; 12 | y = height; 13 | } 14 | 15 | function draw() { 16 | background(200); 17 | 18 | // Draw a circle 19 | stroke(50); 20 | fill(100); 21 | ellipse(x, y, 24, 24); 22 | 23 | // Jiggling randomly on the horizontal axis 24 | x = x + random(-1, 1); 25 | // Moving up at a constant speed 26 | y = y - 1; 27 | 28 | // Reset to the bottom 29 | if (y < 0) { 30 | y = height; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Hello/05_weather.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Weather 3 | * @frame 720,280 4 | * @description This example grabs JSON weather data from apixu.com. 5 | * You will need to include the 6 | * p5.dom library 7 | * for this example to work in your own project. 8 | */ 9 | 10 | // A wind direction vector 11 | var wind; 12 | // Circle position 13 | var position; 14 | 15 | function setup() { 16 | createCanvas(720, 200); 17 | // Request the data from apixu.com 18 | var url = 'https://api.apixu.com/v1/current.json?key=513d8003c8b348f1a2461629162106&q=NYC'; 19 | loadJSON(url, gotWeather); 20 | // Circle starts in the middle 21 | position = createVector(width/2, height/2); 22 | // wind starts as (0,0) 23 | wind = createVector(); 24 | } 25 | 26 | function draw() { 27 | background(200); 28 | 29 | // This section draws an arrow pointing in the direction of wind 30 | push(); 31 | translate(32, height - 32); 32 | // Rotate by the wind's angle 33 | rotate(wind.heading() + PI/2); 34 | noStroke(); 35 | fill(255); 36 | ellipse(0, 0, 48, 48); 37 | 38 | stroke(45, 123, 182); 39 | strokeWeight(3); 40 | line(0, -16, 0, 16); 41 | 42 | noStroke(); 43 | fill(45, 123, 182); 44 | triangle(0, -18, -6, -10, 6, -10); 45 | pop(); 46 | 47 | // Move in the wind's direction 48 | position.add(wind); 49 | 50 | stroke(0); 51 | fill(51); 52 | ellipse(position.x, position.y, 16, 16); 53 | 54 | if (position.x > width) position.x = 0; 55 | if (position.x < 0) position.x = width; 56 | if (position.y > height) position.y = 0; 57 | if (position.y < 0) position.y = height; 58 | 59 | 60 | } 61 | 62 | function gotWeather(weather) { 63 | 64 | // Get the angle (convert to radians) 65 | var angle = radians(Number(weather.current.wind_degree)); 66 | // Get the wind speed 67 | var windmag = Number(weather.current.wind_mph); 68 | 69 | // Display as HTML elements 70 | var temperatureDiv = createDiv(floor(weather.current.temp_f) + '°'); 71 | var windDiv = createDiv("WIND " + windmag + " MPH"); 72 | 73 | // Make a vector 74 | wind = p5.Vector.fromAngle(angle); 75 | } 76 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Image/00_Load_and_Display_Image.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Load and Display Image 3 | * @description Images can be loaded and displayed to the screen at their 4 | * actual size or any other size. 5 | *

To run this example locally, you will need an 6 | * image file, and a running 7 | * local server.

8 | 9 | */ 10 | var img; // Declare variable 'img'. 11 | 12 | function setup() { 13 | createCanvas(720, 400); 14 | img = loadImage("assets/moonwalk.jpg"); // Load the image 15 | } 16 | 17 | function draw() { 18 | // Displays the image at its actual size at point (0,0) 19 | image(img, 0, 0); 20 | // Displays the image at point (0, height/2) at half size 21 | image(img, 0, height/2, img.width/2, img.height/2); 22 | } 23 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Image/01_Background_Image.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Background Image 3 | * @description This example presents the fastest way to load a 4 | * background image. To load an image as the background, 5 | * it must be the same width and height as the program. 6 | *

To run this example locally, you will need an 7 | * image file, and a running 8 | * local server.

9 | */ 10 | var bg; 11 | var y = 0; 12 | 13 | function setup() { 14 | // The background image must be the same size as the parameters 15 | // into the createCanvas() method. In this program, the size of 16 | // the image is 720x400 pixels. 17 | bg = loadImage("assets/moonwalk.jpg"); 18 | createCanvas(720, 400); 19 | } 20 | 21 | function draw() { 22 | background(bg); 23 | 24 | stroke(226, 204, 0); 25 | line(0, y, width, y); 26 | 27 | y++; 28 | if (y > height) { 29 | y = 0; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Image/02_Transparency.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Transparency 3 | * @description Move the pointer left and right across the image to change its 4 | * position. This program overlays one image over another by modifying the 5 | * alpha value of the image with the tint() function. 6 | *

To run this example locally, you will need an 7 | * image file, and a running 8 | * local server.

9 | */ 10 | var img; 11 | var offset = 0; 12 | var easing = 0.05; 13 | 14 | function setup() { 15 | createCanvas(720, 400); 16 | img = loadImage("assets/moonwalk.jpg"); // Load an image into the program 17 | } 18 | 19 | function draw() { 20 | image(img, 0, 0); // Display at full opacity 21 | var dx = (mouseX-img.width/2) - offset; 22 | offset += dx * easing; 23 | tint(255, 127); // Display at half opacity 24 | image(img, offset, 0); 25 | } 26 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Image/03_Alpha_Mask.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Alpha Mask 3 | * @description Loads a "mask" for an image to specify the transparency in 4 | * different parts of the image. The two images are blended together using 5 | * the mask() method of p5.Image. 6 | *

To run this example locally, you will need two 7 | * image files, and a running 8 | * local server.

9 | */ 10 | var img; 11 | var imgMask; 12 | 13 | function preload() { 14 | img = loadImage("assets/moonwalk.jpg"); 15 | imgMask = loadImage("assets/mask.png"); 16 | } 17 | 18 | function setup() { 19 | createCanvas(720, 400); 20 | img.mask(imgMask); 21 | imageMode(CENTER); 22 | } 23 | 24 | function draw() { 25 | background(0, 102, 153); 26 | image(img, width/2, height/2); 27 | image(img, mouseX, mouseY); 28 | } 29 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Image/04_Create_Image.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Create Image 3 | * @description The createImage() function provides a fresh buffer of pixels to 4 | * play with. This example creates an image gradient. 5 | */ 6 | var img; // Declare variable 'img'. 7 | 8 | function setup() { 9 | createCanvas(720, 400); 10 | img = createImage(230, 230); 11 | img.loadPixels(); 12 | for(var x = 0; x < img.width; x++) { 13 | for(var y = 0; y < img.height; y++) { 14 | var a = map(y, 0, img.height, 255, 0); 15 | img.set(x, y, [0, 153, 204, a]); 16 | } 17 | } 18 | img.updatePixels(); 19 | } 20 | 21 | function draw() { 22 | background(0); 23 | image(img, 90, 80); 24 | image(img, mouseX-img.width/2, mouseY-img.height/2); 25 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Image/05_Pointillism.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Pointillism 3 | * @description By Dan Shiffman. Mouse horizontal location controls size of 4 | * dots. Creates a simple pointillist effect using ellipses colored according 5 | * to pixels in an image. 6 | *

To run this example locally, you will need an 7 | * image file, and a running 8 | * local server.

9 | */ 10 | var img; 11 | var smallPoint, largePoint; 12 | 13 | function preload() { 14 | img = loadImage("assets/moonwalk.jpg"); 15 | } 16 | 17 | function setup() { 18 | createCanvas(720, 400); 19 | smallPoint = 4; 20 | largePoint = 40; 21 | imageMode(CENTER); 22 | noStroke(); 23 | background(255); 24 | img.loadPixels(); 25 | } 26 | 27 | function draw() { 28 | var pointillize = map(mouseX, 0, width, smallPoint, largePoint); 29 | var x = floor(random(img.width)); 30 | var y = floor(random(img.height)); 31 | var pix = img.get(x, y); 32 | fill(pix, 128); 33 | ellipse(x, y, pointillize, pointillize); 34 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Instance/01_Instantiating.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Instantiation 3 | * @description Create a p5 instance, which keeps all variables 4 | * out of the global scope of your page. 5 | */ 6 | var sketch = function( p ) { 7 | 8 | var x = 100; 9 | var y = 100; 10 | 11 | p.setup = function() { 12 | p.createCanvas(700, 410); 13 | }; 14 | 15 | p.draw = function() { 16 | p.background(0); 17 | p.fill(255); 18 | p.rect(x,y,50,50); 19 | }; 20 | }; 21 | 22 | var myp5 = new p5(sketch); 23 | 24 | // Compare to "global mode" 25 | // var x = 100; 26 | // var y = 100; 27 | 28 | // function setup() { 29 | // createCanvas(200,200); 30 | // } 31 | 32 | // function draw() { 33 | // background(0); 34 | // fill(255); 35 | // ellipse(x,y,50,50); 36 | // } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Interaction/10_Tickle.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Tickle 3 | * @description The word "tickle" jitters when the cursor hovers over. 4 | * Sometimes, it can be tickled off the screen. 5 | */ 6 | var message = "tickle", 7 | font, 8 | bounds, // holds x, y, w, h of the text's bounding box 9 | fontsize = 60, 10 | x, y; // x and y coordinates of the text 11 | 12 | function preload() { 13 | font = loadFont('assets/LeagueGothic-Regular.otf'); 14 | } 15 | 16 | function setup() { 17 | createCanvas(710, 400); 18 | 19 | // set up the font 20 | textFont(font); 21 | textSize(fontsize); 22 | 23 | // get the width and height of the text so we can center it initially 24 | bounds = font.textBounds(message, 0, 0, fontsize); 25 | x = width / 2 - bounds.w / 2; 26 | y = height / 2 - bounds.h / 2; 27 | } 28 | 29 | function draw() { 30 | // instead of clearing the background, fade it by drawing 31 | // a semi-transparent rectangle on top 32 | fill(204, 120); 33 | rect(0, 0, width, height); 34 | 35 | // write the text in black and get its bounding box 36 | fill(0); 37 | text(message, x, y); 38 | bounds = font.textBounds(message,x,y,fontsize); 39 | 40 | // check if the mouse is inside the bounding box and tickle if so 41 | if ( mouseX >= bounds.x && mouseX <= bounds.x + bounds.w && 42 | mouseY >= bounds.y && mouseY <= bounds.y + bounds.h) { 43 | x += random(-5, 5); 44 | y += random(-5, 5); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Interaction/20_Follow1.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Follow 1 3 | * @frame 710,400 4 | * @description A line segment is pushed and pulled by the cursor. 5 | * Based on code from Keith Peters. 6 | */ 7 | var x = 100, 8 | y = 100, 9 | angle1 = 0.0, 10 | segLength = 50; 11 | 12 | 13 | function setup() { 14 | createCanvas(710, 400); 15 | strokeWeight(20.0); 16 | stroke(255, 100); 17 | } 18 | 19 | function draw() { 20 | background(0); 21 | 22 | dx = mouseX - x; 23 | dy = mouseY - y; 24 | angle1 = atan2(dy, dx); 25 | x = mouseX - (cos(angle1) * segLength); 26 | y = mouseY - (sin(angle1) * segLength); 27 | 28 | segment(x, y, angle1); 29 | ellipse(x, y, 20, 20); 30 | } 31 | 32 | function segment(x, y, a) { 33 | push(); 34 | translate(x, y); 35 | rotate(a); 36 | line(0, 0, segLength, 0); 37 | pop(); 38 | } 39 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Interaction/21_Follow2.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Follow 2 3 | * @frame 710,400 4 | * @description A two-segmented arm follows the cursor position. The relative 5 | * angle between the segments is calculated with atan2() and the position 6 | * calculated with sin() and cos(). Based on code from Keith Peters. 7 | */ 8 | var x = [0,0], 9 | y = [0,0], 10 | segLength = 50; 11 | 12 | function setup() { 13 | createCanvas(710, 400); 14 | strokeWeight(20.0); 15 | stroke(255, 100); 16 | } 17 | 18 | function draw() { 19 | background(0); 20 | dragSegment(0, mouseX, mouseY); 21 | dragSegment(1, x[0], y[0]); 22 | } 23 | 24 | function dragSegment(i, xin, yin) { 25 | var dx = xin - x[i]; 26 | var dy = yin - y[i]; 27 | var angle = atan2(dy, dx); 28 | x[i] = xin - cos(angle) * segLength; 29 | y[i] = yin - sin(angle) * segLength; 30 | segment(x[i], y[i], angle); 31 | } 32 | 33 | function segment(x, y, a) { 34 | push(); 35 | translate(x, y); 36 | rotate(a); 37 | line(0, 0, segLength, 0); 38 | pop(); 39 | } 40 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Interaction/22_Follow3.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Follow 3 3 | * @frame 710,400 4 | * @description A segmented line follows the mouse. The relative angle from 5 | * each segment to the next is calculated with atan2() and the position of 6 | * the next is calculated with sin() and cos(). Based on code from Keith Peters. 7 | */ 8 | var x = [], 9 | y = [], 10 | segNum = 20, 11 | segLength = 18; 12 | 13 | for (var i = 0; i < segNum; i++) { 14 | x[i] = 0; 15 | y[i] = 0; 16 | } 17 | 18 | function setup() { 19 | createCanvas(710, 400); 20 | strokeWeight(9); 21 | stroke(255, 100); 22 | } 23 | 24 | function draw() { 25 | background(0); 26 | dragSegment(0, mouseX, mouseY); 27 | for( var i=0; i=1; j--) { 37 | positionSegment(j, j-1); 38 | } 39 | for(var k=0; k width-25 || ballX < 25) { 41 | ballXDirection *= -1; 42 | } 43 | if(ballY > height-25 || ballY < 25) { 44 | ballYDirection *= -1; 45 | } 46 | ellipse(ballX, ballY, 30, 30); 47 | 48 | reachSegment(0, ballX, ballY); 49 | for(var i=1; i=1; j--) { 53 | positionSegment(j, j-1); 54 | } 55 | for(var k=0; k width) { 22 | a = 0; 23 | direction = !direction; 24 | } 25 | if(direction == true){ 26 | stroke(a); 27 | } else { 28 | stroke(width-a); 29 | } 30 | line(a, 0, a, height/2); 31 | 32 | b--; 33 | if(b < 0) { 34 | b = width; 35 | } 36 | if(direction == true) { 37 | stroke(width-b); 38 | } else { 39 | stroke(b); 40 | } 41 | line(b, height/2+1, b, height); 42 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Math/01_operatorprecedence.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Operator Precedence 3 | * @description If you don't explicitly state the order in which an 4 | * expression is evaluated, they are evaluated based on the operator 5 | * precedence. For example, in the statement "4+2*8", the 2 will 6 | * first be multiplied by 8 and then the result will be added to 4. 7 | * This is because the "*" has a higher precedence than the "+". To avoid 8 | * ambiguity in reading the program, it is recommended that is statement 9 | * is written as "4+(2*8)". The order of evaluation can be controlled 10 | * through placement of parenthesis in the code. A table of operator 11 | * precedence follows below. 12 | */ 13 | // The highest precedence is at the top of the list and 14 | // the lowest is at the bottom. 15 | // Multiplicative: * / % 16 | // Additive: + - 17 | // Relational: < > <= >= 18 | // Equality: == != 19 | // Logical AND: && 20 | // Logical OR: || 21 | // Assignment: = += -= *= /= %= 22 | function setup() { 23 | createCanvas(710, 400); 24 | background(51); 25 | noFill(); 26 | stroke(51); 27 | 28 | stroke(204); 29 | for(var i=0; i< width-20; i+= 4) { 30 | // The 30 is added to 70 and then evaluated 31 | // if it is greater than the current value of "i" 32 | // For clarity, write as "if (i > (30 + 70)) {" 33 | if (i > 30 + 70) { 34 | line(i, 0, i, 50); 35 | } 36 | } 37 | 38 | stroke(255); 39 | // The 2 is multiplied by the 8 and the result is added to the 4 40 | // For clarity, write as "rect(5 + (2 * 8), 0, 90, 20);" 41 | rect(4 + 2 * 8, 52, 290, 48); 42 | rect((4 + 2) * 8, 100, 290, 49); 43 | 44 | stroke(153); 45 | for (var i = 0; i < width; i+= 2) { 46 | // The relational statements are evaluated 47 | // first, and then the logical AND statements and 48 | // finally the logical OR. For clarity, write as: 49 | // "if(((i > 20) && (i < 50)) || ((i > 100) && (i < width-20))) {" 50 | if (i > 20 && i < 50 || i > 100 && i < width-20) { 51 | line(i, 151, i, height-1); 52 | } 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Math/02_distance1d.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Distance 1D 3 | * @description Move the mouse left and right to control 4 | * the speed and direction of the moving shapes. 5 | */ 6 | var xpos1; 7 | var xpos2; 8 | var xpos3; 9 | var xpos4; 10 | var thin = 8; 11 | var thick = 36; 12 | 13 | function setup() { 14 | createCanvas(710, 400); 15 | noStroke(); 16 | xpos1 = width/2; 17 | xpos2 = width/2; 18 | xpos3 = width/2; 19 | xpos4 = width/2; 20 | } 21 | 22 | function draw() { 23 | background(0); 24 | 25 | var mx = mouseX * 0.4 - width/5.0; 26 | 27 | fill(102); 28 | rect(xpos2, 0, thick, height/2); 29 | fill(204); 30 | rect(xpos1, 0, thin, height/2); 31 | fill(102); 32 | rect(xpos4, height/2, thick, height/2); 33 | fill(204); 34 | rect(xpos3, height/2, thin, height/2); 35 | 36 | xpos1 += mx/16; 37 | xpos2 += mx/64; 38 | xpos3 -= mx/16; 39 | xpos4 -= mx/64; 40 | 41 | if(xpos1 < -thin) { xpos1 = width; } 42 | if(xpos1 > width) { xpos1 = -thin; } 43 | if(xpos2 < -thick) { xpos2 = width; } 44 | if(xpos2 > width) { xpos2 = -thick; } 45 | if(xpos3 < -thin) { xpos3 = width; } 46 | if(xpos3 > width) { xpos3 = -thin; } 47 | if(xpos4 < -thick) { xpos4 = width; } 48 | if(xpos4 > width) { xpos4 = -thick; } 49 | } 50 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Math/03_distance2d.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Distance 2D 3 | * @description Move the mouse across the image to obscure 4 | * and reveal the matrix. Measures the distance from the mouse 5 | * to each square and sets the size proportionally. 6 | */ 7 | var max_distance; 8 | 9 | function setup() { 10 | createCanvas(710, 400); 11 | noStroke(); 12 | max_distance = dist(0, 0, width, height); 13 | } 14 | 15 | function draw() { 16 | background(0); 17 | 18 | for(var i = 0; i <= width; i += 20) { 19 | for(var j = 0; j <= height; j += 20) { 20 | var size = dist(mouseX, mouseY, i, j); 21 | size = size/max_distance * 66; 22 | ellipse(i, j, size, size); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Math/04_sine.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Sine 3 | * @description Smoothly scaling size with the sin() function. 4 | */ 5 | var diameter; 6 | var angle = 0; 7 | 8 | function setup() { 9 | createCanvas(710, 400); 10 | diameter = height - 10; 11 | noStroke(); 12 | fill(255, 204, 0); 13 | } 14 | 15 | function draw() { 16 | background(0); 17 | 18 | var d1 = 10 + (sin(angle) * diameter/2) + diameter/2; 19 | var d2 = 10 + (sin(angle + PI/2) * diameter/2) + diameter/2; 20 | var d3 = 10 + (sin(angle + PI) * diameter/2) + diameter/2; 21 | 22 | ellipse(0, height/2, d1, d1); 23 | ellipse(width/2, height/2, d2, d2); 24 | ellipse(width, height/2, d3, d3); 25 | 26 | angle += 0.02; 27 | } 28 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Math/05_sincosine.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Sine Cosine 3 | * @description Linear movement with sin() and cos(). 4 | * Numbers between 0 and PI*2 (TWO_PI which angles roughly 6.28) 5 | * are put into these functions and numbers between -1 and 1 are returned. 6 | * These values are then scaled to produce larger movements. 7 | */ 8 | var angle1=0; 9 | var angle2=0; 10 | var scalar = 70; 11 | 12 | function setup() { 13 | createCanvas(710, 400); 14 | noStroke(); 15 | rectMode(CENTER); 16 | } 17 | 18 | function draw() { 19 | background(0); 20 | 21 | var ang1 = radians(angle1); 22 | var ang2 = radians(angle2); 23 | 24 | var x1 = width/2 + (scalar * cos(ang1)); 25 | var x2 = width/2 + (scalar * cos(ang2)); 26 | 27 | var y1 = height/2 + (scalar * sin(ang1)); 28 | var y2 = height/2 + (scalar * sin(ang2)); 29 | 30 | fill(255); 31 | rect(width*0.5, height*0.5, 140, 140); 32 | 33 | fill(0, 102, 153); 34 | ellipse(x1, height*0.5 - 120, scalar, scalar); 35 | ellipse(x2, height*0.5 + 120, scalar, scalar); 36 | 37 | fill(255, 204, 0); 38 | ellipse(width*0.5 - 120, y1, scalar, scalar); 39 | ellipse(width*0.5 + 120, y2, scalar, scalar); 40 | 41 | angle1 += 2; 42 | angle2 += 3; 43 | } 44 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Math/06_sinewave.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Sine Wave 3 | * @description Render a simple sine wave. 4 | * Original by Danial Shiffman. 5 | */ 6 | 7 | var xspacing = 16; // Distance between each horizontal location 8 | var w; // Width of entire wave 9 | var theta = 0.0; // Start angle at 0 10 | var amplitude = 75.0; // Height of wave 11 | var period = 500.0; // How many pixels before the wave repeats 12 | var dx; // Value for incrementing x 13 | var yvalues; // Using an array to store height values for the wave 14 | 15 | function setup() { 16 | createCanvas(710, 400); 17 | w = width+16; 18 | dx = (TWO_PI / period) * xspacing; 19 | yvalues = new Array(floor(w/xspacing)); 20 | } 21 | 22 | function draw() { 23 | background(0); 24 | calcWave(); 25 | renderWave(); 26 | } 27 | 28 | function calcWave() { 29 | // Increment theta (try different values for 30 | // 'angular velocity' here 31 | theta += 0.02; 32 | 33 | // For every x value, calculate a y value with sine function 34 | var x = theta; 35 | for (var i = 0; i < yvalues.length; i++) { 36 | yvalues[i] = sin(x)*amplitude; 37 | x+=dx; 38 | } 39 | } 40 | 41 | function renderWave() { 42 | noStroke(); 43 | fill(255); 44 | // A simple way to draw the wave with an ellipse at each location 45 | for (var x = 0; x < yvalues.length; x++) { 46 | ellipse(x*xspacing, height/2+yvalues[x], 16, 16); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Math/07_additivewave.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Additive Wave 3 | * @description Create a more complex wave by adding two waves together. 4 | * Original by Daniel Shiffman 5 | */ 6 | var xspacing = 8; // Distance between each horizontal location 7 | var w; // Width of entire wave 8 | var maxwaves = 4; // total # of waves to add together 9 | 10 | var theta = 0.0; 11 | var amplitude = new Array(maxwaves); // Height of wave 12 | // Value for incrementing X, to be calculated 13 | // as a function of period and xspacing 14 | var dx = new Array(maxwaves); 15 | // Using an array to store height values 16 | // for the wave (not entirely necessary) 17 | var yvalues; 18 | 19 | function setup() { 20 | createCanvas(710, 400); 21 | frameRate(30); 22 | colorMode(RGB, 255, 255, 255, 100); 23 | w = width + 16; 24 | 25 | for (var i = 0; i < maxwaves; i++) { 26 | amplitude[i] = random(10,30); 27 | var period = random(100,300); // Num pixels before wave repeats 28 | dx[i] = (TWO_PI / period) * xspacing; 29 | } 30 | 31 | yvalues = new Array(floor(w/xspacing)); 32 | } 33 | 34 | function draw() { 35 | background(0); 36 | calcWave(); 37 | renderWave(); 38 | } 39 | 40 | function calcWave() { 41 | // Increment theta (try different values 42 | // for 'angular velocity' here 43 | theta += 0.02; 44 | 45 | // Set all height values to zero 46 | for (var i = 0; i < yvalues.length; i++) { 47 | yvalues[i] = 0; 48 | } 49 | 50 | // Accumulate wave height values 51 | for (var j = 0; j < maxwaves; j++) { 52 | var x = theta; 53 | for (var i = 0; i < yvalues.length; i++) { 54 | // Every other wave is cosine instead of sine 55 | if (j % 2 == 0) yvalues[i] += sin(x)*amplitude[j]; 56 | else yvalues[i] += cos(x)*amplitude[j]; 57 | x+=dx[j]; 58 | } 59 | } 60 | } 61 | 62 | function renderWave() { 63 | // A simple way to draw the wave with an ellipse at each location 64 | noStroke(); 65 | fill(255,50); 66 | ellipseMode(CENTER); 67 | for (var x = 0; x < yvalues.length; x++) { 68 | ellipse(x*xspacing,width/2+yvalues[x],16,16); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Math/08_polartocartesian.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name PolarToCartesian 3 | * @description Convert a polar coordinate (r,theta) 4 | * to cartesian (x,y): x = rcos(theta) y = rsin(theta) 5 | * Original by Daniel Shiffman. 6 | */ 7 | var r; 8 | 9 | // Angle and angular velocity, accleration 10 | var theta; 11 | var theta_vel; 12 | var theta_acc; 13 | 14 | function setup() { 15 | createCanvas(710, 400); 16 | 17 | // Initialize all values 18 | r = height * 0.45; 19 | theta = 0; 20 | theta_vel = 0; 21 | theta_acc = 0.0001; 22 | } 23 | 24 | function draw() { 25 | 26 | background(0); 27 | 28 | // Translate the origin point to the center of the screen 29 | translate(width/2, height/2); 30 | 31 | // Convert polar to cartesian 32 | var x = r * cos(theta); 33 | var y = r * sin(theta); 34 | 35 | // Draw the ellipse at the cartesian coordinate 36 | ellipseMode(CENTER); 37 | noStroke(); 38 | fill(200); 39 | ellipse(x, y, 32, 32); 40 | 41 | // Apply acceleration and velocity to angle 42 | // (r remains static in this example) 43 | theta_vel += theta_acc; 44 | theta += theta_vel; 45 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Math/11_doubleRandom.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Double Random 3 | * @frame 720,400 (optional) 4 | * @description Using two random() calls and the point() 5 | * function to create an irregular sawtooth line. 6 | * Original by by Ira Greenberg. 7 | */ 8 | var totalPts = 300; 9 | var steps = totalPts + 1; 10 | 11 | function setup() { 12 | createCanvas(710, 400); 13 | stroke(255); 14 | frameRate(1); 15 | } 16 | 17 | function draw() { 18 | background(0); 19 | var rand = 0; 20 | for (var i = 1; i < steps; i++) { 21 | point( (width/steps) * i, (height/2) + random(-rand, rand) ); 22 | rand += random(-5, 5); 23 | } 24 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Math/12_random.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Random 3 | * @description Random numbers create the basis of this image. 4 | * Each time the program is loaded the result is different. 5 | */ 6 | function setup() { 7 | createCanvas(710, 400); 8 | background(0); 9 | strokeWeight(20); 10 | frameRate(2); 11 | } 12 | 13 | function draw() { 14 | for (var i = 0; i < width; i++) { 15 | var r = random(255); 16 | stroke(r); 17 | line(i, 0, i, height); 18 | } 19 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Math/13_noise1D.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Noise1D 3 | * @description Using 1D Perlin Noise to assign location. 4 | */ 5 | var xoff = 0.0; 6 | var xincrement = 0.01; 7 | 8 | function setup() { 9 | createCanvas(710, 400); 10 | background(0); 11 | noStroke(); 12 | } 13 | 14 | function draw() { 15 | // Create an alpha blended background 16 | fill(0, 10); 17 | rect(0,0,width,height); 18 | 19 | //float n = random(0,width); // Try this line instead of noise 20 | 21 | // Get a noise value based on xoff and scale 22 | // it according to the window's width 23 | var n = noise(xoff)*width; 24 | 25 | // With each cycle, increment xoff 26 | xoff += xincrement; 27 | 28 | // Draw the ellipse at the value produced by perlin noise 29 | fill(200); 30 | ellipse(n,height/2, 64, 64); 31 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Math/14_noisewave.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Noise Wave 3 | * @description Using Perlin Noise to generate a wave-like pattern. 4 | * Original by Daniel Shiffman. 5 | */ 6 | var yoff = 0.0; // 2nd dimension of perlin noise 7 | 8 | function setup() { 9 | createCanvas(710, 400); 10 | } 11 | 12 | function draw() { 13 | background(51); 14 | 15 | fill(255); 16 | // We are going to draw a polygon out of the wave points 17 | beginShape(); 18 | 19 | var xoff = 0; // Option #1: 2D Noise 20 | // var xoff = yoff; // Option #2: 1D Noise 21 | 22 | // Iterate over horizontal pixels 23 | for (var x = 0; x <= width; x += 10) { 24 | // Calculate a y value according to noise, map to 25 | 26 | // Option #1: 2D Noise 27 | var y = map(noise(xoff, yoff), 0, 1, 200,300); 28 | 29 | // Option #2: 1D Noise 30 | // var y = map(noise(xoff), 0, 1, 200,300); 31 | 32 | // Set the vertex 33 | vertex(x, y); 34 | // Increment x dimension for noise 35 | xoff += 0.05; 36 | } 37 | // increment y dimension for noise 38 | yoff += 0.01; 39 | vertex(width, height); 40 | vertex(0, height); 41 | endShape(CLOSE); 42 | } 43 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Math/15_arctangent.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Arctangent 3 | * @description Move the mouse to change the direction of the eyes.
The atan2() function computes the angle from each eye to the cursor. 4 | */ 5 | var e1, e2, e3; 6 | 7 | function setup() { 8 | createCanvas(720, 400); 9 | noStroke(); 10 | e1 = new Eye(250, 16, 120); 11 | e2 = new Eye(164, 185, 80); 12 | e3 = new Eye(420, 230, 220); 13 | } 14 | 15 | function draw() { 16 | background(102); 17 | e1.update(mouseX, mouseY); 18 | e2.update(mouseX, mouseY); 19 | e3.update(mouseX, mouseY); 20 | e1.display(); 21 | e2.display(); 22 | e3.display(); 23 | } 24 | 25 | function Eye(tx, ty, ts) { 26 | this.x = tx; 27 | this.y = ty; 28 | this.size = ts; 29 | this.angle = 0; 30 | 31 | this.update = function (mx, my) { 32 | this.angle = atan2(my - this.y, mx - this.x); 33 | }; 34 | 35 | this.display = function () { 36 | push(); 37 | translate(this.x, this.y); 38 | fill(255); 39 | ellipse(0, 0, this.size, this.size); 40 | rotate(this.angle); 41 | fill(153, 204, 0); 42 | ellipse(this.size / 4, 0, this.size / 2, this.size / 2); 43 | pop(); 44 | }; 45 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Mobile/00_Acceleration_Ball_Bounce.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Acceleration Ball Bounce 3 | * @description Move an ellipse around based on accelerationX and accelerationY values, and bounces when touch the edge of the canvas. 4 | */ 5 | 6 | // Position Variables 7 | var x = 0; 8 | var y = 0; 9 | 10 | // Speed - Velocity 11 | var vx = 0; 12 | var vy = 0; 13 | 14 | // Acceleration 15 | var ax = 0; 16 | var ay = 0; 17 | 18 | var vMultiplier = 0.007; 19 | var bMultiplier = 0.6; 20 | 21 | function setup() { 22 | createCanvas(displayWidth, displayHeight); 23 | fill(0); 24 | } 25 | 26 | function draw() { 27 | background(255); 28 | ballMove(); 29 | ellipse(x, y, 30, 30); 30 | } 31 | 32 | function ballMove() { 33 | 34 | ax = accelerationX; 35 | ay = accelerationY; 36 | 37 | vx = vx + ay; 38 | vy = vy + ax; 39 | y = y + vy * vMultiplier; 40 | x = x + vx * vMultiplier; 41 | 42 | // Bounce when touch the edge of the canvas 43 | if (x < 0) { 44 | x = 0; 45 | vx = -vx * bMultiplier; 46 | } 47 | if (y < 0) { 48 | y = 0; 49 | vy = -vy * bMultiplier; 50 | } 51 | if (x > width - 20) { 52 | x = width - 20; 53 | vx = -vx * bMultiplier; 54 | } 55 | if (y > height - 20) { 56 | y = height - 20; 57 | vy = -vy * bMultiplier; 58 | } 59 | 60 | } 61 | 62 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Mobile/00_acceleration_ballBounce.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Acceleration Ball Bounce 3 | * @description Move an ellipse around based on accelerationX and accelerationY values, and bounces when touch the edge of the canvas. 4 | */ 5 | 6 | // Position Variables 7 | var x = 0; 8 | var y = 0; 9 | 10 | // Speed - Velocity 11 | var vx = 0; 12 | var vy = 0; 13 | 14 | // Acceleration 15 | var ax = 0; 16 | var ay = 0; 17 | 18 | var vMultiplier = 0.007; 19 | var bMultiplier = 0.6; 20 | 21 | function setup() { 22 | createCanvas(displayWidth, displayHeight); 23 | fill(0); 24 | } 25 | 26 | function draw() { 27 | background(255); 28 | ballMove(); 29 | ellipse(x, y, 30, 30); 30 | } 31 | 32 | function ballMove() { 33 | 34 | ax = accelerationX; 35 | ay = accelerationY; 36 | 37 | vx = vx + ay; 38 | vy = vy + ax; 39 | y = y + vy * vMultiplier; 40 | x = x + vx * vMultiplier; 41 | 42 | // Bounce when touch the edge of the canvas 43 | if (x < 0) { 44 | x = 0; 45 | vx = -vx * bMultiplier; 46 | } 47 | if (y < 0) { 48 | y = 0; 49 | vy = -vy * bMultiplier; 50 | } 51 | if (x > width - 20) { 52 | x = width - 20; 53 | vx = -vx * bMultiplier; 54 | } 55 | if (y > height - 20) { 56 | y = height - 20; 57 | vy = -vy * bMultiplier; 58 | } 59 | 60 | } 61 | 62 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Mobile/01_Simple_Draw.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Simple Draw 3 | * @description Touch to draw on the screen using touchX, touchY, ptouchX, and ptouchY values. 4 | */ 5 | 6 | function setup() { 7 | createCanvas(displayWidth, displayHeight); 8 | strokeWeight(10) 9 | stroke(0); 10 | } 11 | 12 | function touchMoved() { 13 | line(touchX, touchY, ptouchX, ptouchY); 14 | return false; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Mobile/01_simpleDraw.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Simple Draw 3 | * @description Touch to draw on the screen using touchX, touchY, ptouchX, and ptouchY values. 4 | */ 5 | 6 | function setup() { 7 | createCanvas(displayWidth, displayHeight); 8 | strokeWeight(10) 9 | stroke(0); 10 | } 11 | 12 | function touchMoved() { 13 | line(touchX, touchY, ptouchX, ptouchY); 14 | return false; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Mobile/02_Acceleration_Color.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Acceleration Color 3 | * @description Use deviceMoved() to detect when the device is rotated. The background RGB color values are mapped to accelerationX, accelerationY, and accelerationZ values. 4 | */ 5 | 6 | var r, g, b; 7 | 8 | function setup() { 9 | createCanvas(displayWidth, displayHeight); 10 | r = random(50, 255); 11 | g = random(0, 200); 12 | b = random(50, 255); 13 | } 14 | 15 | function draw() { 16 | background(r, g, b); 17 | console.log('draw'); 18 | } 19 | 20 | function deviceMoved() { 21 | r = map(accelerationX, -90, 90, 100, 175); 22 | g = map(accelerationY, -90, 90, 100, 200); 23 | b = map(accelerationZ, -90, 90, 100, 200); 24 | } 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Mobile/02_accelerationColor.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Acceleration Color 3 | * @description Use deviceMoved() to detect when the device is rotated. The background RGB color values are mapped to accelerationX, accelerationY, and accelerationZ values. 4 | */ 5 | 6 | var r, g, b; 7 | 8 | function setup() { 9 | createCanvas(displayWidth, displayHeight); 10 | r = random(50, 255); 11 | g = random(0, 200); 12 | b = random(50, 255); 13 | } 14 | 15 | function draw() { 16 | background(r, g, b); 17 | console.log('draw'); 18 | } 19 | 20 | function deviceMoved() { 21 | r = map(accelerationX, -90, 90, 100, 175); 22 | g = map(accelerationY, -90, 90, 100, 200); 23 | b = map(accelerationZ, -90, 90, 100, 200); 24 | } 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Mobile/04_tilted_3D_box.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Tilted 3D Box 3 | * @description Use mobile to tilt a box 4 | */ 5 | function setup(){ 6 | createCanvas(displayWidth, displayHeight, WEBGL); 7 | } 8 | 9 | function draw(){ 10 | background(250); 11 | normalMaterial(); 12 | rotateX(accelerationX * 0.01); 13 | rotateY(accelerationY * 0.01); 14 | box(100, 100, 100); 15 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Objects/01_Objects.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Objects 3 | * @description Create a Jitter class, instantiate an object, 4 | * and move it around the screen. Adapted from Getting Started with 5 | * Processing by Casey Reas and Ben Fry. 6 | */ 7 | var bug; // Declare object 8 | 9 | function setup() { 10 | createCanvas(710, 400); 11 | // Create object 12 | bug = new Jitter(); 13 | } 14 | 15 | function draw() { 16 | background(50, 89, 100); 17 | bug.move(); 18 | bug.display(); 19 | } 20 | 21 | // Jitter class 22 | function Jitter() { 23 | this.x = random(width); 24 | this.y = random(height); 25 | this.diameter = random(10, 30); 26 | this.speed = 1; 27 | 28 | this.move = function() { 29 | this.x += random(-this.speed, this.speed); 30 | this.y += random(-this.speed, this.speed); 31 | }; 32 | 33 | this.display = function() { 34 | ellipse(this.x, this.y, this.diameter, this.diameter); 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Objects/02_Multiple_Objects.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Multiple Objects 3 | * @description Create a Jitter class, instantiate multiple objects, 4 | * and move it around the screen. 5 | */ 6 | var bug1; // Declare objects 7 | var bug2; 8 | var bug3; 9 | var bug4; 10 | 11 | function setup() { 12 | createCanvas(710, 400); 13 | // Create object 14 | bug1 = new Jitter(); 15 | bug2 = new Jitter(); 16 | bug3 = new Jitter(); 17 | bug4 = new Jitter(); 18 | } 19 | 20 | function draw() { 21 | background(50, 89, 100); 22 | bug1.move(); 23 | bug1.display(); 24 | bug2.move(); 25 | bug2.display(); 26 | bug3.move(); 27 | bug3.display(); 28 | bug4.move(); 29 | bug4.display(); 30 | } 31 | 32 | // Jitter class 33 | function Jitter() { 34 | this.x = random(width); 35 | this.y = random(height); 36 | this.diameter = random(10, 30); 37 | this.speed = 1; 38 | 39 | this.move = function() { 40 | this.x += random(-this.speed, this.speed); 41 | this.y += random(-this.speed, this.speed); 42 | }; 43 | 44 | this.display = function() { 45 | ellipse(this.x, this.y, this.diameter, this.diameter); 46 | }; 47 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Objects/03_Objects_Array.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Array of Objects 3 | * @description Create a Jitter class, instantiate an array of objects 4 | * and move them around the screen. 5 | */ 6 | var bugs = []; // array of Jitter objects 7 | 8 | function setup() { 9 | createCanvas(710, 400); 10 | // Create objects 11 | for (var i=0; i<50; i++) { 12 | bugs.push(new Jitter()); 13 | } 14 | } 15 | 16 | function draw() { 17 | background(50, 89, 100); 18 | for (var i=0; i 1) { 44 | this.ypos -= dif/damping; 45 | } 46 | dif = this.xpos - posX; 47 | if (abs(dif) > 1) { 48 | this.xpos -= dif/damping; 49 | } 50 | } 51 | 52 | this.display = function() { 53 | for (var i=0; inatureofcode.com) 5 | */ 6 | var system; 7 | 8 | function setup() { 9 | createCanvas(720, 400); 10 | system = new ParticleSystem(createVector(width/2, 50)); 11 | } 12 | 13 | function draw() { 14 | background(51); 15 | system.addParticle(); 16 | system.run(); 17 | } 18 | 19 | // A simple Particle class 20 | var Particle = function(position) { 21 | this.acceleration = createVector(0, 0.05); 22 | this.velocity = createVector(random(-1, 1), random(-1, 0)); 23 | this.position = position.copy(); 24 | this.lifespan = 255.0; 25 | }; 26 | 27 | Particle.prototype.run = function() { 28 | this.update(); 29 | this.display(); 30 | }; 31 | 32 | // Method to update position 33 | Particle.prototype.update = function(){ 34 | this.velocity.add(this.acceleration); 35 | this.position.add(this.velocity); 36 | this.lifespan -= 2; 37 | }; 38 | 39 | // Method to display 40 | Particle.prototype.display = function() { 41 | stroke(200, this.lifespan); 42 | strokeWeight(2); 43 | fill(127, this.lifespan); 44 | ellipse(this.position.x, this.position.y, 12, 12); 45 | }; 46 | 47 | // Is the particle still useful? 48 | Particle.prototype.isDead = function(){ 49 | if (this.lifespan < 0) { 50 | return true; 51 | } else { 52 | return false; 53 | } 54 | }; 55 | 56 | var ParticleSystem = function(position) { 57 | this.origin = position.copy(); 58 | this.particles = []; 59 | }; 60 | 61 | ParticleSystem.prototype.addParticle = function() { 62 | this.particles.push(new Particle(this.origin)); 63 | }; 64 | 65 | ParticleSystem.prototype.run = function() { 66 | for (var i = this.particles.length-1; i >= 0; i--) { 67 | var p = this.particles[i]; 68 | p.run(); 69 | if (p.isDead()) { 70 | this.particles.splice(i, 1); 71 | } 72 | } 73 | }; -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Simulate/04_WolframCA.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Wolfram CA 3 | * @description Simple demonstration of a Wolfram 1-dimensional cellular automata 4 | * (natureofcode.com) 5 | */ 6 | 7 | var w = 10; 8 | // An array of 0s and 1s 9 | var cells; 10 | 11 | // We arbitrarily start with just the middle cell having a state of "1" 12 | var generation = 0; 13 | 14 | // An array to store the ruleset, for example {0,1,1,0,1,1,0,1} 15 | var ruleset = [0, 1, 0, 1, 1, 0, 1, 0]; 16 | 17 | function setup() { 18 | createCanvas(640, 400); 19 | cells = Array(floor(width/w)); 20 | for (var i = 0; i < cells.length; i++) { 21 | cells[i] = 0; 22 | } 23 | cells[cells.length/2] = 1; 24 | 25 | } 26 | 27 | function draw() { 28 | for (var i = 0; i < cells.length; i++) { 29 | if (cells[i] === 1) { 30 | fill(200); 31 | } else { 32 | fill(51); 33 | noStroke(); 34 | rect(i*w, generation*w, w, w); 35 | } 36 | } 37 | if (generation < height/w) { 38 | generate(); 39 | } 40 | } 41 | 42 | // The process of creating the new generation 43 | function generate() { 44 | // First we create an empty array for the new values 45 | var nextgen = Array(cells.length); 46 | // For every spot, determine new state by examing current state, and neighbor states 47 | // Ignore edges that only have one neighor 48 | for (var i = 1; i < cells.length-1; i++) { 49 | var left = cells[i-1]; // Left neighbor state 50 | var me = cells[i]; // Current state 51 | var right = cells[i+1]; // Right neighbor state 52 | nextgen[i] = rules(left, me, right); // Compute next generation state based on ruleset 53 | } 54 | // The current generation is the new generation 55 | cells = nextgen; 56 | generation++; 57 | } 58 | 59 | 60 | // Implementing the Wolfram rules 61 | // Could be improved and made more concise, but here we can explicitly see what is going on for each case 62 | function rules(a, b, c) { 63 | if (a == 1 && b == 1 && c == 1) return ruleset[0]; 64 | if (a == 1 && b == 1 && c == 0) return ruleset[1]; 65 | if (a == 1 && b == 0 && c == 1) return ruleset[2]; 66 | if (a == 1 && b == 0 && c == 0) return ruleset[3]; 67 | if (a == 0 && b == 1 && c == 1) return ruleset[4]; 68 | if (a == 0 && b == 1 && c == 0) return ruleset[5]; 69 | if (a == 0 && b == 0 && c == 1) return ruleset[6]; 70 | if (a == 0 && b == 0 && c == 0) return ruleset[7]; 71 | return 0; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Simulate/09_Spring.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Spring 3 | * @frame 710, 400 4 | * @description Click, drag, and release the horizontal bar to start the spring. 5 | */ 6 | // Spring drawing constants for top bar 7 | var springHeight = 32, 8 | left, 9 | right, 10 | maxHeight = 200, 11 | minHeight = 100, 12 | over = false, 13 | move = false; 14 | 15 | // Spring simulation constants 16 | var M = 0.8, // Mass 17 | K = 0.2, // Spring constant 18 | D = 0.92, // Damping 19 | R = 150; // Rest position 20 | 21 | // Spring simulation variables 22 | var ps = R, // Position 23 | vs = 0.0, // Velocity 24 | as = 0, // Acceleration 25 | f = 0; // Force 26 | 27 | function setup() { 28 | createCanvas(710, 400); 29 | rectMode(CORNERS); 30 | noStroke(); 31 | left = width/2 - 100; 32 | right = width/2 + 100; 33 | } 34 | 35 | function draw() { 36 | background(102); 37 | updateSpring(); 38 | drawSpring(); 39 | } 40 | 41 | function drawSpring() { 42 | // Draw base 43 | fill(0.2); 44 | var baseWidth = 0.5 * ps + -8; 45 | rect(width/2 - baseWidth, ps + springHeight, width/2 + baseWidth, height); 46 | 47 | // Set color and draw top bar 48 | if (over || move) { 49 | fill(255); 50 | } else { 51 | fill(204); 52 | } 53 | 54 | rect(left, ps, right, ps + springHeight); 55 | } 56 | 57 | function updateSpring() { 58 | // Update the spring position 59 | if ( !move ) { 60 | f = -K * ( ps - R ); // f=-ky 61 | as = f / M; // Set the acceleration, f=ma == a=f/m 62 | vs = D * (vs + as); // Set the velocity 63 | ps = ps + vs; // Updated position 64 | } 65 | 66 | if (abs(vs) < 0.1) { 67 | vs = 0.0; 68 | } 69 | 70 | // Test if mouse if over the top bar 71 | if (mouseX > left && mouseX < right && mouseY > ps && mouseY < ps + springHeight) { 72 | over = true; 73 | } else { 74 | over = false; 75 | } 76 | 77 | // Set and constrain the position of top bar 78 | if (move) { 79 | ps = mouseY - springHeight/2; 80 | ps = constrain(ps, minHeight, maxHeight); 81 | } 82 | } 83 | 84 | function mousePressed() { 85 | if (over) { 86 | move = true; 87 | } 88 | } 89 | 90 | function mouseReleased() { 91 | move = false; 92 | } 93 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Simulate/12_BrownianMotion.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Brownian Motion 3 | * @description Recording random movement as a continuous line. 4 | * Port of original example from the Processing examples page. 5 | */ 6 | 7 | var num = 2000; 8 | var range = 6; 9 | 10 | var ax = []; 11 | var ay = []; 12 | 13 | 14 | function setup() { 15 | createCanvas(710, 400); 16 | for ( var i = 0; i < num; i++ ) { 17 | ax[i] = width / 2; 18 | ay[i] = height / 2; 19 | } 20 | frameRate(30); 21 | } 22 | 23 | function draw() { 24 | background(51); 25 | 26 | // Shift all elements 1 place to the left 27 | for ( var i = 1; i < num; i++ ) { 28 | ax[i - 1] = ax[i]; 29 | ay[i - 1] = ay[i]; 30 | } 31 | 32 | // Put a new value at the end of the array 33 | ax[num - 1] += random(-range, range); 34 | ay[num - 1] += random(-range, range); 35 | 36 | // Constrain all points to the screen 37 | ax[num - 1] = constrain(ax[num - 1], 0, width); 38 | ay[num - 1] = constrain(ay[num - 1], 0, height); 39 | 40 | // Draw a line connecting the points 41 | for ( var j = 1; j < num; j++ ) { 42 | var val = j / num * 204.0 + 51; 43 | stroke(val); 44 | line(ax[j - 1], ay[j - 1], ax[j], ay[j]); 45 | } 46 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Sound/00_Load_and_Play_Sound.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Load and Play Sound 3 | * @description Load sound during preload(). Play a sound when canvas is clicked. 4 | *

To run this example locally, you will need the 5 | * p5.sound library 6 | * a sound file, and a running local server. 7 | */ 8 | var song; 9 | 10 | function setup() { 11 | song = loadSound('assets/lucky_dragons_-_power_melody.mp3'); 12 | createCanvas(720, 200); 13 | background(255,0,0); 14 | } 15 | 16 | function mousePressed() { 17 | if ( song.isPlaying() ) { // .isPlaying() returns a boolean 18 | song.stop(); 19 | background(255,0,0); 20 | } else { 21 | song.play(); 22 | background(0,255,0); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Sound/01_Preload_Sound.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Preload SoundFile 3 | * @description Call loadSound() during preload() to ensure that the 4 | * sound is completely loaded before setup() is called. It's best to always 5 | * call loadSound() in preload(), otherwise sounds won't necessarily be loaded 6 | * by the time you want to play them in your sketch. 7 | * 8 | *

To run this example locally, you will need the 9 | * p5.sound library 10 | * a sound file, and a running local server. 11 | */ 12 | 13 | var song; 14 | 15 | function preload() { 16 | song = loadSound('assets/lucky_dragons_-_power_melody.mp3'); 17 | } 18 | 19 | function setup() { 20 | createCanvas(710, 200); 21 | song.loop(); // song is ready to play during setup() because it was loaded during preload 22 | background(0,255,0); 23 | } 24 | 25 | function mousePressed() { 26 | if ( song.isPlaying() ) { // .isPlaying() returns a boolean 27 | song.pause(); // .play() will resume from .pause() position 28 | background(255,0,0); 29 | } else { 30 | song.play(); 31 | background(0,255,0); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Sound/02_soundFormats.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @name soundFormats 3 | * @description

Technically, due to patent issues, there is no single 4 | * sound format that is supported by all web browsers. While 5 | * mp3 is supported across the 6 | * latest versions of major browsers on OS X and Windows, for example, 7 | * it may not be available on some less mainstream operating systems and 8 | * browsers.

9 | * 10 | *

To ensure full compatibility, you can include the same sound file 11 | * in multiple formats, e.g. 'sound.mp3' and 'sound.ogg'. (Ogg is an 12 | * open source alternative to mp3.) You can convert audio files 13 | * into web friendly formats for free online at media.io

. 15 | * 16 | *

The soundFormats() method tells loadSound which formats 17 | * we have included with our sketch. Then, loadSound will 18 | * attempt to load the first format that is supported by the 19 | * client's web browser.

20 | * 21 | *

To run this example locally, you will need the 22 | * p5.sound library 23 | * a sound file, and a running local server.

24 | */ 25 | var song; 26 | 27 | function preload() { 28 | // we have included both an .ogg file and an .mp3 file 29 | soundFormats('ogg', 'mp3'); 30 | 31 | // if mp3 is not supported by this browser, 32 | // loadSound will load the ogg file 33 | // we have included with our sketch 34 | song = loadSound('assets/lucky_dragons_-_power_melody.mp3'); 35 | } 36 | 37 | function setup() { 38 | createCanvas(710, 200); 39 | 40 | // song loaded during preload(), ready to play in setup() 41 | song.play(); 42 | background(0,255,0); 43 | } 44 | 45 | function mousePressed() { 46 | if ( song.isPlaying() ) { // .isPlaying() returns a boolean 47 | song.pause(); 48 | background(255,0,0); 49 | } else { 50 | song.play(); // playback will resume from the pause position 51 | background(0,255,0); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Sound/03_Play_Mode.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Play Mode 3 | * @description 4 | *

In 'sustain' mode, the sound will overlap with itself. 5 | * In 'restart' mode it will stop and then start again. 6 | * Click mouse to play a sound file. 7 | * Trigger lots of sounds at once! Press any key to change playmode.

8 | *

To run this example locally, you will need the 9 | * p5.sound library 10 | * a sound file, and a running local server.

11 | */ 12 | var playMode = 'sustain'; 13 | var sample; 14 | 15 | function setup() { 16 | createCanvas(710,50); 17 | soundFormats('mp3', 'ogg'); 18 | sample = loadSound('assets/Damscray_-_Dancing_Tiger_02.mp3'); 19 | } 20 | 21 | function draw() { 22 | background(255,255,0); 23 | var str = 'Click here to play! Press key to toggle play mode.'; 24 | str += ' Current Play Mode: ' + playMode+'.'; 25 | text(str, 10, height/2); 26 | } 27 | 28 | function mouseClicked() { 29 | sample.play(); 30 | } 31 | function keyPressed(k) { 32 | togglePlayMode(); 33 | } 34 | 35 | function togglePlayMode(){ 36 | if (playMode == 'sustain'){ 37 | playMode = 'restart'; 38 | } 39 | else { 40 | playMode = 'sustain'; 41 | } 42 | sample.playMode(playMode); 43 | } 44 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Sound/04_Pan_SoundFile.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Pan Sound 3 | * @description

Click mouse to play the sound. 4 | * Ball position follows mouse and correlates to panning of sound.

5 | *

To run this example locally, you will need the 6 | * p5.sound library 7 | * a sound file, and a running local server.

8 | * 9 | */ 10 | var ball = {}; 11 | var soundFile; 12 | 13 | function preload() { 14 | soundFormats('mp3', 'ogg'); 15 | soundFile = loadSound('assets/beatbox.ogg'); 16 | } 17 | 18 | function setup() { 19 | createCanvas(710, 100); 20 | } 21 | 22 | function draw() { 23 | background(0); 24 | ball.x = constrain(mouseX, 0, width); 25 | ellipse(ball.x, height/2, 100, 100) 26 | } 27 | 28 | function mousePressed(){ 29 | // map the ball's x location to a panning degree 30 | // between -1.0 (left) and 1.0 (right) 31 | var panning = map(ball.x, 0., width,-1.0, 1.0); 32 | soundFile.pan(panning); 33 | soundFile.play(); 34 | } 35 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Sound/05_Sound_Effect.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Sound Effect 3 | * @description

Play a sound effect when the mouse is clicked inside the circle.

4 | *

To run this example locally, you will need the 5 | * p5.sound library 6 | * a sound file, and a running local server.

7 | */ 8 | // Adapted from Learning Processing by Daniel Shiffman 9 | // http://www.learningprocessing.com 10 | // Doorbell sample by Corsica_S via freesound.org, 11 | // Creative Commons BY 3.0 12 | 13 | // A sound file object 14 | var dingdong; 15 | 16 | // A doorbell object (that will trigger the sound) 17 | var doorbell; 18 | 19 | function setup() { 20 | createCanvas(200, 200); 21 | 22 | // Load the sound file. 23 | // We have included both an MP3 and an OGG version. 24 | soundFormats('mp3', 'ogg'); 25 | dingdong = loadSound('assets/doorbell.mp3'); 26 | 27 | // Create a new doorbell 28 | doorbell = new Doorbell(width/2, height/2, 64); 29 | } 30 | 31 | function draw() { 32 | background(255); 33 | // Show the doorbell 34 | doorbell.display(mouseX, mouseY); 35 | } 36 | 37 | function mousePressed() { 38 | // If the user clicks on the doorbell, play the sound! 39 | if (doorbell.contains(mouseX, mouseY)) { 40 | dingdong.play(); 41 | } 42 | } 43 | 44 | // A Class to describe a "doorbell" (really a button) 45 | var Doorbell = function(x_, y_, r_) { 46 | // Location and size 47 | var x = x_; 48 | var y = y_; 49 | var r = r_; 50 | 51 | // Is a point inside the doorbell? (used for mouse rollover, etc.) 52 | this.contains = function(mx, my) { 53 | if (dist(mx, my, x, y) < r) { 54 | return true; 55 | } else { 56 | return false; 57 | } 58 | }; 59 | 60 | // Show the doorbell (hardcoded colors, could be improved) 61 | this.display = function(mx, my) { 62 | if (this.contains(mx, my)) { 63 | fill(100); 64 | } else { 65 | fill(175); 66 | } 67 | stroke(0); 68 | strokeWeight(4); 69 | ellipse(x, y, r, r); 70 | }; 71 | }; 72 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Sound/06_Manipulate_Sound.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Playback Rate 3 | * @description

Load a SoundFile and map its playback rate to 4 | * mouseY, volume to mouseX. Playback rate is the speed with 5 | * which the web audio context processings the sound file information. 6 | * Slower rates not only increase the duration of the sound, but also 7 | * decrease the pitch because it is being played back at a slower frequency.

8 | *

To run this example locally, you will need the 9 | * p5.sound library 10 | * a sound file, and a running local server.

11 | */ 12 | // A sound file object 13 | var song; 14 | 15 | function preload() { 16 | // Load a sound file 17 | song = loadSound('assets/Damscray_DancingTiger.mp3'); 18 | } 19 | 20 | function setup() { 21 | createCanvas(710, 400); 22 | 23 | // Loop the sound forever 24 | // (well, at least until stop() is called) 25 | song.loop(); 26 | } 27 | 28 | function draw() { 29 | background(200); 30 | 31 | // Set the volume to a range between 0 and 1.0 32 | var volume = map(mouseX, 0, width, 0, 1); 33 | volume = constrain(volume, 0, 1); 34 | song.amp(volume); 35 | 36 | // Set the rate to a range between 0.1 and 4 37 | // Changing the rate alters the pitch 38 | var speed = map(mouseY, 0.1, height, 0, 2); 39 | speed = constrain(speed, 0.01, 4); 40 | song.rate(speed); 41 | 42 | // Draw some circles to show what is going on 43 | stroke(0); 44 | fill(51, 100); 45 | ellipse(mouseX, 100, 48, 48); 46 | stroke(0); 47 | fill(51, 100); 48 | ellipse(100, mouseY, 48, 48); 49 | } 50 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Sound/07_Amplitude_Analysis.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @name Measuring Amplitude 3 | * @description

Analyze the amplitude of sound with 4 | * p5.Amplitude.

5 | * 6 | *

Amplitude is the magnitude of vibration. Sound is vibration, 7 | * so its amplitude is is closely related to volume / loudness.

8 | * 9 | *

The getLevel() method takes an array 10 | * of amplitude values collected over a small period of time (1024 samples). 11 | * Then it returns the Root Mean Square (RMS) of these values.

12 | * 13 | *

The original amplitude values for digital audio are between -1.0 and 1.0. 14 | * But the RMS will always be positive, because it is squared. 15 | * And, rather than use instantanous amplitude readings that are sampled at a rate 16 | * of 44,100 times per second, the RMS is an average over time (1024 samples, in this case), 17 | * which better represents how we hear amplitude. 18 | *

19 | *

To run this example locally, you will need the 20 | * p5.sound library 21 | * a sound file, and a running local server.

22 | */ 23 | var song, analyzer; 24 | 25 | function preload() { 26 | song = loadSound('assets/lucky_dragons_-_power_melody.mp3'); 27 | } 28 | 29 | function setup() { 30 | createCanvas(710, 200); 31 | song.loop(); 32 | 33 | // create a new Amplitude analyzer 34 | analyzer = new p5.Amplitude(); 35 | 36 | // Patch the input to an volume analyzer 37 | analyzer.setInput(song); 38 | } 39 | 40 | function draw() { 41 | background(255); 42 | 43 | // Get the average (root mean square) amplitude 44 | var rms = analyzer.getLevel(); 45 | fill(127); 46 | stroke(0); 47 | 48 | // Draw an ellipse with size based on volume 49 | ellipse(width/2, height/2, 10+rms*200, 10+rms*200); 50 | } 51 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Sound/08_Noise_Envelope.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @name Noise Drum Envelope 3 | * @description

White Noise is a random audio signal with equal energy 4 | * at every part of the frequency spectrum

5 | * 6 | *

An Envelope is a series of fades, defined 7 | * as time / value pairs.

8 | * 9 | *

In this example, the p5.Env 10 | * will be used to "play" the p5.Noise like a drum by controlling its output 11 | * amplitude. A p5.Amplitude will get the level of all sound in the sketch, and 12 | * we'll use this value to draw a green rectangle that shows the envelope 13 | * in action.

14 | *

To run this example locally, you will need the 15 | * p5.sound library and a 16 | * sound file.

17 | */ 18 | var noise, env, analyzer; 19 | 20 | function setup() { 21 | createCanvas(710, 200); 22 | noise = new p5.Noise(); // other types include 'brown' and 'pink' 23 | noise.start(); 24 | 25 | // multiply noise volume by 0 26 | // (keep it quiet until we're ready to make noise!) 27 | noise.amp(0); 28 | 29 | env = new p5.Env(); 30 | // set attackTime, decayTime, sustainRatio, releaseTime 31 | env.setADSR(0.001, 0.1, 0.2, 0.1); 32 | // set attackLevel, releaseLevel 33 | env.setRange(1, 0); 34 | 35 | // p5.Amplitude will analyze all sound in the sketch 36 | // unless the setInput() method is used to specify an input. 37 | analyzer = new p5.Amplitude(); 38 | } 39 | 40 | function draw() { 41 | background(0); 42 | 43 | // get volume reading from the p5.Amplitude analyzer 44 | var level = analyzer.getLevel(); 45 | 46 | // use level to draw a green rectangle 47 | var levelHeight = map(level, 0, .4, 0, height); 48 | fill(100,250,100); 49 | rect(0, height, width, - levelHeight); 50 | } 51 | 52 | function mousePressed() { 53 | env.play(noise); 54 | } 55 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Sound/09_Note_Envelope.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @name Note Envelope 3 | * @description

An Envelope is a series of fades, defined 4 | * as time / value pairs. In this example, the envelope 5 | * will be used to "play" a note by controlling the output 6 | * amplitude of an oscillator.

7 | * The p5.Oscillator sends its output through 8 | * an internal Web Audio GainNode (p5.Oscillator.output). 9 | * By default, that node has a constant value of 0.5. It can 10 | * be reset with the osc.amp() method. Or, in this example, an 11 | * Envelope takes control of that node, turning the amplitude 12 | * up and down like a volume knob.

13 | *

To run this example locally, you will need the 14 | * p5.sound library and a 15 | * sound file.

16 | */ 17 | var osc, envelope, fft; 18 | 19 | var scaleArray = [60, 62, 64, 65, 67, 69, 71, 72]; 20 | var note = 0; 21 | 22 | function setup() { 23 | createCanvas(710, 200); 24 | osc = new p5.SinOsc(); 25 | 26 | // Instantiate the envelope 27 | envelope = new p5.Env(); 28 | 29 | // set attackTime, decayTime, sustainRatio, releaseTime 30 | envelope.setADSR(0.001, 0.5, 0.1, 0.5); 31 | 32 | // set attackLevel, releaseLevel 33 | envelope.setRange(1, 0); 34 | 35 | osc.start(); 36 | 37 | fft = new p5.FFT(); 38 | noStroke(); 39 | } 40 | 41 | function draw() { 42 | background(20); 43 | 44 | if (frameCount % 60 == 0 || frameCount == 1) { 45 | var midiValue = scaleArray[note]; 46 | var freqValue = midiToFreq(midiValue); 47 | osc.freq(freqValue); 48 | 49 | envelope.play(osc, 0, 0.1); 50 | note = (note + 1) % scaleArray.length; 51 | } 52 | 53 | // plot FFT.analyze() frequency analysis on the canvas 54 | var spectrum = fft.analyze(); 55 | for (var i = 0; i < spectrum.length/20; i++) { 56 | fill(spectrum[i], spectrum[i]/10, 0); 57 | var x = map(i, 0, spectrum.length/20, 0, width); 58 | var h = map(spectrum[i], 0, 255, 0, height); 59 | rect(x, height, spectrum.length/20, -h); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Sound/10_Oscillator_Waveform.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Oscillator Frequency 3 | * @description

Control an Oscillator and view the waveform using FFT. 4 | * MouseX is mapped to frequency, mouseY is mapped to amplitude.

5 | *

To run this example locally, you will need the 6 | * p5.sound library and a 7 | * sound file.

8 | */ 9 | var osc, fft; 10 | 11 | function setup() { 12 | createCanvas(720, 256); 13 | 14 | osc = new p5.TriOsc(); // set frequency and type 15 | osc.amp(.5); 16 | 17 | fft = new p5.FFT(); 18 | osc.start(); 19 | } 20 | 21 | function draw() { 22 | background(255); 23 | 24 | var waveform = fft.waveform(); // analyze the waveform 25 | beginShape(); 26 | strokeWeight(5); 27 | for (var i = 0; i < waveform.length; i++){ 28 | var x = map(i, 0, waveform.length, 0, width); 29 | var y = map(waveform[i], -1, 1, height, 0); 30 | vertex(x, y); 31 | } 32 | endShape(); 33 | 34 | // change oscillator frequency based on mouseX 35 | var freq = map(mouseX, 0, width, 40, 880); 36 | osc.freq(freq); 37 | 38 | var amp = map(mouseY, 0, height, 1, .01); 39 | osc.amp(amp); 40 | } 41 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Sound/11_Live_Input.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @name Mic Input 3 | * @description

Get audio input from your computer's microphone. 4 | * Make noise to float the ellipse.

5 | *

Note: p5.AudioIn contains its own p5.Amplitude object, 6 | * so you can call getLevel on p5.AudioIn without 7 | * creating a p5.Amplitude.

8 | *

To run this example locally, you will need the 9 | * p5.sound library 10 | * and a running local server.

11 | */ 12 | var mic; 13 | 14 | function setup() { 15 | createCanvas(710, 200); 16 | 17 | // Create an Audio input 18 | mic = new p5.AudioIn(); 19 | 20 | // start the Audio Input. 21 | // By default, it does not .connect() (to the computer speakers) 22 | mic.start(); 23 | } 24 | 25 | function draw() { 26 | background(200); 27 | 28 | // Get the overall volume (between 0 and 1.0) 29 | var vol = mic.getLevel(); 30 | fill(127); 31 | stroke(0); 32 | 33 | // Draw an ellipse with height based on volume 34 | var h = map(vol, 0, 1, height, 0); 35 | ellipse(width/2, h - 25, 50, 50); 36 | } 37 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Sound/12_FFT_Spectrum.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @name Frequency Spectrum 3 | * @description

Visualize the frequency spectrum of live audio input.

4 | *

To run this example locally, you will need the 5 | * p5.sound library 6 | * and a running local server.

7 | */ 8 | var mic, fft; 9 | 10 | function setup() { 11 | createCanvas(710,400); 12 | noFill(); 13 | 14 | mic = new p5.AudioIn(); 15 | mic.start(); 16 | fft = new p5.FFT(); 17 | fft.setInput(mic); 18 | } 19 | 20 | function draw() { 21 | background(200); 22 | 23 | var spectrum = fft.analyze(); 24 | 25 | beginShape(); 26 | for (i = 0; iTrigger an event (draw a rectangle) when the Audio Input 4 | * volume surpasses a threshold.

5 | *

To run this example locally, you will need the 6 | * p5.sound library 7 | * and a running local server.

8 | */ 9 | // Adapted from Learning Processing, Daniel Shiffman 10 | // learningprocessing.com 11 | var input; 12 | var analyzer; 13 | 14 | function setup() { 15 | createCanvas(710, 200); 16 | background(255); 17 | 18 | // Create an Audio input 19 | input = new p5.AudioIn(); 20 | 21 | input.start(); 22 | } 23 | 24 | function draw() { 25 | // Get the overall volume (between 0 and 1.0) 26 | var volume = input.getLevel(); 27 | 28 | // If the volume > 0.1, a rect is drawn at a random location. 29 | // The louder the volume, the larger the rectangle. 30 | var threshold = 0.1; 31 | if (volume > threshold) { 32 | stroke(0); 33 | fill(0, 100); 34 | rect(random(40, width), random(height), volume*50, volume*50); 35 | } 36 | 37 | // Graph the overall potential volume, w/ a line at the threshold 38 | var y = map(volume, 0, 1, height, 0); 39 | var ythreshold = map(threshold, 0, 1, height, 0); 40 | 41 | noStroke(); 42 | fill(175); 43 | rect(0, 0, 20, height); 44 | // Then draw a rectangle on the graph, sized according to volume 45 | fill(0); 46 | rect(0, y, 20, y); 47 | stroke(0); 48 | line(0, ythreshold, 19, ythreshold); 49 | } 50 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Sound/14_Filter_LowPass.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @name Filter LowPass 3 | * @description Apply a p5.LowPass filter to a p5.SoundFile. 4 | * Visualize the sound with FFT. 5 | * Map mouseX to the the filter's cutoff frequency 6 | * and mouseY to resonance/width of the a BandPass filter 7 | * 8 | *

To run this example locally, you will need the 9 | * p5.sound library 10 | * a sound file, and a running local server.

11 | */ 12 | var soundFile; 13 | var fft; 14 | 15 | var filter, filterFreq, filterRes; 16 | 17 | function preload() { 18 | soundFormats('mp3', 'ogg'); 19 | soundFile = loadSound('assets/beat'); 20 | } 21 | 22 | function setup() { 23 | createCanvas(710, 256); 24 | fill(255, 40, 255); 25 | 26 | // loop the sound file 27 | soundFile.loop(); 28 | 29 | filter = new p5.LowPass(); 30 | 31 | // Disconnect soundfile from master output. 32 | // Then, connect it to the filter, so that we only hear the filtered sound 33 | soundFile.disconnect(); 34 | soundFile.connect(filter); 35 | 36 | fft = new p5.FFT(); 37 | } 38 | 39 | function draw() { 40 | background(30); 41 | 42 | // Map mouseX to a the cutoff frequency from the lowest 43 | // frequency (10Hz) to the highest (22050Hz) that humans can hear 44 | filterFreq = map (mouseX, 0, width, 10, 22050); 45 | 46 | // Map mouseY to resonance (volume boost) at the cutoff frequency 47 | filterRes = map(mouseY, 0, height, 15, 5); 48 | 49 | // set filter parameters 50 | filter.set(filterFreq, filterRes); 51 | 52 | // Draw every value in the FFT spectrum analysis where 53 | // x = lowest (10Hz) to highest (22050Hz) frequencies, 54 | // h = energy (amplitude / volume) at that frequency 55 | var spectrum = fft.analyze(); 56 | noStroke(); 57 | for (var i = 0; i< spectrum.length; i++){ 58 | var x = map(i, 0, spectrum.length, 0, width); 59 | var h = -height + map(spectrum[i], 0, 255, height, 0); 60 | rect(x, height, width/spectrum.length, h) ; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Sound/15_Filter_BandPass.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @name Filter BandPass 3 | * @description Apply a p5.BandPass filter to white noise. 4 | * Visualize the sound with FFT. 5 | * Map mouseX to the bandpass frequency 6 | * and mouseY to resonance/width of the a BandPass filter 7 | * 8 | *

To run this example locally, you will need the 9 | * p5.sound library 10 | * a sound file, and a running local server.

11 | */ 12 | var noise; 13 | var fft; 14 | var filter, filterFreq, filterWidth; 15 | 16 | function setup() { 17 | createCanvas(710, 256); 18 | fill(255, 40, 255); 19 | 20 | filter = new p5.BandPass(); 21 | 22 | noise = new p5.Noise(); 23 | 24 | noise.disconnect(); // Disconnect soundfile from master output... 25 | filter.process(noise); // ...and connect to filter so we'll only hear BandPass. 26 | noise.start(); 27 | 28 | fft = new p5.FFT(); 29 | } 30 | 31 | function draw() { 32 | background(30); 33 | 34 | // Map mouseX to a bandpass freq from the FFT spectrum range: 10Hz - 22050Hz 35 | filterFreq = map (mouseX, 0, width, 10, 22050); 36 | // Map mouseY to resonance/width 37 | filterWidth = map(mouseY, 0, height, 0, 90); 38 | // set filter parameters 39 | filter.set(filterFreq, filterWidth); 40 | 41 | // Draw every value in the FFT spectrum analysis where 42 | // x = lowest (10Hz) to highest (22050Hz) frequencies, 43 | // h = energy / amplitude at that frequency 44 | var spectrum = fft.analyze(); 45 | noStroke(); 46 | for (var i = 0; i< spectrum.length; i++){ 47 | var x = map(i, 0, spectrum.length, 0, width); 48 | var h = -height + map(spectrum[i], 0, 255, height, 0); 49 | rect(x, height, width/spectrum.length, h) ; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Sound/16_Delay.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @name Delay 3 | * @description 4 | * Click the mouse to hear the p5.Delay process a SoundFile. 5 | * MouseX controls the p5.Delay Filter Frequency. 6 | * MouseY controls both the p5.Delay Time and Resonance. 7 | * Visualize the resulting sound's volume with an Amplitude object. 8 | * 9 | *

To run this example locally, you will need the 10 | * p5.sound library 11 | * a sound file, and a running local server.

12 | */ 13 | 14 | var soundFile, analyzer, delay; 15 | 16 | function preload() { 17 | soundFormats('ogg', 'mp3'); 18 | soundFile = loadSound('assets/beatbox.mp3'); 19 | } 20 | 21 | function setup() { 22 | createCanvas(710, 400); 23 | 24 | soundFile.disconnect(); // so we'll only hear delay 25 | 26 | delay = new p5.Delay(); 27 | delay.process(soundFile, .12, .7, 2300); 28 | delay.setType('pingPong'); // a stereo effect 29 | 30 | analyzer = new p5.Amplitude(); 31 | } 32 | 33 | function draw() { 34 | background(0); 35 | 36 | // get volume reading from the p5.Amplitude analyzer 37 | var level = analyzer.getLevel(); 38 | 39 | // use level to draw a green rectangle 40 | var levelHeight = map(level, 0, .1, 0, height); 41 | fill(100,250,100); 42 | rect(0, height, width, - levelHeight); 43 | 44 | var filterFreq = map(mouseX, 0, width, 60, 15000); 45 | filterFreq = constrain(filterFreq, 60, 15000); 46 | var filterRes = map(mouseY, 0, height, 3, 0.01); 47 | filterRes = constrain(filterRes, 0.01, 3); 48 | delay.filter(filterFreq, filterRes); 49 | var delTime = map(mouseY, 0, width, .2, .01); 50 | delTime = constrain(delTime, .01, .2); 51 | delay.delayTime(delTime); 52 | } 53 | 54 | function mousePressed() { 55 | soundFile.play(); 56 | } 57 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Sound/17_Reverb.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @name Reverb 3 | * @description Reverb gives depth and perceived space to a sound. Here, 4 | * noise is processed with reverb. 5 | * 6 | *

To run this example locally, you will need the 7 | * p5.sound library 8 | * a sound file, and a running local server.

9 | */ 10 | var sound, reverb; 11 | 12 | function preload() { 13 | soundFormats('mp3', 'ogg'); 14 | soundFile = loadSound('assets/Damscray_DancingTiger'); 15 | 16 | // disconnect the default connection 17 | // so that we only hear the sound via the reverb.process 18 | soundFile.disconnect(); 19 | } 20 | 21 | function setup() { 22 | createCanvas(720,100); 23 | background(0); 24 | 25 | reverb = new p5.Reverb(); 26 | 27 | // sonnects soundFile to reverb with a 28 | // reverbTime of 6 seconds, decayRate of 0.2% 29 | reverb.process(soundFile, 6, 0.2); 30 | 31 | reverb.amp(4); // turn it up! 32 | } 33 | 34 | function mousePressed() { 35 | soundFile.play(); 36 | } 37 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Sound/19_Record_Save.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @name Record Save Audio 3 | * @description Record a sound, play it back and save 4 | * it as a .wav file to the client's computer. 5 | * We need three objects: a p5.AudioIn (mic / sound source), 6 | * p5.SoundRecorder (records the sound), and a 7 | * p5.SoundFile (play back / save). 8 | *

To run this example locally, you will need the 9 | * p5.sound library 10 | * a sound file, and a running local server.

11 | */ 12 | var mic, recorder, soundFile; 13 | 14 | var state = 0; // mousePress will increment from Record, to Stop, to Play 15 | 16 | function setup() { 17 | createCanvas(400,400); 18 | background(200); 19 | fill(0); 20 | text('Enable mic and click the mouse to begin recording', 20, 20); 21 | 22 | // create an audio in 23 | mic = new p5.AudioIn(); 24 | 25 | // users must manually enable their browser microphone for recording to work properly! 26 | mic.start(); 27 | 28 | // create a sound recorder 29 | recorder = new p5.SoundRecorder(); 30 | 31 | // connect the mic to the recorder 32 | recorder.setInput(mic); 33 | 34 | // create an empty sound file that we will use to playback the recording 35 | soundFile = new p5.SoundFile(); 36 | } 37 | 38 | function mousePressed() { 39 | // use the '.enabled' boolean to make sure user enabled the mic (otherwise we'd record silence) 40 | if (state === 0 && mic.enabled) { 41 | 42 | // Tell recorder to record to a p5.SoundFile which we will use for playback 43 | recorder.record(soundFile); 44 | 45 | background(255,0,0); 46 | text('Recording now! Click to stop.', 20, 20); 47 | state++; 48 | } 49 | 50 | else if (state === 1) { 51 | recorder.stop(); // stop recorder, and send the result to soundFile 52 | 53 | background(0,255,0); 54 | text('Recording stopped. Click to play & save', 20, 20); 55 | state++; 56 | } 57 | 58 | else if (state === 2) { 59 | soundFile.play(); // play the result! 60 | saveSound(soundFile, 'mySound.wav'); // save file 61 | state++; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Structure/00_Coordinates.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Coordinates 3 | * @description All shapes drawn to the screen have a position that is 4 | * specified as a coordinate. All coordinates are measured as the distance from 5 | * the origin in units of pixels. The origin [0, 0] is the coordinate in the 6 | * upper left of the window and the coordinate in the lower right is [width-1, 7 | * height-1]. 8 | */ 9 | function setup() { 10 | // Sets the screen to be 640 pixels wide and 360 pixels high 11 | createCanvas(720, 400); 12 | } 13 | 14 | function draw() { 15 | // Set the background to black and turn off the fill color 16 | background(0); 17 | noFill(); 18 | 19 | // The two parameters of the point() method each specify 20 | // coordinates. 21 | // The first parameter is the x-coordinate and the second is the Y 22 | stroke(255); 23 | point(width * 0.5, height * 0.5); 24 | point(width * 0.5, height * 0.25); 25 | 26 | // Coordinates are used for drawing all shapes, not just points. 27 | // Parameters for different functions are used for different 28 | // purposes. For example, the first two parameters to line() 29 | // specify the coordinates of the first endpoint and the second 30 | // two parameters specify the second endpoint 31 | stroke(0, 153, 255); 32 | line(0, height*0.33, width, height*0.33); 33 | 34 | // By default, the first two parameters to rect() are the 35 | // coordinates of the upper-left corner and the second pair 36 | // is the width and height 37 | stroke(255, 153, 0); 38 | rect(width*0.25, height*0.1, width * 0.5, height * 0.8); 39 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Structure/01_Width_and_Height.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Width and Height 3 | * @description The 'width' and 'height' variables contain the 4 | * width and height of the display window as defined in the createCanvas() 5 | * function. 6 | */ 7 | function setup() { 8 | createCanvas(720, 400); 9 | } 10 | 11 | function draw() { 12 | background(127); 13 | noStroke(); 14 | for (var i = 0; i < height; i += 20) { 15 | fill(129, 206, 15); 16 | rect(0, i, width, 10); 17 | fill(255); 18 | rect(i, 0, 10, height); 19 | } 20 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Structure/02_Setup_and_Draw.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Setup and Draw 3 | * @description The code inside the draw() function runs continuously from top 4 | * to bottom until the program is stopped. 5 | */ 6 | var y = 100; 7 | 8 | // The statements in the setup() function 9 | // execute once when the program begins 10 | function setup() { 11 | // createCanvas must be the first statement 12 | createCanvas(720, 400); 13 | stroke(255); // Set line drawing color to white 14 | frameRate(30); 15 | } 16 | // The statements in draw() are executed until the 17 | // program is stopped. Each statement is executed in 18 | // sequence and after the last line is read, the first 19 | // line is executed again. 20 | function draw() { 21 | background(0); // Set the background to black 22 | y = y - 1; 23 | if (y < 0) { 24 | y = height; 25 | } 26 | line(0, y, width, y); 27 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Structure/03_No_Loop.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name No Loop 3 | * @description The noLoop() function causes draw() to only execute once. 4 | * Without calling noLoop(), the code inside draw() is run continually. 5 | */ 6 | var y; 7 | 8 | // The statements in the setup() function 9 | // execute once when the program begins 10 | function setup() 11 | { 12 | // createCanvas should be the first statement 13 | createCanvas(720, 400); 14 | stroke(255); // Set line drawing color to white 15 | noLoop(); 16 | 17 | y = height * 0.5; 18 | } 19 | 20 | // The statements in draw() are executed until the 21 | // program is stopped. Each statement is executed in 22 | // sequence and after the last line is read, the first 23 | // line is executed again. 24 | function draw() 25 | { 26 | background(0); // Set the background to black 27 | y = y - 1; 28 | if (y < 0) { y = height; } 29 | line(0, y, width, y); 30 | } 31 | -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Structure/04_Loop.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Loop 3 | * @description The code inside the draw() function runs continuously from top 4 | * to bottom until the program is stopped. 5 | */ 6 | var y = 100; 7 | 8 | // The statements in the setup() function 9 | // execute once when the program begins 10 | function setup() { 11 | createCanvas(720, 400); // Size must be the first statement 12 | stroke(255); // Set line drawing color to white 13 | frameRate(30); 14 | } 15 | // The statements in draw() are executed until the 16 | // program is stopped. Each statement is executed in 17 | // sequence and after the last line is read, the first 18 | // line is executed again. 19 | function draw() { 20 | background(0); // Set the background to black 21 | y = y - 1; 22 | if (y < 0) { 23 | y = height; 24 | } 25 | line(0, y, width, y); 26 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Structure/05_Redraw.js: -------------------------------------------------------------------------------- 1 | /* 2 | *@name Redraw 3 | *@description The redraw() function makes draw() execute once. In this example, 4 | *draw() is executed once every time the mouse is clicked. 5 | */ 6 | 7 | var y; 8 | 9 | // The statements in the setup() function 10 | // execute once when the program begins 11 | function setup() { 12 | createCanvas(720, 400); 13 | stroke(255); 14 | noLoop(); 15 | y = height * 0.5; 16 | } 17 | 18 | // The statements in draw() are executed until the 19 | // program is stopped. Each statement is executed in 20 | // sequence and after the last line is read, the first 21 | // line is executed again. 22 | function draw() { 23 | background(0); 24 | y = y - 4; 25 | if (y < 0) { 26 | y = height; 27 | } 28 | line(0, y, width, y); 29 | } 30 | 31 | function mousePressed() { 32 | redraw(); 33 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Structure/06_Functions.js: -------------------------------------------------------------------------------- 1 | /* 2 | *@name Functions 3 | *@description The drawTarget() function makes it easy to draw many distinct 4 | *targets. Each call to drawTarget() specifies the position, size, and number of 5 | *rings for each target. 6 | */ 7 | 8 | function setup() { 9 | createCanvas(720, 400); 10 | background(51); 11 | noStroke(); 12 | noLoop(); 13 | } 14 | 15 | function draw() { 16 | drawTarget(width*0.25, height*0.4, 200, 4); 17 | drawTarget(width*0.5, height*0.5, 300, 10); 18 | drawTarget(width*0.75, height*0.3, 120, 6); 19 | } 20 | 21 | function drawTarget(xloc, yloc, size, num) { 22 | grayvalues = 255/num; 23 | steps = size/num; 24 | for (i = 0; i < num; i++) { 25 | fill(i*grayvalues); 26 | ellipse(xloc, yloc, size - i*steps, size - i*steps); 27 | } 28 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Structure/07_Recursion.js: -------------------------------------------------------------------------------- 1 | /* 2 | *@name Recursion 3 | *@description A demonstration of recursion, which means functions call themselves. 4 | * Notice how the drawCircle() function calls itself at the end of its block. 5 | * It continues to do this until the variable "level" is equal to 1. 6 | */ 7 | 8 | function setup() { 9 | createCanvas(720, 400); 10 | noStroke(); 11 | noLoop(); 12 | } 13 | 14 | function draw() { 15 | drawCircle(width/2, 280, 6); 16 | } 17 | 18 | function drawCircle(x, radius, level) { 19 | var tt = 126 * level/4.0; 20 | fill(tt); 21 | ellipse(x, height/2, radius*2, radius*2); 22 | if(level > 1) { 23 | level = level - 1; 24 | drawCircle(x - radius/2, radius/2, level); 25 | drawCircle(x + radius/2, radius/2, level); 26 | } 27 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/examples/Structure/08_Create_Graphics.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name Create Graphics 3 | * @description Creates and returns a new p5.Renderer object. Use this 4 | * class if you need to draw into an off-screen graphics buffer. The two parameters 5 | * define the width and height in pixels. 6 | */ 7 | 8 | var pg; 9 | 10 | function setup(){ 11 | createCanvas(710, 400); 12 | pg = createGraphics(400, 250); 13 | } 14 | 15 | function draw(){ 16 | fill(0, 12); 17 | rect(0, 0, width, height); 18 | fill(255); 19 | noStroke(); 20 | ellipse(mouseX, mouseY, 60, 60); 21 | 22 | pg.background(51); 23 | pg.noFill(); 24 | pg.stroke(255); 25 | pg.ellipse(mouseX-150, mouseY-75, 60, 60); 26 | 27 | //Draw the offscreen buffer to the screen with image() 28 | image(pg, 150, 75); 29 | } -------------------------------------------------------------------------------- /public/mode_assets/p5/server.js: -------------------------------------------------------------------------------- 1 | var serialserver = require('p5.serialserver'); 2 | serialserver.start(); 3 | -------------------------------------------------------------------------------- /public/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "p5", 3 | "version": "0.6.2", 4 | "main": "boot.html", 5 | "window": { 6 | "title": "Untitled", 7 | "toolbar": false, 8 | "frame": true, 9 | "position": "center", 10 | "width": 1024, 11 | "height": 768, 12 | "show": false, 13 | "focus": true, 14 | "resizable": true 15 | }, 16 | "dependencies": { 17 | "chokidar": "1.0.5", 18 | "node-static": "0.7.6", 19 | "p5.serialserver": "0.0.22", 20 | "portscanner": "1.0.0", 21 | "rimraf": "^2.3.4", 22 | "semver": "~3.0.1", 23 | "serialport": "git://github.com/julianduque/node-serialport.git#master", 24 | "trash": "~0.1.2", 25 | "wrench": "~1.5.8" 26 | }, 27 | "devDependencies": { 28 | "request": "^2.58.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /public/serial.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | serial 9 | 10 | -------------------------------------------------------------------------------- /release-howto.md: -------------------------------------------------------------------------------- 1 | # Setup 2 | 3 | 1. Install wine (and xquartz), instructions [here](http://www.davidbaumgold.com/tutorials/wine-mac/). 4 | 5 | # How to make a release 6 | 7 | First, it's a good idea to download the latest build of p5, examples & offline reference: 8 | 9 | ``` 10 | gulp p5 11 | gulp getExamples 12 | gulp getOfflineReference 13 | ``` 14 | 15 | Update the version number in `package.json` and `public/package.json` 16 | ``` 17 | "version": "0.5.7", 18 | ``` 19 | 20 | **Very important: do NOT push to master yet!** 21 | 22 | Next, run the build task. 23 | 24 | ``` 25 | gulp build 26 | ``` 27 | This should create a new folder `dist/p5 - v[VERSION_NUMBER]` with your build. Test it out and make sure that nothing is busted. Things that should always be tested manually are: 28 | * playing mp4s/mp3s 29 | * serial communication 30 | * the version number in the about window 31 | 32 | Zip the release: 33 | ``` 34 | gulp latest 35 | ``` 36 | This will create zip files of the Mac and Windows releases and put them in `dist/latest`. 37 | 38 | Then, make a new release on github. 39 | 40 | * Make the tag look like this: `v0.5.8` 41 | * And the title look like this: `p5.js Editor v0.5.8` 42 | * Upload the zips to the release 43 | * Save 44 | 45 | Finally, push to github. Again, it's very important that you only push AFTER you make the release. The editor reads the version number from github to determine when users should be prompted to download a new version. There is probably a smarter way to do this, but that's how it works now. 46 | 47 | 48 | 49 | 50 | --------------------------------------------------------------------------------