HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div id="gs" class="test">greensock</div>
<div id="p5" class="test">p5.js</div>
.test {
top: 0;
left: 10;
width: 100px;
height: 100px;
position: absolute;
background-color: rgb(255,0,0);
}
#gs {}
#p5 {
top: 120px;
}
/*--------------------*/
/*! p5.js v0.4.4 April 12, 2015 */
/*patched by jedierikb to include pull request #615 */
(function (root, factory) {
if (typeof define === 'function' && define.amd)
define('p5', [], function () { return (root.returnExportsGlobal = factory());});
else if (typeof exports === 'object')
module.exports = factory();
else
root['p5'] = factory();
}(this, function () {
var amdclean = {};
amdclean['shim'] = function (require) {
window.requestDraw = function () {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback, element) {
window.setTimeout(callback, 1000 / 60);
};
}();
}({});
amdclean['constants'] = function (require) {
var PI = Math.PI;
return {
ARROW: 'default',
CROSS: 'crosshair',
HAND: 'pointer',
MOVE: 'move',
TEXT: 'text',
WAIT: 'wait',
HALF_PI: PI / 2,
PI: PI,
QUARTER_PI: PI / 4,
TAU: PI * 2,
TWO_PI: PI * 2,
DEGREES: 'degrees',
RADIANS: 'radians',
CORNER: 'corner',
CORNERS: 'corners',
RADIUS: 'radius',
RIGHT: 'right',
LEFT: 'left',
CENTER: 'center',
TOP: 'top',
BOTTOM: 'bottom',
BASELINE: 'alphabetic',
POINTS: 'points',
LINES: 'lines',
TRIANGLES: 'triangles',
TRIANGLE_FAN: 'triangles_fan',
TRIANGLE_STRIP: 'triangles_strip',
QUADS: 'quads',
QUAD_STRIP: 'quad_strip',
CLOSE: 'close',
OPEN: 'open',
CHORD: 'chord',
PIE: 'pie',
PROJECT: 'square',
SQUARE: 'butt',
ROUND: 'round',
BEVEL: 'bevel',
MITER: 'miter',
RGB: 'rgb',
HSB: 'hsb',
AUTO: 'auto',
ALT: 18,
BACKSPACE: 8,
CONTROL: 17,
DELETE: 46,
DOWN_ARROW: 40,
ENTER: 13,
ESCAPE: 27,
LEFT_ARROW: 37,
OPTION: 18,
RETURN: 13,
RIGHT_ARROW: 39,
SHIFT: 16,
TAB: 9,
UP_ARROW: 38,
BLEND: 'normal',
ADD: 'lighter',
DARKEST: 'darken',
LIGHTEST: 'lighten',
DIFFERENCE: 'difference',
EXCLUSION: 'exclusion',
MULTIPLY: 'multiply',
SCREEN: 'screen',
REPLACE: 'source-over',
OVERLAY: 'overlay',
HARD_LIGHT: 'hard-light',
SOFT_LIGHT: 'soft-light',
DODGE: 'color-dodge',
BURN: 'color-burn',
THRESHOLD: 'threshold',
GRAY: 'gray',
OPAQUE: 'opaque',
INVERT: 'invert',
POSTERIZE: 'posterize',
DILATE: 'dilate',
ERODE: 'erode',
BLUR: 'blur',
NORMAL: 'normal',
ITALIC: 'italic',
BOLD: 'bold',
LINEAR: 'linear',
QUADRATIC: 'quadratic',
BEZIER: 'bezier',
CURVE: 'curve'
};
}({});
amdclean['core'] = function (require, shim, constants) {
'use strict';
var constants = constants;
var p5 = function (sketch, node, sync) {
if (arguments.length === 2 && typeof node === 'boolean') {
sync = node;
node = undefined;
}
this._setupDone = false;
this._pixelDensity = window.devicePixelRatio || 1;
this._startTime = new Date().getTime();
this._userNode = node;
this._curElement = null;
this._elements = [];
this._preloadCount = 0;
this._updateInterval = 0;
this._isGlobal = false;
this._loop = true;
this._styles = [];
this._defaultCanvasSize = {
width: 100,
height: 100
};
this._events = {
'mousemove': null,
'mousedown': null,
'mouseup': null,
'click': null,
'mouseover': null,
'mouseout': null,
'keydown': null,
'keyup': null,
'keypress': null,
'touchstart': null,
'touchmove': null,
'touchend': null,
'resize': null,
'blur': null
};
if (window.DeviceOrientationEvent) {
this._events.deviceorientation = null;
} else if (window.DeviceMotionEvent) {
this._events.devicemotion = null;
} else {
this._events.MozOrientation = null;
}
if (/Firefox/i.test(navigator.userAgent)) {
this._events.DOMMouseScroll = null;
} else {
this._events.mousewheel = null;
}
this._loadingScreenId = 'p5_loading';
this._start = function () {
if (this._userNode) {
if (typeof this._userNode === 'string') {
this._userNode = document.getElementById(this._userNode);
}
}
this._loadingScreen = document.getElementById(this._loadingScreenId);
if (!this._loadingScreen) {
this._loadingScreen = document.createElement('loadingDiv');
this._loadingScreen.innerHTML = 'loading...';
this._loadingScreen.style.position = 'absolute';
var node = this._userNode || document.body;
node.appendChild(this._loadingScreen);
}
this.createCanvas(this._defaultCanvasSize.width, this._defaultCanvasSize.height, true);
var userPreload = this.preload || window.preload;
var context = this._isGlobal ? window : this;
if (userPreload) {
this._preloadMethods.forEach(function (f) {
context[f] = function () {
var argsArray = Array.prototype.slice.call(arguments);
return context._preload(f, argsArray);
};
});
userPreload();
if (this._preloadCount === 0) {
this._setup();
this._runFrames();
this._draw();
}
} else {
this._setup();
this._runFrames();
this._draw();
}
}.bind(this);
this._preload = function (func, args) {
var context = this._isGlobal ? window : this;
context._setProperty('_preloadCount', context._preloadCount + 1);
var preloadCallback = function (resp) {
context._setProperty('_preloadCount', context._preloadCount - 1);
if (context._preloadCount === 0) {
context._setup();
context._runFrames();
context._draw();
}
};
args.push(preloadCallback);
return p5.prototype[func].apply(context, args);
}.bind(this);
this._setup = function () {
var context = this._isGlobal ? window : this;
if (typeof context.preload === 'function') {
this._preloadMethods.forEach(function (f) {
context[f] = p5.prototype[f];
});
}
if (typeof context.setup === 'function') {
context.setup();
}
this.canvas.style.visibility = '';
this.canvas.className = this.canvas.className.replace('p5_hidden', '');
this._setupDone = true;
this._loadingScreen.parentNode.removeChild(this._loadingScreen);
}.bind(this);
this._draw = function () {
var now = new Date().getTime();
this._frameRate = 1000 / (now - this._lastFrameTime);
this._lastFrameTime = now;
this._setProperty('frameCount', this.frameCount + 1);
if (this._loop) {
if (this._drawInterval) {
clearInterval(this._drawInterval);
}
this._drawInterval = setTimeout(function () {
window.requestDraw(this._draw.bind(this));
}.bind(this), 1000 / this._targetFrameRate);
}
this.redraw();
this._updatePAccelerations();
this._updatePMouseCoords();
this._updatePTouchCoords();
}.bind(this);
this._runFrames = function () {
if (this._updateInterval) {
clearInterval(this._updateInterval);
}
}.bind(this);
this._setProperty = function (prop, value) {
this[prop] = value;
if (this._isGlobal) {
window[prop] = value;
}
}.bind(this);
this.remove = function () {
if (this._curElement) {
this._loop = false;
if (this._drawInterval) {
clearTimeout(this._drawInterval);
}
if (this._updateInterval) {
clearTimeout(this._updateInterval);
}
for (var ev in this._events) {
window.removeEventListener(ev, this._events[ev]);
}
for (var i = 0; i < this._elements.length; i++) {
var e = this._elements[i];
if (e.elt.parentNode) {
e.elt.parentNode.removeChild(e.elt);
}
for (var elt_ev in e._events) {
e.elt.removeEventListener(elt_ev, e._events[elt_ev]);
}
}
var self = this;
this._registeredMethods.remove.forEach(function (f) {
if (typeof f !== 'undefined') {
f.call(self);
}
});
if (this._isGlobal) {
for (var p in p5.prototype) {
try {
delete window[p];
} catch (x) {
window[p] = undefined;
}
}
for (var p2 in this) {
if (this.hasOwnProperty(p2)) {
try {
delete window[p2];
} catch (x) {
window[p2] = undefined;
}
}
}
}
}
}.bind(this);
for (var k in constants) {
p5.prototype[k] = constants[k];
}
if (!sketch) {
this._isGlobal = true;
for (var p in p5.prototype) {
if (typeof p5.prototype[p] === 'function') {
var ev = p.substring(2);
if (!this._events.hasOwnProperty(ev)) {
window[p] = p5.prototype[p].bind(this);
}
} else {
window[p] = p5.prototype[p];
}
}
for (var p2 in this) {
if (this.hasOwnProperty(p2)) {
window[p2] = this[p2];
}
}
} else {
sketch(this);
}
for (var e in this._events) {
var f = this['_on' + e];
if (f) {
var m = f.bind(this);
window.addEventListener(e, m);
this._events[e] = m;
}
}
var self = this;
window.addEventListener('focus', function () {
self._setProperty('focused', true);
});
window.addEventListener('blur', function () {
self._setProperty('focused', false);
});
if (sync) {
this._start();
} else {
if (document.readyState === 'complete') {
this._start();
} else {
window.addEventListener('load', this._start.bind(this), false);
}
}
};
p5.prototype._preloadMethods = [
'loadJSON',
'loadImage',
'loadStrings',
'loadXML',
'loadShape',
'loadTable'
];
p5.prototype._registeredMethods = {
pre: [],
post: [],
remove: []
};
p5.prototype.registerPreloadMethod = function (m) {
p5.prototype._preloadMethods.push(m);
}.bind(this);
p5.prototype.registerMethod = function (name, m) {
if (!p5.prototype._registeredMethods.hasOwnProperty(name)) {
p5.prototype._registeredMethods[name] = [];
}
p5.prototype._registeredMethods[name].push(m);
}.bind(this);
return p5;
}({}, amdclean['shim'], amdclean['constants']);
amdclean['utilscolor_utils'] = function (require, core) {
var p5 = core;
p5.ColorUtils = {};
p5.ColorUtils.hsbaToRGBA = function (hsba) {
var h = hsba[0];
var s = hsba[1];
var v = hsba[2];
h /= 255;
s /= 255;
v /= 255;
var RGBA = [];
if (s === 0) {
RGBA = [
Math.round(v * 255),
Math.round(v * 255),
Math.round(v * 255),
hsba[3]
];
} else {
var var_h = h * 6;
if (var_h === 6) {
var_h = 0;
}
var var_i = Math.floor(var_h);
var var_1 = v * (1 - s);
var var_2 = v * (1 - s * (var_h - var_i));
var var_3 = v * (1 - s * (1 - (var_h - var_i)));
var var_r;
var var_g;
var var_b;
if (var_i === 0) {
var_r = v;
var_g = var_3;
var_b = var_1;
} else if (var_i === 1) {
var_r = var_2;
var_g = v;
var_b = var_1;
} else if (var_i === 2) {
var_r = var_1;
var_g = v;
var_b = var_3;
} else if (var_i === 3) {
var_r = var_1;
var_g = var_2;
var_b = v;
} else if (var_i === 4) {
var_r = var_3;
var_g = var_1;
var_b = v;
} else {
var_r = v;
var_g = var_1;
var_b = var_2;
}
RGBA = [
Math.round(var_r * 255),
Math.round(var_g * 255),
Math.round(var_b * 255),
hsba[3]
];
}
return RGBA;
};
p5.ColorUtils.rgbaToHSBA = function (rgba) {
var var_R = rgba[0] / 255;
var var_G = rgba[1] / 255;
var var_B = rgba[2] / 255;
var var_Min = Math.min(var_R, var_G, var_B);
var var_Max = Math.max(var_R, var_G, var_B);
var del_Max = var_Max - var_Min;
var H;
var S;
var V = var_Max;
if (del_Max === 0) {
H = 0;
S = 0;
} else {
S = del_Max / var_Max;
var del_R = ((var_Max - var_R) / 6 + del_Max / 2) / del_Max;
var del_G = ((var_Max - var_G) / 6 + del_Max / 2) / del_Max;
var del_B = ((var_Max - var_B) / 6 + del_Max / 2) / del_Max;
if (var_R === var_Max) {
H = del_B - del_G;
} else if (var_G === var_Max) {
H = 1 / 3 + del_R - del_B;
} else if (var_B === var_Max) {
H = 2 / 3 + del_G - del_R;
}
if (H < 0) {
H += 1;
}
if (H > 1) {
H -= 1;
}
}
return [
Math.round(H * 255),
Math.round(S * 255),
Math.round(V * 255),
rgba[3]
];
};
return p5.ColorUtils;
}({}, amdclean['core']);
amdclean['p5Color'] = function (require, core, utilscolor_utils, constants) {
var p5 = core;
var color_utils = utilscolor_utils;
var constants = constants;
p5.Color = function (pInst, vals) {
this.color_array = p5.Color._getFormattedColor.apply(pInst, vals);
this._normalizeColorArray(pInst);
if (pInst._colorMode === constants.HSB) {
this.hsba = this.color_array;
this.rgba = color_utils.hsbaToRGBA(this.hsba);
} else {
this.rgba = this.color_array;
this.hsba = color_utils.rgbaToHSBA(this.rgba);
}
return this;
};
p5.Color.prototype._normalizeColorArray = function (pInst) {
var isRGB = pInst._colorMode === constants.RGB;
var maxArr = isRGB ? pInst._maxRGB : pInst._maxHSB;
var arr = this.color_array;
arr[0] *= 255 / maxArr[0];
arr[1] *= 255 / maxArr[1];
arr[2] *= 255 / maxArr[2];
arr[3] *= 255 / maxArr[3];
return arr;
};
p5.Color.prototype.getHue = function () {
return this.hsba[0];
};
p5.Color.prototype.getSaturation = function () {
return this.hsba[1];
};
p5.Color.prototype.getBrightness = function () {
return this.hsba[2];
};
p5.Color.prototype.getRed = function () {
return this.rgba[0];
};
p5.Color.prototype.getGreen = function () {
return this.rgba[1];
};
p5.Color.prototype.getBlue = function () {
return this.rgba[2];
};
p5.Color.prototype.getAlpha = function () {
return this.rgba[3];
};
p5.Color.prototype.toString = function () {
var a = this.rgba;
for (var i = 0; i < 3; i++) {
a[i] = Math.floor(a[i]);
}
var alpha = typeof a[3] !== 'undefined' ? a[3] / 255 : 1;
return 'rgba(' + a[0] + ',' + a[1] + ',' + a[2] + ',' + alpha + ')';
};
var WHITESPACE = /\s*/;
var INTEGER = /(\d{1,3})/;
var DECIMAL = /((?:\d+(?:\.\d+)?)|(?:\.\d+))/;
var PERCENT = new RegExp(DECIMAL.source + '%');
var namedColors = {
aliceblue: '#f0f8ff',
antiquewhite: '#faebd7',
aqua: '#00ffff',
aquamarine: '#7fffd4',
azure: '#f0ffff',
beige: '#f5f5dc',
bisque: '#ffe4c4',
black: '#000000',
blanchedalmond: '#ffebcd',
blue: '#0000ff',
blueviolet: '#8a2be2',
brown: '#a52a2a',
burlywood: '#deb887',
cadetblue: '#5f9ea0',
chartreuse: '#7fff00',
chocolate: '#d2691e',
coral: '#ff7f50',
cornflowerblue: '#6495ed',
cornsilk: '#fff8dc',
crimson: '#dc143c',
cyan: '#00ffff',
darkblue: '#00008b',
darkcyan: '#008b8b',
darkgoldenrod: '#b8860b',
darkgray: '#a9a9a9',
darkgreen: '#006400',
darkgrey: '#a9a9a9',
darkkhaki: '#bdb76b',
darkmagenta: '#8b008b',
darkolivegreen: '#556b2f',
darkorange: '#ff8c00',
darkorchid: '#9932cc',
darkred: '#8b0000',
darksalmon: '#e9967a',
darkseagreen: '#8fbc8f',
darkslateblue: '#483d8b',
darkslategray: '#2f4f4f',
darkslategrey: '#2f4f4f',
darkturquoise: '#00ced1',
darkviolet: '#9400d3',
deeppink: '#ff1493',
deepskyblue: '#00bfff',
dimgray: '#696969',
dimgrey: '#696969',
dodgerblue: '#1e90ff',
firebrick: '#b22222',
floralwhite: '#fffaf0',
forestgreen: '#228b22',
fuchsia: '#ff00ff',
gainsboro: '#dcdcdc',
ghostwhite: '#f8f8ff',
gold: '#ffd700',
goldenrod: '#daa520',
gray: '#808080',
green: '#008000',
greenyellow: '#adff2f',
grey: '#808080',
honeydew: '#f0fff0',
hotpink: '#ff69b4',
indianred: '#cd5c5c',
indigo: '#4b0082',
ivory: '#fffff0',
khaki: '#f0e68c',
lavender: '#e6e6fa',
lavenderblush: '#fff0f5',
lawngreen: '#7cfc00',
lemonchiffon: '#fffacd',
lightblue: '#add8e6',
lightcoral: '#f08080',
lightcyan: '#e0ffff',
lightgoldenrodyellow: '#fafad2',
lightgray: '#d3d3d3',
lightgreen: '#90ee90',
lightgrey: '#d3d3d3',
lightpink: '#ffb6c1',
lightsalmon: '#ffa07a',
lightseagreen: '#20b2aa',
lightskyblue: '#87cefa',
lightslategray: '#778899',
lightslategrey: '#778899',
lightsteelblue: '#b0c4de',
lightyellow: '#ffffe0',
lime: '#00ff00',
limegreen: '#32cd32',
linen: '#faf0e6',
magenta: '#ff00ff',
maroon: '#800000',
mediumaquamarine: '#66cdaa',
mediumblue: '#0000cd',
mediumorchid: '#ba55d3',
mediumpurple: '#9370db',
mediumseagreen: '#3cb371',
mediumslateblue: '#7b68ee',
mediumspringgreen: '#00fa9a',
mediumturquoise: '#48d1cc',
mediumvioletred: '#c71585',
midnightblue: '#191970',
mintcream: '#f5fffa',
mistyrose: '#ffe4e1',
moccasin: '#ffe4b5',
navajowhite: '#ffdead',
navy: '#000080',
oldlace: '#fdf5e6',
olive: '#808000',
olivedrab: '#6b8e23',
orange: '#ffa500',
orangered: '#ff4500',
orchid: '#da70d6',
palegoldenrod: '#eee8aa',
palegreen: '#98fb98',
paleturquoise: '#afeeee',
palevioletred: '#db7093',
papayawhip: '#ffefd5',
peachpuff: '#ffdab9',
peru: '#cd853f',
pink: '#ffc0cb',
plum: '#dda0dd',
powderblue: '#b0e0e6',
purple: '#800080',
red: '#ff0000',
rosybrown: '#bc8f8f',
royalblue: '#4169e1',
saddlebrown: '#8b4513',
salmon: '#fa8072',
sandybrown: '#f4a460',
seagreen: '#2e8b57',
seashell: '#fff5ee',
sienna: '#a0522d',
silver: '#c0c0c0',
skyblue: '#87ceeb',
slateblue: '#6a5acd',
slategray: '#708090',
slategrey: '#708090',
snow: '#fffafa',
springgreen: '#00ff7f',
steelblue: '#4682b4',
tan: '#d2b48c',
teal: '#008080',
thistle: '#d8bfd8',
tomato: '#ff6347',
turquoise: '#40e0d0',
violet: '#ee82ee',
wheat: '#f5deb3',
white: '#ffffff',
whitesmoke: '#f5f5f5',
yellow: '#ffff00',
yellowgreen: '#9acd32'
};
var colorPatterns = {
HEX3: /^#([a-f0-9])([a-f0-9])([a-f0-9])$/i,
HEX6: /^#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i,
RGB: new RegExp([
'^rgb\\(',
INTEGER.source,
',',
INTEGER.source,
',',
INTEGER.source,
'\\)$'
].join(WHITESPACE.source), 'i'),
RGB_PERCENT: new RegExp([
'^rgb\\(',
PERCENT.source,
',',
PERCENT.source,
',',
PERCENT.source,
'\\)$'
].join(WHITESPACE.source), 'i'),
RGBA: new RegExp([
'^rgba\\(',
INTEGER.source,
',',
INTEGER.source,
',',
INTEGER.source,
',',
DECIMAL.source,
'\\)$'
].join(WHITESPACE.source), 'i'),
RGBA_PERCENT: new RegExp([
'^rgba\\(',
PERCENT.source,
',',
PERCENT.source,
',',
PERCENT.source,
',',
DECIMAL.source,
'\\)$'
].join(WHITESPACE.source), 'i')
};
p5.Color._getFormattedColor = function () {
var r, g, b, a, str, vals;
if (arguments.length >= 3) {
r = arguments[0];
g = arguments[1];
b = arguments[2];
a = typeof arguments[3] === 'number' ? arguments[3] : 255;
} else if (typeof arguments[0] === 'string') {
str = arguments[0].trim().toLowerCase();
if (namedColors[str]) {
return p5.Color._getFormattedColor.apply(this, [namedColors[str]]);
}
if (colorPatterns.HEX3.test(str)) {
vals = colorPatterns.HEX3.exec(str).slice(1).map(function (color) {
return parseInt(color + color, 16);
});
} else if (colorPatterns.HEX6.test(str)) {
vals = colorPatterns.HEX6.exec(str).slice(1).map(function (color) {
return parseInt(color, 16);
});
} else if (colorPatterns.RGB.test(str)) {
vals = colorPatterns.RGB.exec(str).slice(1).map(function (color) {
return parseInt(color, 10);
});
} else if (colorPatterns.RGB_PERCENT.test(str)) {
vals = colorPatterns.RGB_PERCENT.exec(str).slice(1).map(function (color) {
return parseInt(parseFloat(color) / 100 * 255, 10);
});
} else if (colorPatterns.RGBA.test(str)) {
vals = colorPatterns.RGBA.exec(str).slice(1).map(function (color, idx) {
if (idx === 3) {
return parseInt(parseFloat(color) * 255, 10);
}
return parseInt(color, 10);
});
} else if (colorPatterns.RGBA_PERCENT.test(str)) {
vals = colorPatterns.RGBA_PERCENT.exec(str).slice(1).map(function (color, idx) {
if (idx === 3) {
return parseInt(parseFloat(color) * 255, 10);
}
return parseInt(parseFloat(color) / 100 * 255, 10);
});
} else {
vals = [255];
}
return p5.Color._getFormattedColor.apply(this, vals);
} else {
if (this._colorMode === constants.RGB) {
r = g = b = arguments[0];
} else {
r = b = arguments[0];
g = 0;
}
a = typeof arguments[1] === 'number' ? arguments[1] : 255;
}
return [
r,
g,
b,
a
];
};
return p5.Color;
}({}, amdclean['core'], amdclean['utilscolor_utils'], amdclean['constants']);
amdclean['p5Element'] = function (require, core) {
var p5 = core;
p5.Element = function (elt, pInst) {
this.elt = elt;
this._pInst = pInst;
this._events = {};
this.width = this.elt.offsetWidth;
this.height = this.elt.offsetHeight;
};
p5.Element.prototype.parent = function (p) {
if (typeof p === 'string') {
p = document.getElementById(p);
} else if (p instanceof p5.Element) {
p = p.elt;
}
p.appendChild(this.elt);
return this;
};
p5.Element.prototype.id = function (id) {
this.elt.id = id;
return this;
};
p5.Element.prototype.class = function (c) {
this.elt.className += ' ' + c;
return this;
};
p5.Element.prototype.mousePressed = function (fxn) {
attachListener('mousedown', fxn, this);
attachListener('touchstart', fxn, this);
return this;
};
p5.Element.prototype.mouseWheel = function (fxn) {
attachListener('mousewheel', fxn, this);
return this;
};
p5.Element.prototype.mouseReleased = function (fxn) {
attachListener('mouseup', fxn, this);
attachListener('touchend', fxn, this);
return this;
};
p5.Element.prototype.mouseClicked = function (fxn) {
attachListener('click', fxn, this);
return this;
};
p5.Element.prototype.mouseMoved = function (fxn) {
attachListener('mousemove', fxn, this);
attachListener('touchmove', fxn, this);
return this;
};
p5.Element.prototype.mouseOver = function (fxn) {
attachListener('mouseover', fxn, this);
return this;
};
p5.Element.prototype.mouseOut = function (fxn) {
attachListener('mouseout', fxn, this);
return this;
};
p5.Element.prototype.touchStarted = function (fxn) {
attachListener('touchstart', fxn, this);
attachListener('mousedown', fxn, this);
return this;
};
p5.Element.prototype.touchMoved = function (fxn) {
attachListener('touchmove', fxn, this);
attachListener('mousemove', fxn, this);
return this;
};
p5.Element.prototype.touchEnded = function (fxn) {
attachListener('touchend', fxn, this);
attachListener('mouseup', fxn, this);
return this;
};
p5.Element.prototype.dragOver = function (fxn) {
attachListener('dragover', fxn, this);
return this;
};
p5.Element.prototype.dragLeave = function (fxn) {
attachListener('dragleave', fxn, this);
return this;
};
p5.Element.prototype.drop = function (callback, fxn) {
function makeLoader(theFile) {
var p5file = new p5.File(theFile);
return function (e) {
p5file.data = e.target.result;
callback(p5file);
};
}
if (window.File && window.FileReader && window.FileList && window.Blob) {
attachListener('dragover', function (evt) {
evt.stopPropagation();
evt.preventDefault();
}, this);
attachListener('dragleave', function (evt) {
evt.stopPropagation();
evt.preventDefault();
}, this);
if (arguments.length > 1) {
attachListener('drop', fxn, this);
}
attachListener('drop', function (evt) {
evt.stopPropagation();
evt.preventDefault();
var files = evt.dataTransfer.files;
for (var i = 0; i < files.length; i++) {
var f = files[i];
var reader = new FileReader();
reader.onload = makeLoader(f);
if (f.type === 'text') {
reader.readAsText(f);
} else {
reader.readAsDataURL(f);
}
}
}, this);
} else {
console.log('The File APIs are not fully supported in this browser.');
}
return this;
};
function attachListener(ev, fxn, ctx) {
var f = fxn.bind(ctx);
ctx.elt.addEventListener(ev, f, false);
ctx._events[ev] = f;
}
p5.Element.prototype._setProperty = function (prop, value) {
this[prop] = value;
};
return p5.Element;
}({}, amdclean['core']);
amdclean['p5Graphics'] = function (require, core, constants) {
var p5 = core;
var constants = constants;
p5.Graphics = function (elt, pInst, isMainCanvas) {
p5.Element.call(this, elt, pInst);
this.canvas = elt;
this.drawingContext = this.canvas.getContext('2d');
this._pInst = pInst;
if (isMainCanvas) {
this._isMainCanvas = true;
this._pInst._setProperty('_curElement', this);
this._pInst._setProperty('canvas', this.canvas);
this._pInst._setProperty('drawingContext', this.drawingContext);
this._pInst._setProperty('width', this.width);
this._pInst._setProperty('height', this.height);
} else {
this.canvas.style.display = 'none';
this._styles = [];
}
};
p5.Graphics.prototype = Object.create(p5.Element.prototype);
p5.Graphics.prototype._applyDefaults = function () {
this.drawingContext.fillStyle = '#FFFFFF';
this.drawingContext.strokeStyle = '#000000';
this.drawingContext.lineCap = constants.ROUND;
this.drawingContext.font = 'normal 12px sans-serif';
};
p5.Graphics.prototype.resize = function (w, h) {
this.width = w;
this.height = h;
this.elt.width = w * this._pInst._pixelDensity;
this.elt.height = h * this._pInst._pixelDensity;
this.elt.style.width = w + 'px';
this.elt.style.height = h + 'px';
if (this._isMainCanvas) {
this._pInst._setProperty('width', this.width);
this._pInst._setProperty('height', this.height);
}
this.drawingContext.scale(this._pInst._pixelDensity, this._pInst._pixelDensity);
};
return p5.Graphics;
}({}, amdclean['core'], amdclean['constants']);
amdclean['filters'] = function (require) {
'use strict';
var Filters = {};
Filters._toPixels = function (canvas) {
if (canvas instanceof ImageData) {
return canvas.data;
} else {
return canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height).data;
}
};
Filters._getARGB = function (data, i) {
var offset = i * 4;
return data[offset + 3] << 24 & 4278190080 | data[offset] << 16 & 16711680 | data[offset + 1] << 8 & 65280 | data[offset + 2] & 255;
};
Filters._setPixels = function (pixels, data) {
var offset = 0;
for (var i = 0, al = pixels.length; i < al; i++) {
offset = i * 4;
pixels[offset + 0] = (data[i] & 16711680) >>> 16;
pixels[offset + 1] = (data[i] & 65280) >>> 8;
pixels[offset + 2] = data[i] & 255;
pixels[offset + 3] = (data[i] & 4278190080) >>> 24;
}
};
Filters._toImageData = function (canvas) {
if (canvas instanceof ImageData) {
return canvas;
} else {
return canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height);
}
};
Filters._createImageData = function (width, height) {
Filters._tmpCanvas = document.createElement('canvas');
Filters._tmpCtx = Filters._tmpCanvas.getContext('2d');
return this._tmpCtx.createImageData(width, height);
};
Filters.apply = function (canvas, func, filterParam) {
var ctx = canvas.getContext('2d');
var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
var newImageData = func(imageData, filterParam);
if (newImageData instanceof ImageData) {
ctx.putImageData(newImageData, 0, 0, 0, 0, canvas.width, canvas.height);
} else {
ctx.putImageData(imageData, 0, 0, 0, 0, canvas.width, canvas.height);
}
};
Filters.threshold = function (canvas, level) {
var pixels = Filters._toPixels(canvas);
if (level === undefined) {
level = 0.5;
}
var thresh = Math.floor(level * 255);
for (var i = 0; i < pixels.length; i += 4) {
var r = pixels[i];
var g = pixels[i + 1];
var b = pixels[i + 2];
var grey = 0.2126 * r + 0.7152 * g + 0.0722 * b;
var val;
if (grey >= thresh) {
val = 255;
} else {
val = 0;
}
pixels[i] = pixels[i + 1] = pixels[i + 2] = val;
}
};
Filters.gray = function (canvas) {
var pixels = Filters._toPixels(canvas);
for (var i = 0; i < pixels.length; i += 4) {
var r = pixels[i];
var g = pixels[i + 1];
var b = pixels[i + 2];
var gray = 0.2126 * r + 0.7152 * g + 0.0722 * b;
pixels[i] = pixels[i + 1] = pixels[i + 2] = gray;
}
};
Filters.opaque = function (canvas) {
var pixels = Filters._toPixels(canvas);
for (var i = 0; i < pixels.length; i += 4) {
pixels[i + 3] = 255;
}
return pixels;
};
Filters.invert = function (canvas) {
var pixels = Filters._toPixels(canvas);
for (var i = 0; i < pixels.length; i += 4) {
pixels[i] = 255 - pixels[i];
pixels[i + 1] = 255 - pixels[i + 1];
pixels[i + 2] = 255 - pixels[i + 2];
}
};
Filters.posterize = function (canvas, level) {
var pixels = Filters._toPixels(canvas);
if (level < 2 || level > 255) {
throw new Error('Level must be greater than 2 and less than 255 for posterize');
}
var levels1 = level - 1;
for (var i = 0; i < pixels.length; i += 4) {
var rlevel = pixels[i];
var glevel = pixels[i + 1];
var blevel = pixels[i + 2];
pixels[i] = (rlevel * level >> 8) * 255 / levels1;
pixels[i + 1] = (glevel * level >> 8) * 255 / levels1;
pixels[i + 2] = (blevel * level >> 8) * 255 / levels1;
}
};
Filters.dilate = function (canvas) {
var pixels = Filters._toPixels(canvas);
var currIdx = 0;
var maxIdx = pixels.length ? pixels.length / 4 : 0;
var out = new Int32Array(maxIdx);
var currRowIdx, maxRowIdx, colOrig, colOut, currLum;
var idxRight, idxLeft, idxUp, idxDown, colRight, colLeft, colUp, colDown, lumRight, lumLeft, lumUp, lumDown;
while (currIdx < maxIdx) {
currRowIdx = currIdx;
maxRowIdx = currIdx + canvas.width;
while (currIdx < maxRowIdx) {
colOrig = colOut = Filters._getARGB(pixels, currIdx);
idxLeft = currIdx - 1;
idxRight = currIdx + 1;
idxUp = currIdx - canvas.width;
idxDown = currIdx + canvas.width;
if (idxLeft < currRowIdx) {
idxLeft = currIdx;
}
if (idxRight >= maxRowIdx) {
idxRight = currIdx;
}
if (idxUp < 0) {
idxUp = 0;
}
if (idxD
Also see: Tab Triggers