Skip to content

Commit 6eaa75c

Browse files
author
Lauren McCarthy
committed
fixes #247 fixes #1275
1 parent 4c452d1 commit 6eaa75c

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

src/core/p5.Renderer2D.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ p5.Renderer2D.prototype.blend = function() {
150150
);
151151

152152
this.drawingContext.globalCompositeOperation = blendMode;
153-
this._pInst.copy.apply(this._pInst, copyArgs);
153+
if (this._pInst) {
154+
this._pInst.copy.apply(this._pInst, copyArgs);
155+
} else {
156+
this.copy.apply(this, copyArgs);
157+
}
154158
this.drawingContext.globalCompositeOperation = currBlend;
155159
};
156160

src/image/p5.Image.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,52 @@ p5.Image.prototype.filter = function(operation, value) {
535535
*
536536
*
537537
* http://blogs.adobe.com/webplatform/2013/01/28/blending-features-in-canvas/
538+
* @example
539+
* <div><code>
540+
* var mountains;
541+
* var bricks;
542+
*
543+
* function preload() {
544+
* mountains = loadImage("assets/rockies.jpg");
545+
* bricks = loadImage("assets/bricks_third.jpg");
546+
* }
547+
*
548+
* function setup() {
549+
* mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, ADD);
550+
* image(mountains, 0, 0);
551+
* image(bricks, 0, 0);
552+
* }
553+
* </code></div>
554+
* <div><code>
555+
* var mountains;
556+
* var bricks;
538557
*
558+
* function preload() {
559+
* mountains = loadImage("assets/rockies.jpg");
560+
* bricks = loadImage("assets/bricks_third.jpg");
561+
* }
562+
*
563+
* function setup() {
564+
* mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST);
565+
* image(mountains, 0, 0);
566+
* image(bricks, 0, 0);
567+
* }
568+
* </code></div>
569+
* <div><code>
570+
* var mountains;
571+
* var bricks;
572+
*
573+
* function preload() {
574+
* mountains = loadImage("assets/rockies.jpg");
575+
* bricks = loadImage("assets/bricks_third.jpg");
576+
* }
577+
*
578+
* function setup() {
579+
* mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST);
580+
* image(mountains, 0, 0);
581+
* image(bricks, 0, 0);
582+
* }
583+
* </code></div>
539584
*/
540585
p5.Image.prototype.blend = function() {
541586
p5.prototype.blend.apply(this, arguments);

src/image/pixels.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ p5.prototype.pixels = [];
145145
* </code></div>
146146
*/
147147
p5.prototype.blend = function() {
148-
this._renderer.blend.apply(this._renderer, arguments);
148+
if (this._renderer) {
149+
this._renderer.blend.apply(this._renderer, arguments);
150+
} else {
151+
p5.Renderer2D.prototype.blend.apply(this, arguments);
152+
}
149153
};
150154

151155
/**

0 commit comments

Comments
 (0)