Skip to content

Commit

Permalink
Add BITCUT and BITPASTE commands. Resolves #142
Browse files Browse the repository at this point in the history
  • Loading branch information
inexorabletash committed Sep 23, 2023
1 parent ede7a08 commit 1d2dfbf
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
11 changes: 10 additions & 1 deletion language.html
Original file line number Diff line number Diff line change
Expand Up @@ -826,9 +826,18 @@ <h4>6.6 Pen Queries</h4>

<!--
<h4>6.7 Saving and Loading Pictures</h4>
-->
<h4>6.7 Bitmap Operations</h4>
<dl>
<dt><code>bitcut <var>width</var> <var>height</var></code>
<dd>Copy a bitmap, from the turtle's position <var>width</var> by <var>height</var> pixels.

<dt><code>bitpaste</code>
<dd>Paste the previously copied bitmap at the current turtle position.
<dd class=example>repeat 4 [ rt 90 fd 40 ] bitcut 50 50 pu fd 100 bitpaste</dd>
</dl>
-->



<h4>6.8 Mouse/Touch Queries</h4>
<dl>
Expand Down
10 changes: 10 additions & 0 deletions logo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand Down
17 changes: 17 additions & 0 deletions turtle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 1d2dfbf

Please sign in to comment.