forked from jeromeetienne/threex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTHREEx.LogoTurtle.js
More file actions
46 lines (37 loc) · 1001 Bytes
/
THREEx.LogoTurtle.js
File metadata and controls
46 lines (37 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/** @namespace */
var THREEx = THREEx || {};
// TODO should those relative polar coord function be INSIDE path already ?
THREEx.LogoTurtle = function()
{
this._penX = 0;
this._penY = 0;
this._angle = 0;
this._vectors = [];
}
THREEx.LogoTurtle.create = function()
{
return new THREEx.LogoTurtle()
}
THREEx.LogoTurtle.prototype.turn = function(rotation)
{
this._angle += rotation;
return this;
}
THREEx.LogoTurtle.prototype.moveTo = function(x, y)
{
this._penX = x * Math.cos(this._angle) - y * Math.sin(this._angle);
this._penY = x * Math.sin(this._angle) + y * Math.cos(this._angle);
this._vectors.push( new THREE.Vector2(this._penX, this._penY) );
return this;
}
THREEx.LogoTurtle.prototype.forward = function(distance)
{
this._penX += Math.cos(this._angle) * distance;
this._penY += Math.sin(this._angle) * distance;
this._vectors.push( new THREE.Vector2(this._penX, this._penY) );
return this;
}
THREEx.LogoTurtle.prototype.points = function()
{
return this._vectors;
}