: - : http://forresto.github.com/turtle-svg/
SVG- ( ) JavaScript, :
var TAU = 2 * Math.PI;
var pen = true;
var d = "";
var vector = {
x: 0,
y: 1
};
var currentAngle = 0;
var turnRight = function(angle){
currentAngle += angle;
currentAngle = currentAngle%1;
vector.x = Math.sin(TAU*currentAngle);
vector.y = Math.cos(TAU*currentAngle);
};
var turnLeft = function(angle){
turnRight(-angle);
};
var turnTo = function(angle){
currentAngle = angle;
vector.x = Math.sin(TAU*currentAngle);
vector.y = Math.cos(TAU*currentAngle);
};
var penUp = function(){
pen = false;
};
var penDown = function(){
pen = true;
};
var moveForward = function (distance) {
d += pen ? "l " : "m ";
d += (distance * vector.x) + " " + (distance * vector.y) + " ";
}
var moveTo = function (x, y) {
d += pen ? "L " : "M ";
d += x + " " + y + " ";
}
d d. : http://jsfiddle.net/forresto/hVE2U/