Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cylinder #10

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch :)

*/
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 @@ -247,6 +247,13 @@
return pyramid;
};

Shape.Cylinder = function (origin, radius, vertices, height) {
radius = radius || 1;
var Path = Isomer.Path;
var circle = new Path.Circle(origin, radius, vertices);
var cylinder = Shape.extrude(circle,height);
return cylinder;
};
exports.Shape = Shape;

})(Isomer);
26 changes: 18 additions & 8 deletions test/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ 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 +117,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,15 +143,21 @@ 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.extrude(Path.Circle(new Point(8, 8, 0), 2)));
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));
Expand Down