diff --git a/language.html b/language.html
index e8f34a9..5dabf14 100644
--- a/language.html
+++ b/language.html
@@ -826,9 +826,18 @@
6.6 Pen Queries
+6.7 Bitmap Operations
+ bitcut width height
+ - Copy a bitmap, from the turtle's position width by height pixels.
+
+
bitpaste
+ - Paste the previously copied bitmap at the current turtle position.
+
- repeat 4 [ rt 90 fd 40 ] bitcut 50 50 pu fd 100 bitpaste
--->
+
+
6.8 Mouse/Touch Queries
diff --git a/logo.js b/logo.js
index e17ecb1..243a6db 100644
--- a/logo.js
+++ b/logo.js
@@ -2428,6 +2428,16 @@ function LogoInterpreter(turtle, stream, savehook)
return turtle.touches;
});
+ // Extensions
+
+ def("bitcut", function(w, h) {
+ return turtle.copy(w, h);
+ });
+
+ def("bitpaste", function() {
+ return turtle.paste();
+ });
+
//----------------------------------------------------------------------
//
// 7. Workspace Management
diff --git a/tests.js b/tests.js
index ed87bb4..e273d76 100644
--- a/tests.js
+++ b/tests.js
@@ -2026,8 +2026,10 @@ QUnit.test("Arity of Primitives", function(t) {
['bfs', [1, 1, 1]],
['bg', [0, 0, 0]],
['bitand', [0, 2, -1]],
+ ['bitcut', [2, 2, 2]],
['bitnot', [1, 1, 1]],
['bitor', [0, 2, -1]],
+ ['bitpaste', [0, 0, 0]],
['bitxor', [0, 2, -1]],
['bk', [1, 1, 1]],
['bl', [1, 1, 1]],
diff --git a/turtle.js b/turtle.js
index b95147c..40dc434 100644
--- a/turtle.js
+++ b/turtle.js
@@ -507,6 +507,23 @@
this.pendown = state.pendown;
}},
+ copy: {value: function(w, h) {
+ var x = this.width / 2 + this.x * this.sx;
+ var y = this.height / 2 - this.y * this.sy;
+ w *= this.sx;
+ h *= this.sy;
+ this._clipboard = this.canvas_ctx.getImageData(x, y, w, h);
+ }},
+
+ paste: {value: function() {
+ if (!this._clipboard)
+ return;
+
+ var x = this.width / 2 + this.x * this.sx;
+ var y = this.height / 2 - this.y * this.sy;
+ this.canvas_ctx.putImageData(this._clipboard, x, y);
+ }},
+
// Properties
pendown: {