From d42f564e0485f461f1fee29e5f20b9f7f137d2a0 Mon Sep 17 00:00:00 2001
From: David Bau
Date: Mon, 27 May 2013 08:43:14 -0400
Subject: [PATCH 01/25] scale is a relative operation now.
---
jquery-turtle.js | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/jquery-turtle.js b/jquery-turtle.js
index 15f149a..baabdd5 100644
--- a/jquery-turtle.js
+++ b/jquery-turtle.js
@@ -54,7 +54,7 @@ Turtle-oriented methods taking advantage of the css support:
$(x).img('blue') // Switch the image to a blue pointer. May use any url.
$(x).moveto({pageX: 40, pageY: 140}) // Absolute motion in page coordinates.
$(x).turnto(heading || position) // Absolute heading adjustment.
- $(x).scale(1.5) // Scales the element up to 150% size.
+ $(x).scale(1.5) // Scales turtle size and motion by 150%.
$(x).twist(180) // Changes which direction is considered "forward".
$(x).mirror(true) // Flips the turtle across its direction axis.
$(x).reload() // Reloads the turtle's image (restarting animated gifs)
@@ -1795,14 +1795,16 @@ var turtlefn = {
});
},
scale: function(valx, valy) {
- if (valx === undefined && valy === undefined) {
- return parseFloat(this.css('turtleTwist'));
- }
- var val = '' + cssNum(valx) +
- (valy === undefined ? '' : ' ' + cssNum(valy));
+ if (valy === undefined) { valy = valx; }
+ // Disallow scaling to zero using this method.
+ if (!valx || !valy) { return this; }
return this.direct(function(j, elem) {
if ($.isWindow(elem) || elem.nodeType === 9) return;
- this.css('turtleScale', val);
+ var c = $.map($.css(elem, 'turtleScale').split(' '), parseFloat);
+ if (c.length === 1) { c.push(c[0]); }
+ c[0] *= valx;
+ c[1] *= valy;
+ this.css('turtleScale', $.map(c, cssNum).join(' '));
});
},
shown: function() {
From 1834ead4bc264f4082be2495afa96b86635e8d2f Mon Sep 17 00:00:00 2001
From: David Bau
Date: Mon, 27 May 2013 08:59:42 -0400
Subject: [PATCH 02/25] dot scales diameter.
---
jquery-turtle.js | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/jquery-turtle.js b/jquery-turtle.js
index baabdd5..199ff6c 100644
--- a/jquery-turtle.js
+++ b/jquery-turtle.js
@@ -1683,7 +1683,9 @@ var turtlefn = {
var ps = parsePenStyle(style, 'fillStyle');
return this.direct(function(j, elem) {
var c = this.center();
- fillDot(c, diameter, ps);
+ // Scale by sx. (TODO: consider drawing ellipse for sx != sy.)
+ var s = $.map($.css(elem, 'turtleScale').split(' '), parseFloat);
+ fillDot(c, diameter * s[0], ps);
// Once drawing begins, origin must be stable.
watchImageToFixOriginOnLoad(elem);
});
From 4de42392a7007efb05e0a647a2065f2e8ead2f1d Mon Sep 17 00:00:00 2001
From: David Bau
Date: Mon, 27 May 2013 09:39:13 -0400
Subject: [PATCH 03/25] Fix pen 'path'.
---
jquery-turtle.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/jquery-turtle.js b/jquery-turtle.js
index 199ff6c..a08a934 100644
--- a/jquery-turtle.js
+++ b/jquery-turtle.js
@@ -1300,9 +1300,9 @@ function flushPenState(elem) {
!isPointNearby(center, state.path[state.path.length - 1])) {
state.path.push(center);
}
- if (!state.style.path) {
+ if (!state.style.savePath) {
var ctx = getTurtleDrawingCtx();
- isClosed = isPointNearby(
+ isClosed = state.path.length > 2 && isPointNearby(
state.path[0], state.path[state.path.length - 1]);
ctx.save();
applyPenStyle(ctx, state.style);
From 14bd120bb5e3881d9c074954de754a06a1467465 Mon Sep 17 00:00:00 2001
From: David Bau
Date: Tue, 28 May 2013 09:12:25 -0400
Subject: [PATCH 04/25] Update jquery-turtle.js
---
jquery-turtle.js | 131 +++++++++++++++++++++++++++++++----------------
1 file changed, 87 insertions(+), 44 deletions(-)
diff --git a/jquery-turtle.js b/jquery-turtle.js
index a08a934..fad8516 100644
--- a/jquery-turtle.js
+++ b/jquery-turtle.js
@@ -4,7 +4,7 @@
jQuery-turtle
=============
-version 2.0.4
+version 2.0.5
jQuery-turtle is a jQuery plugin for turtle graphics.
@@ -48,25 +48,28 @@ Turtle-oriented methods taking advantage of the css support:
$(x).bk(50) // Back.
$(x).rt(90) // Right turn.
$(x).lt(45) // Left turn.
+
+ // Methods below happen in an instant, but queue after animation.
$(x).pen('red') // Sets a pen style, or 'none' for no drawing.
- $(x).dot(12) // Draws a dot of diameter 12.
+ $(x).dot(12) // Draws a circular dot of diameter 12.
$(x).erase() // Erases under the turtles collision hull.
$(x).img('blue') // Switch the image to a blue pointer. May use any url.
$(x).moveto({pageX: 40, pageY: 140}) // Absolute motion in page coordinates.
$(x).turnto(heading || position) // Absolute heading adjustment.
$(x).scale(1.5) // Scales turtle size and motion by 150%.
$(x).twist(180) // Changes which direction is considered "forward".
- $(x).mirror(true) // Flips the turtle across its direction axis.
+ $(x).mirror(true) // Flips the turtle across its main axis.
$(x).reload() // Reloads the turtle's image (restarting animated gifs)
$(x).direct(fn) // Like each, but this is set to $(elt) instead of elt.
+
// Methods below this line do not queue for animation.
- $(x).center() // Page coordinate position of transform-origin.
- $(x).direction() // Absolute bearing taking into account nested transforms.
+ $(x).origin() // Page coordinate position of transform-origin.
+ $(x).bearing() // Absolute direction taking into account all transforms.
$(x).shown() // Shorthand for is(":visible")
$(x).hidden() // Shorthand for !is(":visible")
$(x).touches(y) // Collision tests elements (uses turtleHull if present).
$(x).encloses(y) // Containment collision test.
- $(x).within(d, t) // Filters to items with centers within d of t.center().
+ $(x).within(d, t) // Filters to items with origins within d of t.origin().
$(x).notwithin() // The negation of within.
@@ -132,36 +135,57 @@ After eval($.turtle()):
* An eval debugging panel (see.js) is shown at the bottom of the screen.
* Turtle methods on the default turtle are packaged as globals, e.g., fd(10).
* Every #id element is turned into a global variable: window.id = $('#id').
- * Globals are set up to save events: "lastclick", "lastmousemove", etc.
* Default turtle animation is set to 1 move per sec so steps can be seen.
- * speed(movesPerSec) adjusts $.fx.speeds.turtle to 1000 / movesPerSec.
- * tick([ticksPerSec,] fn) is similarly an easier-to-call setInterval.
- * random(lessThanThisInteger || array) is an easy alternative to Math.random.
- * remove() will remove the global turtle and global turtle methods.
- * hatch([n,] [spec]) creates and returns any number of new turtles.
- * see(a, b, c) logs tree-expandable data into the debugging panel.
- * output(html or text) appends html to the document body.
- * input(label, callback) appends a labelled input field to the document body.
+ * And the following are defined:
+
+
+ lastclick // Event object of the last click event in the doc.
+ lastmousemove // The last mousemove event.
+ lastmouseup // The last mouseup event.
+ lastmousedown // The last mousedown event.
+ keydown // The last keydown event.
+ keyup // The last keyup event.
+ keypress // The last keypress event.
+ speed(movesPerSec) // Sets $.fx.speeds.turtle to 1000 / movesPerSec.
+ tick([perSec,] fn) // Sets fn as the tick callback (null to clear).
+ random(n) // Returns a random number [0...n-1].
+ random(list) // Returns a random element of the list.
+ random('normal') // Returns a gaussian random (mean 0 stdev 1).
+ random('uniform') // Returns a uniform random [0...1).
+ random('position') // Returns a random {pageX:x, pageY:y} in the document.
+ remove() // Removes default turtle and its globals (fd, etc).
+ hatch([n,], [img]) // Creates and returns n turtles with the given img.
+ see(a, b, c...) // Logs tree-expandable data into debugging panel.
+ output(html || text) // Appends html into the document body.
+ input([label,] fn) // Makes a one-time input field, calls fn after entry.
+ button([label,] fn) // Makes a clickable button, calls fn when clicked.
+
For example, after eval($.turtle()), the following is a valid program
in CoffeeScript syntax:
Under the covers, CSS3 2D transforms and jQuery animations are
used to execute and store turtle movement, so jQuery-turtle
@@ -71,7 +69,8 @@
jQuery-turtle
and creation of new turtles. The jQuery teaching environment
has been developed to support a curriculum for young students.
-
JQuery Methods for Turtle Movement
+
+JQuery Methods for Turtle Movement
Turtle-oriented methods taking advantage of the css support:
@@ -80,25 +79,28 @@
JQuery Methods for Turtle Movement
$(x).bk(50) // Back.
$(x).rt(90) // Right turn.
$(x).lt(45) // Left turn.
+
+ // Methods below happen in an instant, but queue after animation.
$(x).pen('red') // Sets a pen style, or 'none' for no drawing.
- $(x).dot(12) // Draws a dot of diameter 12.
+ $(x).dot(12) // Draws a circular dot of diameter 12.
$(x).erase() // Erases under the turtles collision hull.
$(x).img('blue') // Switch the image to a blue pointer. May use any url.
$(x).moveto({pageX: 40, pageY: 140}) // Absolute motion in page coordinates.
$(x).turnto(heading || position) // Absolute heading adjustment.
- $(x).scale(1.5) // Scales the element up to 150% size.
+ $(x).scale(1.5) // Scales turtle size and motion by 150%.
$(x).twist(180) // Changes which direction is considered "forward".
- $(x).mirror(true) // Flips the turtle across its direction axis.
+ $(x).mirror(true) // Flips the turtle across its main axis.
$(x).reload() // Reloads the turtle's image (restarting animated gifs)
$(x).direct(fn) // Like each, but this is set to $(elt) instead of elt.
+
// Methods below this line do not queue for animation.
- $(x).center() // Page coordinate position of transform-origin.
- $(x).direction() // Absolute bearing taking into account nested transforms.
+ $(x).origin() // Page coordinate position of transform-origin.
+ $(x).bearing() // Absolute direction taking into account all transforms.
$(x).shown() // Shorthand for is(":visible")
$(x).hidden() // Shorthand for !is(":visible")
$(x).touches(y) // Collision tests elements (uses turtleHull if present).
$(x).encloses(y) // Containment collision test.
- $(x).within(d, t) // Filters to items with centers within d of t.center().
+ $(x).within(d, t) // Filters to items with origins within d of t.origin().
$(x).notwithin() // The negation of within.
@@ -119,7 +121,8 @@
JQuery Methods for Turtle Movement
the bounding box of the elements (as transformed) but can be overridden
by the turtleHull CSS property, if present.
-
JQuery CSS Hooks for Turtle Geometry
+
+JQuery CSS Hooks for Turtle Geometry
Turtle-oriented 2d transform cssHooks, with animation support on all
motion:
@@ -152,7 +155,8 @@
JQuery CSS Hooks for Turtle Geometry
If set to 'auto' (the default) the hull is just the bounding box for the
element.
-
Turtle Teaching Environment
+
+Turtle Teaching Environment
An optional teaching environment setup is created by eval($.turtle()).
It provides easy packaging for the above functionality.
@@ -164,41 +168,63 @@
Turtle Teaching Environment
An eval debugging panel (see.js) is shown at the bottom of the screen.
Turtle methods on the default turtle are packaged as globals, e.g., fd(10).
Every #id element is turned into a global variable: window.id = $('#id').
-
Globals are set up to save events: "lastclick", "lastmousemove", etc.
Default turtle animation is set to 1 move per sec so steps can be seen.
-
speed(movesPerSec) adjusts $.fx.speeds.turtle to 1000 / movesPerSec.
-
tick([ticksPerSec,] fn) is similarly an easier-to-call setInterval.
-
random(lessThanThisInteger || array) is an easy alternative to Math.random.
-
remove() will remove the global turtle and global turtle methods.
-
hatch([n,] [spec]) creates and returns any number of new turtles.
-
see(a, b, c) logs tree-expandable data into the debugging panel.
-
output(html or text) appends html to the document body.
-
input(label, callback) appends a labelled input field to the document body.
-
For example, after eval($.turtle()), the following is a valid program
+
And the following are defined:
+
+ lastclick // Event object of the last click event in the doc.
+ lastmousemove // The last mousemove event.
+ lastmouseup // The last mouseup event.
+ lastmousedown // The last mousedown event.
+ keydown // The last keydown event.
+ keyup // The last keyup event.
+ keypress // The last keypress event.
+ speed(movesPerSec) // Sets $.fx.speeds.turtle to 1000 / movesPerSec.
+ tick([perSec,] fn) // Sets fn as the tick callback (null to clear).
+ random(n) // Returns a random number [0...n-1].
+ random(list) // Returns a random element of the list.
+ random('normal') // Returns a gaussian random (mean 0 stdev 1).
+ random('uniform') // Returns a uniform random [0...1).
+ random('position') // Returns a random {pageX:x, pageY:y} in the document.
+ remove() // Removes default turtle and its globals (fd, etc).
+ hatch([n,], [img]) // Creates and returns n turtles with the given img.
+ see(a, b, c...) // Logs tree-expandable data into debugging panel.
+ output(html || text) // Appends html into the document body.
+ input([label,] fn) // Makes a one-time input field, calls fn after entry.
+ button([label,] fn) // Makes a clickable button, calls fn when clicked.
+
+
+
For example, after eval($.turtle()), the following is a valid program
in CoffeeScript syntax: