-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port tests to JS.Test and do some more reorganization.
- Loading branch information
Showing
19 changed files
with
897 additions
and
1,025 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!doctype html> | ||
|
||
<html> | ||
<head> | ||
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> | ||
<title>Vectors / Matrices</title> | ||
<script type="text/javascript" src="../lib/sylvester-min.js"></script> | ||
</head> | ||
<body style="background: #000;"> | ||
|
||
<script type="text/javascript"> | ||
var dots = [], images = [], h = 500; | ||
var axis = Vector.create([0.7,1,0.3]); | ||
var rot = Matrix.Rotation(0.1, axis); | ||
|
||
for (var i = 0; i < 16; i++) { | ||
dots[i] = Vector.create([h*(Math.random()-0.5), h*(Math.random()-0.5), h*(Math.random()-0.5)]); | ||
image = document.createElement('img'); | ||
image.id = 'img_' + i; | ||
image.src = './dot.png'; | ||
document.body.appendChild(image); | ||
images[i] = image; | ||
} | ||
|
||
setInterval(function() { | ||
for (var i = 0; i < dots.length; i++) { | ||
f = (dots[i].e(3) + h)/(2*h) + 0.1; | ||
|
||
images[i].style.opacity = f - 0.1; | ||
images[i].style.width = (100 * f) + 'px'; | ||
images[i].style.height = (100 * f) + 'px'; | ||
images[i].style.position = 'absolute'; | ||
images[i].style.top = (300 - dots[i].e(2)*f) + 'px'; | ||
images[i].style.left = (600 + dots[i].e(1)*f) + 'px'; | ||
|
||
dots[i] = rot.x(dots[i]); | ||
} | ||
}, 20); | ||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<!doctype html> | ||
|
||
<html> | ||
<head> | ||
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> | ||
<title>Vectors / Matrices</title> | ||
<script type="text/javascript" src="../lib/sylvester-min.js"></script> | ||
</head> | ||
<body> | ||
|
||
<canvas id="canv" width="600" height="450" style="display: block; margin: 20px auto;" onclick="rotate();"></canvas> | ||
|
||
<script type="text/javascript"> | ||
var O = $V([300,225,0]); | ||
|
||
var Foo = Polygon.create([ [0,0], [5,0], [5,5], [0,5], [0,10], [5,10], [0,5], | ||
[5,5], [10,10], [10,15], [-5,15], [-5,5], [-10,5], [-10,0], [-5,0], | ||
[-5,-5], [0,-5] ]).scale(20, $V([0,5])).rotate(Math.PI/3, $L([0,5], [0,2,1])); | ||
|
||
var canvas, ctx; | ||
|
||
window.onload = function() { | ||
canvas = document.getElementById('canv'); | ||
ctx = canvas.getContext('2d'); | ||
ctx.fillColor = '#000000'; | ||
ctx.fillRect(0,0, canvas.width, canvas.height); | ||
|
||
draw(ctx, Foo, 100); | ||
|
||
var trigs; | ||
trigs = Foo.toTriangles(); | ||
var C = 255; | ||
for (var i = 0; i < trigs.length; i++) { | ||
draw(ctx, trigs[i], C); | ||
C -= Math.round((255 - 100) / trigs.length); | ||
} | ||
|
||
var c = Foo.centroid(); | ||
ctx.fillStyle = 'red'; | ||
ctx.fillRect(300 + c.e(1) - 5, 225 - c.e(2) - 5, 10, 10); | ||
}; | ||
|
||
function draw(ctx, poly, color) { | ||
ctx.fillStyle = 'rgb(' + color +',' + color + ',' + color + ')'; | ||
ctx.beginPath(); | ||
poly.vertices.each(function(node) { | ||
point = O.add(node.data).reflectionIn($L(O, Vector.i)); | ||
if (node.data == poly.vertices.first.data) { | ||
ctx.moveTo(point.e(1), point.e(2)); | ||
} else { | ||
ctx.lineTo(point.e(1), point.e(2)); | ||
} | ||
} ); | ||
ctx.fill(); | ||
} | ||
|
||
function rotate() { | ||
ctx.fillStyle = '#000000'; | ||
ctx.fillRect(0,0, canvas.width, canvas.height); | ||
Foo.rotate(Math.PI/20, $L([0,5], [0,2,1])); | ||
var trigs = Foo.toTriangles(); | ||
var C = 255; | ||
for (var i = 0; i < trigs.length; i++) { | ||
draw(ctx, trigs[i], C); | ||
C -= Math.round((255 - 100) / trigs.length); | ||
} | ||
setTimeout(rotate, 20); | ||
} | ||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.