Skip to content

Commit

Permalink
added cylinder; tweaked test names
Browse files Browse the repository at this point in the history
  • Loading branch information
Hermanya authored and jdan committed Apr 27, 2014
1 parent d3b6336 commit ff79bb5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
18 changes: 16 additions & 2 deletions js/shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@
*/

/**
* A prism located at origin with dimensions dx, dy, dz and color
* A prism located at origin with dimensions dx, dy, dz
*/
Shape.Prism = function (origin, dx, dy, dz, color) {
Shape.Prism = function (origin, dx, dy, dz) {
dx = dx || 1;
dy = dy || 1;
dz = dz || 1;
Expand Down Expand Up @@ -215,6 +215,7 @@
return prism;
};


Shape.Pyramid = function (origin, dx, dy, dz) {
dx = dx || 1;
dy = dy || 1;
Expand Down Expand Up @@ -247,6 +248,19 @@
return pyramid;
};


Shape.Cylinder = function (origin, radius, vertices, height) {
radius = radius || 1;

var Path = Isomer.Path;

var circle = Path.Circle(origin, radius, vertices);
var cylinder = Shape.extrude(circle, height);

return cylinder;
};


exports.Shape = Shape;

})(Isomer);
30 changes: 21 additions & 9 deletions test/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,14 @@ function Knot(origin) {
return knot.scale(Point.ORIGIN, 1/5).translate(-0.1, 0.15, 0.4).translate(origin.x, origin.y, origin.z);
}

TestSuite.drawStructure = function () {
function randomColor() {
return new Color(
parseInt(Math.random() * 256),
parseInt(Math.random() * 256),
parseInt(Math.random() * 256));
}

TestSuite['draw structure'] = function () {
iso.add(Shape.Prism(new Point(1, 0, 0), 4, 4, 2));
iso.add(Shape.Prism(new Point(0, 0, 0), 1, 4, 1));
iso.add(Shape.Prism(new Point(-1, 1, 0), 1, 3, 1));
Expand Down Expand Up @@ -113,19 +120,19 @@ TestSuite.drawStructure = function () {
iso.add(Knot(new Point(3, 2, 3.2)), new Color(0, 180, 180));;
};

TestSuite.testScales = function () {
TestSuite['test scales'] = function () {
var cube = Shape.Prism(new Point(5, 5), 1, 1, 1);

for (var i = 0; i < 20; i++) {
iso.add(cube
.scale(new Point(5.5, 5.5), 10 - i/2, 10 - i/2, 1/3)
.translate(0, 0, i/3)
.rotateZ(new Point(5.5, 5.5), -Math.PI/20 * i),
new Color(parseInt(Math.random() * 256), parseInt(Math.random() * 256), parseInt(Math.random() * 256)));
randomColor());
}
};

TestSuite.testExtrude = function () {
TestSuite['test extrude'] = function () {
var basePath = new Path([
new Point(0, 0, 0),
new Point(1, 0, 0),
Expand All @@ -139,22 +146,27 @@ TestSuite.testExtrude = function () {
.translate(6, 6, 0));
};

TestSuite.testCircle = function () {
iso.add(Shape.extrude(Path.Circle(new Point(8, 8, 0), 8)));
TestSuite['test cylinder'] = function () {
iso.add(Shape.Cylinder(new Point(8, 8, 0), 6));
iso.add(Shape.Cylinder(new Point(11, 11, 1), 2.5, 20, 6), randomColor());
iso.add(Shape.Cylinder(new Point(5, 9, 1), 0.75, 20, 12), randomColor());
iso.add(Shape.Cylinder(new Point(4.5, 8, 1), 1.5, 20, 3), randomColor());
iso.add(Shape.Cylinder(new Point(10, 6, 1), 2.5, 20, 5), randomColor());
iso.add(Shape.Cylinder(new Point(6, 5, 1), 2, 20, 4), randomColor());
};

TestSuite.testStar = function () {
TestSuite['test star'] = function () {
iso.add(Shape.extrude(Path.Star(Point.ORIGIN, 1, 2, 4).rotateZ(Point.ORIGIN, Math.PI/6)));
};

TestSuite.drawLogo = function () {
TestSuite['draw logo'] = function () {
iso.add(Shape.Prism(new Point(1, 1), 1, 1, 2), new Color(0, 180, 180));
iso.add(Shape.Prism(new Point(0, 1), 1, 1, 1.5), new Color(50, 60, 180));
iso.add(Shape.Prism(new Point(1, 0), 1, 1, 1), new Color(50, 180, 60));
iso.add(Shape.Prism(new Point(0, 0), 1, 1, 0.5), new Color(180, 50, 60));
};

TestSuite.testRedLight = function () {
TestSuite['red light'] = function () {
iso.lightColor = new Color(160, 50, 60);
iso.add(Shape.Prism(new Point(1, 1), 1, 1, 2), new Color(0, 180, 180));
iso.add(Shape.Prism(new Point(0, 1), 1, 1, 1.5), new Color(50, 60, 180));
Expand Down

0 comments on commit ff79bb5

Please sign in to comment.