Skip to content

Commit 0087976

Browse files
committed
merging upstream changes
2 parents 345ed44 + 6212a74 commit 0087976

File tree

17 files changed

+7117
-589
lines changed

17 files changed

+7117
-589
lines changed

docs/js/p5.js

Lines changed: 5098 additions & 0 deletions
Large diffs are not rendered by default.

docs/js/p5.min.js

Lines changed: 153 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! p5.js v0.3.12 December 01, 2014 */
1+
/*! p5.js v0.3.14 December 15, 2014 */
22
var shim = function (require) {
33
window.requestDraw = function () {
44
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback, element) {
@@ -117,7 +117,8 @@ var core = function (require, shim, constants) {
117117
'touchstart': null,
118118
'touchmove': null,
119119
'touchend': null,
120-
'resize': null
120+
'resize': null,
121+
'blur': null
121122
};
122123
this._loadingScreenId = 'p5_loading';
123124
this._start = function () {
@@ -561,6 +562,7 @@ var p5Element = function (require, core) {
561562
};
562563
p5.Element.prototype.mousePressed = function (fxn) {
563564
attachListener('mousedown', fxn, this);
565+
attachListener('touchstart', fxn, this);
564566
return this;
565567
};
566568
p5.Element.prototype.mouseWheel = function (fxn) {
@@ -569,6 +571,7 @@ var p5Element = function (require, core) {
569571
};
570572
p5.Element.prototype.mouseReleased = function (fxn) {
571573
attachListener('mouseup', fxn, this);
574+
attachListener('touchend', fxn, this);
572575
return this;
573576
};
574577
p5.Element.prototype.mouseClicked = function (fxn) {
@@ -577,6 +580,7 @@ var p5Element = function (require, core) {
577580
};
578581
p5.Element.prototype.mouseMoved = function (fxn) {
579582
attachListener('mousemove', fxn, this);
583+
attachListener('touchmove', fxn, this);
580584
return this;
581585
};
582586
p5.Element.prototype.mouseOver = function (fxn) {
@@ -587,6 +591,21 @@ var p5Element = function (require, core) {
587591
attachListener('mouseout', fxn, this);
588592
return this;
589593
};
594+
p5.Element.prototype.touchStarted = function (fxn) {
595+
attachListener('touchstart', fxn, this);
596+
attachListener('mousedown', fxn, this);
597+
return this;
598+
};
599+
p5.Element.prototype.touchMoved = function (fxn) {
600+
attachListener('touchmove', fxn, this);
601+
attachListener('mousemove', fxn, this);
602+
return this;
603+
};
604+
p5.Element.prototype.touchEnded = function (fxn) {
605+
attachListener('touchend', fxn, this);
606+
attachListener('mouseup', fxn, this);
607+
return this;
608+
};
590609
function attachListener(ev, fxn, ctx) {
591610
var f = fxn.bind(ctx);
592611
ctx.elt.addEventListener(ev, f, false);
@@ -1019,11 +1038,11 @@ var p5Image = function (require, core, filters) {
10191038
};
10201039
p5.Image.prototype.resize = function (width, height) {
10211040
width = width || this.canvas.width;
1022-
height = width || this.canvas.height;
1041+
height = height || this.canvas.height;
10231042
var tempCanvas = document.createElement('canvas');
10241043
tempCanvas.width = width;
10251044
tempCanvas.height = height;
1026-
tempCanvas.getContext('2d').drawImage(this.canvas, 0, 0, this.canvas.width, this.canvas.height, 0, 0, tempCanvas.width, tempCanvas.width);
1045+
tempCanvas.getContext('2d').drawImage(this.canvas, 0, 0, this.canvas.width, this.canvas.height, 0, 0, tempCanvas.width, tempCanvas.height);
10271046
this.canvas.width = this.width = width;
10281047
this.canvas.height = this.height = height;
10291048
this.drawingContext.drawImage(tempCanvas, 0, 0, width, height, 0, 0, width, height);
@@ -2105,6 +2124,14 @@ var environment = function (require, core, constants) {
21052124
}
21062125
}
21072126
};
2127+
p5.prototype.devicePixelScaling = function (val) {
2128+
if (val) {
2129+
this._pixelDensity = window.devicePixelRatio || 1;
2130+
} else {
2131+
this._pixelDensity = 1;
2132+
}
2133+
this.resizeCanvas(this.width, this.height);
2134+
};
21082135
function launchFullscreen(element) {
21092136
var enabled = document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled;
21102137
if (!enabled) {
@@ -2129,6 +2156,26 @@ var environment = function (require, core, constants) {
21292156
document.webkitExitFullscreen();
21302157
}
21312158
}
2159+
p5.prototype.getURL = function () {
2160+
return location.href;
2161+
};
2162+
p5.prototype.getURLPath = function () {
2163+
return location.pathname.split('/').filter(function (v) {
2164+
return v !== '';
2165+
});
2166+
};
2167+
p5.prototype.getURLParams = function () {
2168+
var re = /[?&]([^&=]+)(?:[&=])([^&=]+)/gim;
2169+
var m;
2170+
var v = {};
2171+
while ((m = re.exec(location.search)) != null) {
2172+
if (m.index === re.lastIndex) {
2173+
re.lastIndex++;
2174+
}
2175+
v[m[1]] = m[2];
2176+
}
2177+
return v;
2178+
};
21322179
return p5;
21332180
}({}, core, constants);
21342181
var imageimage = function (require, core, constants) {
@@ -2322,7 +2369,8 @@ var imagepixels = function (require, core, filters, p5Color) {
23222369
} else {
23232370
throw new Error('Signature not supported');
23242371
}
2325-
this.drawingContext.drawImage(srcImage.canvas, sx, sy, sw, sh, dx, dy, dw, dh);
2372+
var s = srcImage.canvas.width / srcImage.width;
2373+
this.drawingContext.drawImage(srcImage.canvas, s * sx, s * sy, s * sw, s * sh, dx, dy, dw, dh);
23262374
};
23272375
p5.prototype.filter = function (operation, value) {
23282376
Filters.apply(this.canvas, Filters[operation.toLowerCase()], value);
@@ -2995,12 +3043,68 @@ var inputfiles = function (require, core, reqwest) {
29953043
p5.prototype.selectInput = function () {
29963044
throw 'not yet implemented';
29973045
};
3046+
p5.prototype.httpGet = function () {
3047+
var args = Array.prototype.slice.call(arguments);
3048+
args.push('GET');
3049+
p5.prototype.httpDo.apply(this, args);
3050+
};
3051+
p5.prototype.httpPost = function () {
3052+
var args = Array.prototype.slice.call(arguments);
3053+
args.push('POST');
3054+
p5.prototype.httpDo.apply(this, args);
3055+
};
3056+
p5.prototype.httpDo = function () {
3057+
var method = 'GET';
3058+
var path = arguments[0];
3059+
var data = {};
3060+
var type = '';
3061+
var callback;
3062+
for (var i = 1; i < arguments.length; i++) {
3063+
var a = arguments[i];
3064+
if (typeof a === 'string') {
3065+
if (a === 'GET' || a === 'POST' || a === 'PUT') {
3066+
method = a;
3067+
} else {
3068+
type = a;
3069+
}
3070+
} else if (typeof a === 'object') {
3071+
data = a;
3072+
} else if (typeof a === 'function') {
3073+
callback = a;
3074+
}
3075+
}
3076+
if (type === '') {
3077+
if (path.indexOf('json') !== -1) {
3078+
type = 'json';
3079+
} else if (path.indexOf('xml') !== -1) {
3080+
type = 'xml';
3081+
} else {
3082+
type = 'text';
3083+
}
3084+
}
3085+
reqwest({
3086+
url: path,
3087+
method: method,
3088+
data: data,
3089+
type: type,
3090+
crossOrigin: true,
3091+
success: function (resp) {
3092+
if (typeof callback !== 'undefined') {
3093+
if (type === 'text') {
3094+
callback(resp.response);
3095+
} else {
3096+
callback(resp);
3097+
}
3098+
}
3099+
}
3100+
});
3101+
};
29983102
return p5;
29993103
}({}, core, reqwest);
30003104
var inputkeyboard = function (require, core) {
30013105
'use strict';
30023106
var p5 = core;
3003-
p5.prototype._downKeys = [];
3107+
var downKeys = {};
30043108
p5.prototype.isKeyPressed = false;
30053109
p5.prototype.keyIsPressed = false;
30063110
p5.prototype.key = '';
@@ -3009,9 +3113,7 @@ var inputkeyboard = function (require, core) {
30093113
this._setProperty('isKeyPressed', true);
30103114
this._setProperty('keyIsPressed', true);
30113115
this._setProperty('keyCode', e.which);
3012-
if (this._downKeys.indexOf(e.which) < 0) {
3013-
this._downKeys.push(e.which);
3014-
}
3116+
downKeys[e.which] = true;
30153117
var key = String.fromCharCode(e.which);
30163118
if (!key) {
30173119
key = e.which;
@@ -3029,9 +3131,7 @@ var inputkeyboard = function (require, core) {
30293131
var keyReleased = this.keyReleased || window.keyReleased;
30303132
this._setProperty('isKeyPressed', false);
30313133
this._setProperty('keyIsPressed', false);
3032-
if (this._downKeys.indexOf(e.which) >= 0) {
3033-
this._downKeys.splice(this._downKeys.indexOf(e.which), 1);
3034-
}
3134+
downKeys[e.which] = false;
30353135
var key = String.fromCharCode(e.which);
30363136
if (!key) {
30373137
key = e.which;
@@ -3056,8 +3156,11 @@ var inputkeyboard = function (require, core) {
30563156
}
30573157
}
30583158
};
3159+
p5.prototype.onblur = function (e) {
3160+
downKeys = {};
3161+
};
30593162
p5.prototype.keyIsDown = function (code) {
3060-
return this._downKeys.indexOf(code) >= 0;
3163+
return downKeys[code];
30613164
};
30623165
return p5;
30633166
}({}, core);
@@ -4099,6 +4202,7 @@ var shape2d_primitives = function (require, core, canvas, constants) {
40994202
var ctx = this.drawingContext;
41004203
var vals = canvas.arcModeAdjust(x, y, width, height, this._ellipseMode);
41014204
var radius = vals.h > vals.w ? vals.h / 2 : vals.w / 2, xScale = vals.h > vals.w ? vals.w / vals.h : 1, yScale = vals.h > vals.w ? 1 : vals.h / vals.w;
4205+
ctx.save();
41024206
ctx.scale(xScale, yScale);
41034207
ctx.beginPath();
41044208
ctx.arc(vals.x, vals.y, radius, start, stop);
@@ -4117,6 +4221,7 @@ var shape2d_primitives = function (require, core, canvas, constants) {
41174221
if (this._doStroke && mode !== constants.OPEN && mode !== undefined) {
41184222
ctx.stroke();
41194223
}
4224+
ctx.restore();
41204225
return this;
41214226
};
41224227
p5.prototype.ellipse = function (x, y, w, h) {
@@ -4923,58 +5028,56 @@ var typographyattributes = function (require, core, constants) {
49235028
};
49245029
return p5;
49255030
}({}, core, constants);
4926-
var typographyloading_displaying = function (require, core, canvas) {
5031+
var typographyloading_displaying = function (require, core) {
49275032
'use strict';
49285033
var p5 = core;
4929-
var canvas = canvas;
4930-
p5.prototype.text = function () {
4931-
if (arguments.length === 3) {
4932-
if (this._doFill) {
4933-
this.drawingContext.fillText(arguments[0], arguments[1], arguments[2]);
4934-
}
4935-
if (this._doStroke) {
4936-
this.drawingContext.strokeText(arguments[0], arguments[1], arguments[2]);
4937-
}
4938-
} else if (arguments.length === 5) {
4939-
var words = arguments[0].split(' ');
5034+
p5.prototype.text = function (str, x, y, maxWidth, maxHeight) {
5035+
if (typeof str !== 'string') {
5036+
return;
5037+
}
5038+
if (typeof maxWidth !== 'undefined') {
5039+
y += this._textLeading;
5040+
maxHeight += y;
5041+
}
5042+
str = str.replace(/(\t)/g, ' ');
5043+
var cars = str.split('\n');
5044+
for (var ii = 0; ii < cars.length; ii++) {
49405045
var line = '';
4941-
var vals = canvas.modeAdjust(arguments[1], arguments[2], arguments[3], arguments[4], this._rectMode);
4942-
var y = vals.y + this._textLeading;
5046+
var words = cars[ii].split(' ');
49435047
for (var n = 0; n < words.length; n++) {
4944-
var testLine = line + words[n] + ' ';
4945-
var metrics = this.drawingContext.measureText(testLine);
4946-
var testWidth = metrics.width;
4947-
if (y > vals.y + vals.h) {
4948-
break;
4949-
} else if (testWidth > vals.w && n > 0) {
4950-
if (this._doFill) {
4951-
this.drawingContext.fillText(line, vals.x, y);
4952-
}
4953-
if (this._doStroke) {
4954-
this.drawingContext.strokeText(line, vals.x, y);
5048+
if (y + this._textLeading <= maxHeight || typeof maxHeight === 'undefined') {
5049+
var testLine = line + words[n] + ' ';
5050+
var metrics = this.drawingContext.measureText(testLine);
5051+
var testWidth = metrics.width;
5052+
if (typeof maxWidth !== 'undefined' && testWidth > maxWidth) {
5053+
if (this._doFill) {
5054+
this.drawingContext.fillText(line, x, y);
5055+
}
5056+
if (this._doStroke) {
5057+
this.drawingContext.strokeText(line, x, y);
5058+
}
5059+
line = words[n] + ' ';
5060+
y += this._textLeading;
5061+
} else {
5062+
line = testLine;
49555063
}
4956-
line = words[n] + ' ';
4957-
y += this._textLeading;
4958-
} else {
4959-
line = testLine;
49605064
}
49615065
}
4962-
if (y <= vals.y + vals.h) {
4963-
if (this._doFill) {
4964-
this.drawingContext.fillText(line, vals.x, y);
4965-
}
4966-
if (this._doStroke) {
4967-
this.drawingContext.strokeText(line, vals.x, y);
4968-
}
5066+
if (this._doFill) {
5067+
this.drawingContext.fillText(line, x, y);
49695068
}
5069+
if (this._doStroke) {
5070+
this.drawingContext.strokeText(line, x, y);
5071+
}
5072+
y += this._textLeading;
49705073
}
49715074
};
49725075
p5.prototype.textFont = function (str) {
49735076
this._setProperty('_textFont', str);
49745077
this._applyTextProperties();
49755078
};
49765079
return p5;
4977-
}({}, core, canvas);
5080+
}({}, core);
49785081
var src_app = function (require, core, p5Color, p5Element, p5Graphics, p5Image, p5Vector, p5TableRow, p5Table, colorcreating_reading, colorsetting, constants, dataconversion, dataarray_functions, datastring_functions, environment, imageimage, imageloading_displaying, imagepixels, inputfiles, inputkeyboard, inputmouse, inputtime_date, inputtouch, mathmath, mathcalculation, mathrandom, mathnoise, mathtrigonometry, outputfiles, outputimage, outputtext_area, renderingrendering, shape2d_primitives, shapeattributes, shapecurves, shapevertex, structure, transform, typographyattributes, typographyloading_displaying) {
49795082
'use strict';
49805083
var p5 = core;
5.05 KB
Loading

lib/addons/p5.dom.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! p5.dom.js v0.1.8 December 5, 2014 */
1+
/*! p5.dom.js v0.1.9 December 10, 2014 */
22
/**
33
* <p>The web is much more than just canvas and p5.dom makes it easy to interact
44
* with other HTML5 objects, including text, hyperlink, image, input, video,
@@ -63,7 +63,7 @@ var p5DOM = (function(){
6363
var res = document.getElementsByClassName(e);
6464
if (res) {
6565
for (var j = 0; j < res.length; j++) {
66-
var obj = wrapElement(res);
66+
var obj = wrapElement(res[j]);
6767
arr.push(obj);
6868
}
6969
}

0 commit comments

Comments
 (0)